外部服务集成方案
通过MCP协议标准化工具接入流程:
- 协议准备:确保服务提供方支持Model Context Protocol
- Connection Configuration: Use
MCPTool.connect()
建立连接,需指定:- 启动命令(如npx/node/python等)
- 必要的环境变量
- 参数列表
- 工具注册:将返回的MCP工具对象加入Agent的tools列表
示例(高德地图集成):
amap_tools = await MCPTool.connect(
command="npx",
args=["-y", "@amap/amap-maps-mcp-server"],
env={"AMAP_MAPS_API_KEY": "your_key"}
)
agent = Agent(tools=[amap_tools])
alternative::
1. 直接封装: Use@function_tool
装饰普通API调用函数
2. OpenAPI适配:对Swagger规范的API可用OpenAPITool
自动生成工具
3. hybrid model:本地工具和远程工具可以共存于同一个Agent
Debugging Tips: Useagent.describe_tools()
验证工具接入状态。
This answer comes from the articleZipAgent: a lightweight Python framework for building exclusive AI assistants in 5 minutesThe