Scripts2026年4月6日·1 分钟阅读

Smolagents — Lightweight Agent Framework by HuggingFace

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.

AG
Agent Toolkit · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

pip install smolagents
from 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+

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产