微型代理-MCP驱动的代理
由模型上下文协议(MCP)支持的轻量级AI代理框架,可与各种AI模型和工具无缝集成。
🌟 概述
该项目演示了如何使用 微型代理 框架与MCP服务器集成。这些代理可以与外部工具(如用于web自动化的Playwright)交互,并且可以由不同的LLM提供商提供支持,包括Ollama和Hugging Face Inference。
🚀 特性
- 多LLM提供商支持:与Ollama、Hugging Face Inference和其他提供商兼容
- MCP服务器集成:无缝连接到像Playwright这样的MCP服务器,以扩展功能
- 灵活配置:基于JSON的代理配置,便于定制
- 工具发现:内置工具列表和发现机制
- 轻便快速:通过快速设置实现最小依赖
📁 项目结构
mcp-practice-tiny-agent/
├── agents/ # Agent configuration files
│ ├── agent.json # Base agent configuration
│ ├── agent_with_ollama.json # Ollama-powered agent
│ └── agent_with_hfinference.json # HuggingFace Inference agent
├── scripts/ # Utility scripts
│ ├── run_agent.py # Main agent execution script
│ ├── test_connection.py # Connection testing script
│ └── mcp_list_tools.py # Tool discovery script
├── servers/ # MCP server configurations
├── requirements.txt # Python dependencies
└── README.md # This file🛠️ 安装
先决条件
- Python 3.8+
- Node.js(适用于Playwright等MCP服务器)
- Ollama(可选,用于本地LLM推理)
设置
- 克隆仓库:
git clone
cd mcp-practice-tiny-agent- 创建虚拟环境:
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate- 安装依赖项:
pip install -r requirements.txt- 设置环境变量 (如果使用拥抱脸):
# Create a .env file
HF_TOKEN=your_huggingface_token_here🎯 用法
运行代理
执行主代理脚本:
python scripts/run_agent.py这将加载代理配置并运行示例任务(例如,web搜索和摘要)。
测试连接
验证您的代理设置:
python scripts/test_connection.py列出可用工具
了解您的代理可以使用哪些工具:
python scripts/mcp_list_tools.py⚙️ 配置
代理配置文件
代理配置存储在 agents/ 目录为JSON文件:
示例:Ollama代理商(agent_with_ollama.json)
{
"name": "playwright-agent",
"description": "Agent with Playwright MCP server",
"model": "Qwen/Qwen2.5-1.5B-Instruct",
"base_url": "http://localhost:11434",
"servers": [
{
"type": "stdio",
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
]
}示例:拥抱面部推理代理(agent_with_hfinference.json)
{
"name": "playwright-agent",
"description": "Agent with Playwright MCP server",
"model": "Qwen/Qwen2.5-1.5B-Instruct",
"provider": "hf-inference",
"servers": [
{
"type": "stdio",
"command": "npx",
"args": ["@playwright/mcp@latest"]
}
]
}配置参数
- 名字:您的代理的唯一标识符
- 描述:代理人目的的简要说明
- 模型:要使用的LLM模型(例如。,
Qwen/Qwen2.5-1.5B-Instruct) - 提供者:法学硕士提供者(
hf-inference,或省略Ollama) - base_url:API终点(对于Ollama,通常
http://localhost:11434) - 服务器:要连接的MCP服务器阵列
🔧 支持的MCP服务器
当前配置为:
- 剧作家MCP:Web自动化和浏览器控制功能
您可以通过修改来添加更多MCP服务器 servers 代理配置中的数组。
📚 关键依赖关系
- 主控程序:模型上下文协议实现
- MCP-奥拉马:用于MCP的Olama集成
- tiny_agent:核心代理框架
- 拥抱脸_主页:拥抱脸部模型集成
- 奥拉玛:Ollama Python客户端
- 皮丹提克:数据验证和设置管理
🤝 贡献
欢迎投稿!请随意:
- 报告错误
- 建议新功能
- 提交拉取请求
📝 许可证
\[在此处添加您的许可证信息\]
🙏 致谢
📞 支持
有关问题和疑问,请在存储库中打开问题。
______________________________________________________________________
代理楼快乐! 🤖✨
