Skip to content

Commit ec546dd

Browse files
authored
Create a tiny-agents package (#1451)
<img width="1944" alt="image" src="https://github.com/user-attachments/assets/e9c2597e-1a3c-42fc-bfbd-08fbb1ee458a" />
1 parent e51625f commit ec546dd

File tree

19 files changed

+1351
-1
lines changed

19 files changed

+1351
-1
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Tiny Agents - Version and Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
newversion:
7+
type: choice
8+
description: "Semantic Version Bump Type"
9+
default: patch
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
bypass_deps_check:
15+
type: boolean
16+
description: "Bypass dependency checking"
17+
default: false
18+
19+
concurrency:
20+
group: "push-to-main" # Consider changing this if tiny-agents has its own release concurrency group
21+
22+
defaults:
23+
run:
24+
working-directory: packages/tiny-agents
25+
26+
jobs:
27+
version_and_release:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/checkout@v3
31+
with:
32+
token: ${{ secrets.BOT_ACCESS_TOKEN }}
33+
- run: npm install -g corepack@latest && corepack enable
34+
- uses: actions/setup-node@v3
35+
with:
36+
node-version: "20"
37+
cache: "pnpm"
38+
cache-dependency-path: |
39+
packages/tiny-agents/pnpm-lock.yaml
40+
packages/doc-internal/pnpm-lock.yaml
41+
registry-url: "https://registry.npmjs.org"
42+
- run: pnpm install
43+
- run: git config --global user.name machineuser
44+
- run: git config --global user.email infra+machineuser@huggingface.co
45+
- run: |
46+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
47+
BUMPED_VERSION=$(node -p "require('semver').inc('$PACKAGE_VERSION', '${{ github.event.inputs.newversion }}')")
48+
# Update package.json with the new version
49+
node -e "const fs = require('fs'); const package = JSON.parse(fs.readFileSync('./package.json')); package.version = '$BUMPED_VERSION'; fs.writeFileSync('./package.json', JSON.stringify(package, null, '\t') + '\n');"
50+
pnpm --filter doc-internal run fix-cdn-versions
51+
git add ../..
52+
git commit -m "🔖 @huggingface/tiny-agents $BUMPED_VERSION"
53+
git tag "tiny-agents-v$BUMPED_VERSION"
54+
55+
# Add checks for dependencies if needed, similar to hub-publish.yml
56+
- if: ${{ !github.event.inputs.bypass_deps_check }}
57+
name: "Check Deps are published before publishing this package"
58+
run: pnpm -w check-deps inference && pnpm -w check-deps tasks # Review if these specific deps apply to tiny-agents
59+
60+
- run: pnpm publish --no-git-checks .
61+
env:
62+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
63+
- run: (git pull --rebase && git push --follow-tags) || (git pull --rebase && git push --follow-tags)
64+
# hack - reuse actions/setup-node@v3 just to set a new registry
65+
- uses: actions/setup-node@v3
66+
with:
67+
node-version: "20"
68+
registry-url: "https://npm.pkg.github.com"
69+
# Disable for now, until github supports PATs for writing github packages (https://github.com/github/roadmap/issues/558)
70+
# - run: pnpm publish --no-git-checks .
71+
# env:
72+
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
- name: "Update Doc"
74+
uses: peter-evans/repository-dispatch@v2
75+
with:
76+
event-type: doc-build
77+
token: ${{ secrets.BOT_ACCESS_TOKEN }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ const agent = new Agent({
241241
],
242242
});
243243

244-
245244
await agent.loadTools();
245+
246246
for await (const chunk of agent.run("What are the top 5 trending models on Hugging Face?")) {
247247
if ("choices" in chunk) {
248248
const delta = chunk.choices[0]?.delta;

packages/mcp-client/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./McpClient";
22
export * from "./Agent";
33
export type { ChatCompletionInputMessageTool } from "./McpClient";
4+
export type { ServerConfig } from "./types";

packages/tiny-agents/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

packages/tiny-agents/.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pnpm-lock.yaml
2+
# In order to avoid code samples to have tabs, they don't display well on npm
3+
README.md
4+
dist

packages/tiny-agents/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# @huggingface/tiny-agents
2+
3+
![meme](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/tiny-agents/legos.png)
4+
5+
A squad of lightweight composable AI applications built on Hugging Face's Inference Client and MCP stack.
6+
7+
## Installation
8+
9+
```bash
10+
npm install @huggingface/tiny-agents
11+
# or
12+
pnpm add @huggingface/tiny-agents
13+
```
14+
15+
## CLI Usage
16+
17+
```bash
18+
npx @huggingface/tiny-agents [command] "agent/id"
19+
20+
```
21+
22+
```
23+
Usage:
24+
tiny-agents [flags]
25+
tiny-agents run "agent/id"
26+
tiny-agents serve "agent/id"
27+
28+
Available Commands:
29+
run Run the Agent in command-line
30+
serve Run the Agent as an OpenAI-compatible HTTP server
31+
```
32+
33+
## Define your own agent
34+
35+
The simplest way to create your own agent is to create a folder containing an `agent.json` file:
36+
37+
```bash
38+
mkdir my-agent
39+
touch my-agent/agent.json
40+
```
41+
42+
```json
43+
{
44+
"model": "Qwen/Qwen2.5-72B-Instruct", // model id
45+
"provider": "nebius", // or you can also use a local endpoint base url with `endpointUrl`
46+
"servers": [
47+
{
48+
"type": "stdio",
49+
"config": {
50+
"command": "npx",
51+
"args": ["@playwright/mcp@latest"]
52+
}
53+
}
54+
]
55+
}
56+
```
57+
58+
Where `servers` is a list of MCP servers (we support Stdio, SSE, and HTTP servers).
59+
60+
Optionally, you can add a `PROMPT.md` file to override the default Agent prompt.
61+
62+
Then just point tiny-agents to your local folder:
63+
64+
```bash
65+
npx @huggingface/tiny-agents run ./my-agent
66+
```
67+
68+
Voilà! 🔥
69+
70+
> [!NOTE]
71+
> Note: you can open a PR in the huggingface.js repo to share your agent with the community, just upload it inside the `src/agents/` directory.
72+
73+
### Advanced: Programmatic Usage
74+
75+
```typescript
76+
import { Agent } from '@huggingface/tiny-agents';
77+
78+
const HF_TOKEN = "hf_...";
79+
80+
// Create an Agent
81+
const agent = new Agent({
82+
provider: "auto",
83+
model: "Qwen/Qwen2.5-72B-Instruct",
84+
apiKey: HF_TOKEN,
85+
servers: [
86+
{
87+
// Playwright MCP
88+
command: "npx",
89+
args: ["@playwright/mcp@latest"],
90+
},
91+
],
92+
});
93+
94+
await agent.loadTools();
95+
96+
// Use the Agent
97+
for await (const chunk of agent.run("What are the top 5 trending models on Hugging Face?")) {
98+
if ("choices" in chunk) {
99+
const delta = chunk.choices[0]?.delta;
100+
if (delta.content) {
101+
console.log(delta.content);
102+
}
103+
}
104+
}
105+
```
106+
107+
108+
## License
109+
110+
MIT

packages/tiny-agents/package.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "@huggingface/tiny-agents",
3+
"packageManager": "pnpm@10.10.0",
4+
"version": "0.1.0",
5+
"description": "Lightweight, composable agents for AI applications",
6+
"repository": "https://github.com/huggingface/huggingface.js.git",
7+
"publishConfig": {
8+
"access": "public"
9+
},
10+
"main": "./dist/index.js",
11+
"module": "./dist/index.mjs",
12+
"types": "./dist/index.d.ts",
13+
"bin": {
14+
"tiny-agents": "./dist/cli.js"
15+
},
16+
"exports": {
17+
".": {
18+
"types": "./dist/index.d.ts",
19+
"require": "./dist/index.js",
20+
"import": "./dist/index.mjs"
21+
}
22+
},
23+
"engines": {
24+
"node": ">=18"
25+
},
26+
"source": "index.ts",
27+
"scripts": {
28+
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
29+
"lint:check": "eslint --ext .cjs,.ts .",
30+
"format": "prettier --write .",
31+
"format:check": "prettier --check .",
32+
"prepublishOnly": "pnpm run build",
33+
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
34+
"prepare": "pnpm run build",
35+
"test": "vitest run",
36+
"check": "tsc",
37+
"cli": "tsx src/cli.ts"
38+
},
39+
"files": [
40+
"src",
41+
"dist",
42+
"tsconfig.json"
43+
],
44+
"keywords": [
45+
"huggingface",
46+
"agent",
47+
"ai",
48+
"llm",
49+
"tiny-agent"
50+
],
51+
"author": "Hugging Face",
52+
"license": "MIT",
53+
"dependencies": {
54+
"@huggingface/inference": "workspace:^",
55+
"@huggingface/mcp-client": "workspace:^",
56+
"@huggingface/tasks": "workspace:^",
57+
"@modelcontextprotocol/sdk": "^1.11.4",
58+
"zod": "^3.25.7"
59+
}
60+
}

0 commit comments

Comments
 (0)