🚀🚀🚀本篇笔记所对应的视频:🚀用MCP为AutoGen开挂接入各种工具和框架!Cline零代码开发MCP Server实现接入LangFlow进行文档问答!利用MCP Server突破_哔哩哔哩_bilibili
AutoGen v0.4引入了对Model Context Protocol (MCP) server的支持,这是一项重要的新功能,为AI代理提供了更强大和灵活的工具使用能力。
MCP Server支持
AutoGen v0.4通过autogen_ext.tools.mcp
模块提供了对MCP server的支持。这允许用户将MCP兼容的工具集成到AutoGen代理中,主要通过以下两种方式:
- Server-Sent Events (SSE): 通过
SseMcpToolAdapter
类,可以包装基于HTTP和SSE的MCP工具。 - 标准输入/输出 (STDIO): 使用
StdioMcpToolAdapter
类,可以包装基于命令行的MCP工具。
集成方法
AutoGen提供了便捷的方法来集成MCP工具:
- 使用
mcp_server_tools
函数可以连接到MCP server并返回所有可用工具的适配器。 - 这些适配器可以直接分配给AutoGen代理的工具列表,使代理能够使用这些工具。
优势
支持MCP server为AutoGen带来了以下优势:
- 标准化接口: MCP被描述为"AI工具的USB",提供了一种标准化的方式让AI代理发现和使用不同的功能。
- 灵活性: 用户可以轻松地将各种MCP兼容工具集成到他们的AutoGen工作流中,包括远程服务、云端工具和Web API。
- 可扩展性: 通过简单的配置,可以添加新的MCP server来扩展代理的能力。
- 动态工具使用: AutoGen实现了基于字典的灵活方法,使得发现和使用工具变得简单。
- 跨语言支持: 这种集成支持不同编程语言构建的代理之间的互操作性。
- 模块化和可扩展: 用户可以轻松定制系统,使用可插拔的组件,包括自定义代理、工具、内存和模型。
通过支持MCP server,AutoGen大大增强了其生态系统的开放性和可扩展性,使开发者能够更容易地集成各种工具和服务,从而创建更强大、更灵活的AI代理系统。
🔥LangFlow安装以及Cline提示词
# 安装命令
python -m pip install langflow
# 运行
python -m langflow run
## 提示词
show me some examples about Self-Consistency Prompt
## Cline提示词
请为我开发一个用于文档问答系统的MCP Tool,
要求实现用户能够输入要检索的提示词,然后进行检索,最后获取到检索到结果。
下面是文档问答系统的API交互方式:
### 请求内容如下,其中input_value的值就是用于检索的提示词:
curl -X POST \\
"<http://127.0.0.1:7860/api/v1/run/a8e187bd-44e7-4984-9218-42f63946760b?stream=false>" \\
-H 'Content-Type: application/json'\\
-d '{"input_value": "show me some examples about Self-Consistency Prompt ",
"output_type": "chat",
"input_type": "chat",
"tweaks": {
"ChatInput-Jrzyb": {},
"ChatOutput-rzoZb": {},
"ParseData-hzL7Q": {},
"File-2Teuj": {},
"Prompt-ktajI": {},
"MistralModel-aLZcw": {}
}}'
### 响应内容如下,其中text的值就是检索到的结果:
{"session_id":"a8e187bd-44e7-4984-9218-42f63946760b","outputs":[{"inputs":{"input_value":"show me some examples about Self-Consistency Prompt "},"outputs":[{"results":{"message":{"text_key":"text","data":{"timestamp":"2025-02-22T08:22:24+00:00","sender":"Machine","sender_name":"AI","session_id":"a8e187bd-44e7-4984-9218-42f63946760b","text":"Sure, here are some examples of the Self-Consistency Prompt technique from the document:\\n\\n1. **Text Generation:**\\n - Task: Generate a product review\\n - Instructions: The review should be consistent with the product information provided in the input\\n - Prompt formula: \\"Generate a product review that is consistent with the following product information [insert product information]\\"\\n\\n2. **Text Summarization:**\\n - Task: Summarize a news article\\n - Instructions: The summary should be consistent with the information provided in the article\\n - Prompt formula: \\"Summarize the following news article in a way that is consistent with the information provided [insert news article]\\"\\n\\n3. **Text Completion:**\\n - Ta