Huggingface.js 文档

@huggingface/tiny-agents

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

@huggingface/tiny-agents

meme

一套基于 Hugging Face 推理客户端和 MCP 堆栈构建的轻量级可组合 AI 应用程序。

安装

npm install @huggingface/tiny-agents
# or
pnpm add @huggingface/tiny-agents

命令行界面使用

npx @huggingface/tiny-agents [command] "agent/id"
Usage:
  tiny-agents [flags]
  tiny-agents run   "agent/id"
  tiny-agents serve "agent/id"

Available Commands:
  run         Run the Agent in command-line
  serve       Run the Agent as an OpenAI-compatible HTTP server

您可以直接从 Hugging Face Hub 的 tiny-agents 数据集加载代理,或指定您自己的本地代理配置路径。

定义您自己的代理

创建您自己的代理最简单的方法是创建一个包含 `agent.json` 文件的文件夹

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

或使用本地或远程端点 URL

{
	"model": "Qwen/Qwen3-32B",
	"endpointUrl": "https://:1234/v1",
	"servers": [
		{
			"type": "stdio",
			"command": "npx",
			"args": ["@playwright/mcp@latest"]
		}
	]
}

其中 `servers` 是 MCP 服务器列表(我们支持 Stdio、SSE 和 HTTP 服务器)。

您可以选择添加一个 `PROMPT.md` 文件来覆盖默认的代理提示。

然后只需将 tiny-agents 指向您的本地文件夹

npx @huggingface/tiny-agents run ./my-agent

瞧!🔥

Tiny Agents 合集

https://huggingface.co/datasets/tiny-agents/tiny-agents 浏览我们精选的 Tiny Agents 合集。每个代理都存储在自己的子目录中,遵循上述结构。从 Hub 运行代理就像使用其 `agent_id` 一样简单。例如,要运行 `julien-c/flux-schnell-generator` 代理

npx @huggingface/tiny-agents run "julien-c/flux-schnell-generator"

[!注意] 想与社区分享您自己的代理吗?向 Hub 上的 Tiny Agents 仓库提交 PR。您的提交必须包含一个 `agent.json` 文件,并且您可以选择添加一个 `PROMPT.md` 文件。为了帮助其他人了解您的代理的功能,请考虑包含一个带有示例提示和用例的 `EXAMPLES.md` 文件。

高级:程序化使用

import { Agent } from '@huggingface/tiny-agents';

const HF_TOKEN = "hf_...";

// Create an Agent
const agent = new Agent({
  provider: "auto",
  model: "Qwen/Qwen2.5-72B-Instruct",
  apiKey: HF_TOKEN,
  servers: [
    {
      // Playwright MCP
      command: "npx",
      args: ["@playwright/mcp@latest"],
    },
  ],
});

await agent.loadTools();

// Use the Agent
for await (const chunk of agent.run("What are the top 5 trending models on Hugging Face?")) {
    if ("choices" in chunk) {
        const delta = chunk.choices[0]?.delta;
        if (delta.content) {
            console.log(delta.content);
        }
    }
}

许可证

MIT

< > 在 GitHub 上更新