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 上更新

© . This site is unofficial and not affiliated with Hugging Face, Inc.