使用说明
Strands MCP数学代理🧠🔧
一个由人工智能驱动的数学代理,将自然语言数学转换为符号表达式,并通过MCP计算器工具求解。
🚀 这个项目做什么
用简单的英语键入数学,例如:
3 plus 7 divided by 2 and multiplied by 10
代理人将:
- 使用LLM(Ollama/LLaMA 3.2)理解句子
- 将其转换为正确的符号表达式:
3 + (7 / 2 * 10) - 将表达式发送到
calculate通过MCP工具 - 返回最终的数字答案(例如。,
38.0)
🏗 项目结构
my-ai-agent/
│
├── server/
│ ├── calc.py # MCP calculator tool server
│ └── agent_strands.py # Strands agent using the tool
│
├── .venv/ # Virtual environment (do not upload)
└── README.md
⚙️ 技术栈
| 技术 | 角色 |
|---|---|
| Strands Agent | 推理+工具决策 |
| Ollama(LLaMA 3.2) | 理解数学文本的语言模型 |
| MCP(模型上下文协议) | 让代理可靠地调用工具 |
| Python AST | 安全数学表达式求值 |
🧠 运作原理
- 用户输入——你用简单的英语输入一道数学题。
- Strands Agent——LLM将句子翻译成符号表达,并调用
calculate工具。 - MCP计算器工具--
calc.py使用Python AST解析表达式并安全地对其求值,返回数值结果。
🛠 设置
- 克隆:
git clone https://github.com/YOUR-USERNAME/YOUR-REPO.git
cd my-ai-agent
- 创建虚拟环境并激活它:
Windows(PowerShell):
python -m venv .venv
.\.venv\Scripts\Activate.ps1
Mac/Linux:
python3 -m venv .venv
source .venv/bin/activate
- 安装Python依赖项:
pip install -r server/requirements.txt
# Optional extras if not included: pip install strands-agents ollama
- (可选)在本地安装并运行Olama,然后拉取模型:
# Install Ollama per https://ollama.com
ollama pull llama3.2
ollama run llama3.2 # ensure Ollama is running
- 启动计算器工具服务器(MCP):
python server/calc.py
- 运行Strands代理:
# Option A (recommended)
python server/agent_strands.py
# Or, if you prefer uv:
uv run server/agent_strands.py
您应该看到:
Strands MCP Calculator Ready!
Type 'exit' to quit.
💬 示例
用户:
5 plus 2 times 3 minus 1
代理流程:
- 表达→
5 + (2 * 3) - 1 - 工具调用→
calculate(expression="5 + (2 * 3) - 1") - 结果→
10
输出:
Agent: 10
👨💻 作者
作为一个学习项目,探索LLMs+MCP+工具使用+代理。