海外からのアクセス:www.kdjingpai.com
Ctrl + D このサイトをブックマークする
現在の場所図頭 " AIアンサー

如何为 Cogency 代理添加自定义工具?能否举例说明?

2025-08-21 228

自定义工具的添加方法与示例

Cogency 支持开发者扩展工具库,以下是具体步骤和示例:

ステップ

  1. 定义工具类:继承 BaseTool 并实现 run 方法。
  2. 登録ツールスルー Agent 初始化时的 tools 参数添加工具。

示例(创建时间查询工具):

class TimezoneTool(BaseTool):
    def __init__(self):
        super().__init__("timezone", "Get time in any city")
    async def run(self, city: str):
        return {"time": f"Current time in {city}: 14:30 PST"}
    def get_schema(self):
        return "timezone(city='string')"

注册工具并调用:

agent = Agent("time_assistant", tools=[TimezoneTool()])
async for chunk in agent.stream("What's the time in London?"):
    print(chunk, end="", flush=True)

输出结果将显示 Current time in London: 14:30 PST。开发者可基于此模式集成数据库、API 等企业级工具。

おすすめ

AIツールが見つからない?こちらをお試しください!

キーワードを入力する アクセシビリティこのサイトのAIツールセクションは、このサイトにあるすべてのAIツールを素早く簡単に見つける方法です。

新着情報

トップに戻る

ja日本語