smolagent是hf推出的agent开发库,简洁易用。这里尝试用smolagents完成简单数学题目。
1 smolagents安装
conda create -n smolagents python=3.12
conda activate smolagents
pip install smolagents
pip install 'smolagents[mlx-lm]'
由于是在mac使用mlx,所以除smolagents外还需要安装mlx-lm套件。
2 编写agent程序
由于hf访问问题,设置hf-mirror镜像环境
受本地算力限制使用4位量化版Coder模型mlx-community/Qwen2.5-Coder-3B-Instruct-4bit
简单算术题目 5+3 + 1294.678,对应如下任务指令。
What is the result of the following operation: 5 + 3 + 1294.678?
import os
os.environ['HF_ENDPOINT'] = "https://hf-mirror.com"from smolagents import CodeAgent, WebSearchTool, InferenceClientModel, MLXModelmodel = MLXModel(model_id="mlx-community/Qwen2.5-Coder-3B-Instruct-4bit")
agent = CodeAgent(tools=[WebSearchTool()], model=model, stream_outputs=False)agent.run("What is the result of the following operation: 5 + 3 + 1294.678?")
保存为smolagents_test.py
3 运行smolagents示例
运行python smolagents_test.py,结果如下
可以看出smolagents不是直接用大模型做题,而是先生成解题程序,然后运行程序获得答案。
reference
---
deepseek
DeepSeek
DeepResearchAgent
https://github.com/SkyworkAI/DeepResearchAgent.git
smolagents
https://github.com/huggingface/smolagents