# Agent 库

## tiny-agents

一个轻量级工具包，用于在 Hugging Face Inference 之上运行基于 MCP 的智能体。提供 [JavaScript](https://huggingface.co/docs/huggingface.js/en/tiny-agents/README)（`@huggingface/tiny-agents`）和 [Python](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/mcp)（`huggingface_hub`）版本。

```bash
# JavaScript
npx @huggingface/tiny-agents run "agent/id"

# Python
pip install "huggingface_hub[mcp]"
tiny-agents run "agent/id"
```

使用 `agent.json` 配置创建你自己的 agent：

```json
{
	"model": "Qwen/Qwen2.5-72B-Instruct",
	"provider": "together",
	"servers": [
		{
			"type": "stdio",
			"command": "npx",
			"args": ["@playwright/mcp@latest"]
		}
	]
}
```

对于本地 LLM，请添加一个指向您服务器的 `endpointUrl`（例如 `http://localhost:1234/v1`）。有关详细信息，请参阅 [SDK 指南](./agents-sdk)。

## Gradio MCP 服务器

只需一行代码，即可将任意 Gradio 应用转换为 MCP 服务器：

```python
demo.launch(mcp_server=True)
```

服务器将每个函数暴露为一个工具，其描述由文档字符串自动生成。您可以将其连接到任何 MCP 客户端。在 [Hub](https://huggingface.co/spaces?filter=mcp-server) 上有数千个兼容 MCP 的 Spaces。有关更多信息，请参阅 [Gradio MCP 指南](https://www.gradio.app/guides/building-mcp-server-with-gradio)。

## smolagents

[smolagents](https://github.com/huggingface/smolagents) 是一个轻量级 Python 库，只需几行代码即可构建智能体。它支持 `CodeAgent`（以 Python 编写操作）和 `ToolCallingAgent`（使用 JSON 工具调用），可通过 [Inference Providers](../inference-providers/index) 与任意模型配合使用，并支持与 MCP 服务器集成。

```bash
smolagent "Plan a trip to Tokyo, Kyoto and Osaka between Mar 28 and Apr 7." \
--model-type "InferenceClientModel" \
--model-id "Qwen/Qwen2.5-Coder-32B-Instruct" \
--tools "web_search"
```

可以将 Agent 作为 Space 推送到 Hub。浏览社区 Agent 请访问[此处](https://huggingface.co/spaces?filter=smolagents&sort=likes)。更多详情请参阅[smolagents 文档](https://huggingface.co/docs/smolagents/tutorials/tools#use-mcp-tools-with-mcpclient-directly)。

