7天上手OpenClaw Day4:工具绑定与使用

工具概念

Tool是Agent可调用的外部能力,可以是Skill、API、数据库操作等。Agent通过Tool接口统一调用不同类型的外部能力,简化开发流程。

绑定Skill作为Tool

将Skill绑定为Tool:在agent.yaml中配置tools: - name: hello_tool, type: skill, skill: hello_skill。Agent可以像调用Tool一样调用Skill。

绑定API作为Tool

绑定外部API为Tool:tools: - name: weather_api, type: http, endpoint: https://api.weather.com, method: GET。Agent可以调用外部HTTP API获取数据。

动态Tool选择

Agent可以根据上下文动态选择Tool。实现方式:在process方法中分析输入,根据意图选择合适的Tool。如:if '天气' in input: use_tool('weather_api')。

💬 📞