简介
Smolagents 是 HuggingFace 推出的极简 Python Agent 框架,GitHub 15,000+ stars。不到 30 行代码构建完整 Agent。独特的 Code Agent 模式让 LLM 直接写 Python 代码调用工具。适合需要最简路径构建 Agent 的开发者。
Minimalist Python agent framework by HuggingFace. Build agents with tool use in under 30 lines of code. Supports code-based agents that write and execute Python instead of JSON tool calls. 15,000+ stars.
这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。
pip install smolagentsfrom smolagents import CodeAgent, tool, LiteLLMModel
@tool
def get_weather(city: str) -> str:
'获取城市天气'
return f"{city}: 22°C, 晴"
agent = CodeAgent(tools=[get_weather], model=LiteLLMModel("anthropic/claude-sonnet-4-20250514"))
agent.run("东京天气怎么样?")Smolagents 是 HuggingFace 推出的极简 Python Agent 框架,GitHub 15,000+ stars。不到 30 行代码构建完整 Agent。独特的 Code Agent 模式让 LLM 直接写 Python 代码调用工具。适合需要最简路径构建 Agent 的开发者。
Created by HuggingFace. Licensed under Apache 2.0.
smolagents — ⭐ 15,000+