# tiny-agents

[tiny-agents](https://huggingface.co/blog/python-tiny-agents) 提供了一种构建使用工具的 agent 的极简模式。一个小型 Python 循环将 MCP 客户端连接到来自 MCP 服务器的工具。Hugging Face Spaces 可作为 MCP 服务器使用。可在 [Hub](https://huggingface.co/spaces?filter=mcp-server) 上找到更多兼容的 Spaces。

创建一个配置文件，指向您的本地模型和工具服务器。本示例使用了一个图像生成 [Space](https://evalstate-flux1-schnell.hf.space/)。

```json
{
    "model": "Menlo/Jan-nano",
    "endpointUrl": "http://localhost:8000",
    "servers": [
        {
            "type": "sse",
            "url": "https://evalstate-flux1-schnell.hf.space/gradio_api/mcp/sse"
        }
    ]
}
```

使用您的配置运行智能体。

```bash
tiny-agents run path/to/your/config.json
```

确保 `transformers serve` 正在后台运行。该智能体将使用您的本地模型来运行图像生成工具。

```bash
Agent loaded with 1 tools:
 • flux1_schnell_infer
»  Generate an image of a cat on the moon
<Tool req_0_tool_call>flux1_schnell_infer {"prompt": "a cat on the moon", "seed": 42, "randomize_seed": true, "width": 1024, "height": 1024, "num_inference_steps": 4}

Tool req_0_tool_call
[Binary Content: Image image/webp, 57732 bytes]
The task is complete and the content accessible to the User
Image URL: https://evalstate-flux1-schnell.hf.space/gradio_api/file=/tmp/gradio/3dbddc0e53b5a865ed56a4e3dbdd30f3f61cf3b8aabf1b456f43e5241bd968b8/image.webp
380576952

I have generated an image of a cat on the moon using the Flux 1 Schnell Image Generator. The image is 1024x1024 pixels and was created with 4 inference steps. Let me know if you would like to make any changes or need further assistance!
```

