-
Notifications
You must be signed in to change notification settings - Fork 385
Create a tiny-agents
package
#1451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
61ef178
some LLM scaffolding + some human edit 🙄
julien-c 2c4bb34
A lot of vibe coding....
julien-c 9ebc685
Fix vibe coding errors...
julien-c b7d11a4
Update pnpm-workspace.yaml
julien-c 1c0215e
re-export
julien-c 3127f31
Define Zod validation for config files
julien-c bb2f36e
Fetch prompt.md from disk
julien-c 4e592ab
hook main loop from mcp-client/cli.ts
julien-c 30c2c94
Create .prettierignore
julien-c 4c628fb
Create .eslintignore
julien-c b417aa5
Fix CI?
julien-c f29eeca
tests
julien-c 71babb5
Create tiny-agents-publish.yml
julien-c 91c87a9
Merge branch 'main' into tiny-agents-package
julien-c b60cfed
README
julien-c b7f61d3
handle local directory
julien-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Tiny Agents - Version and Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
newversion: | ||
type: choice | ||
description: "Semantic Version Bump Type" | ||
default: patch | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
bypass_deps_check: | ||
type: boolean | ||
description: "Bypass dependency checking" | ||
default: false | ||
|
||
concurrency: | ||
group: "push-to-main" # Consider changing this if tiny-agents has its own release concurrency group | ||
|
||
defaults: | ||
run: | ||
working-directory: packages/tiny-agents | ||
|
||
jobs: | ||
version_and_release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
token: ${{ secrets.BOT_ACCESS_TOKEN }} | ||
- run: npm install -g corepack@latest && corepack enable | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "20" | ||
cache: "pnpm" | ||
cache-dependency-path: | | ||
packages/tiny-agents/pnpm-lock.yaml | ||
packages/doc-internal/pnpm-lock.yaml | ||
registry-url: "https://registry.npmjs.org" | ||
- run: pnpm install | ||
- run: git config --global user.name machineuser | ||
- run: git config --global user.email [email protected] | ||
- run: | | ||
PACKAGE_VERSION=$(node -p "require('./package.json').version") | ||
BUMPED_VERSION=$(node -p "require('semver').inc('$PACKAGE_VERSION', '${{ github.event.inputs.newversion }}')") | ||
# Update package.json with the new version | ||
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');" | ||
pnpm --filter doc-internal run fix-cdn-versions | ||
git add ../.. | ||
git commit -m "🔖 @huggingface/tiny-agents $BUMPED_VERSION" | ||
git tag "tiny-agents-v$BUMPED_VERSION" | ||
|
||
# Add checks for dependencies if needed, similar to hub-publish.yml | ||
- if: ${{ !github.event.inputs.bypass_deps_check }} | ||
name: "Check Deps are published before publishing this package" | ||
run: pnpm -w check-deps inference && pnpm -w check-deps tasks # Review if these specific deps apply to tiny-agents | ||
|
||
- run: pnpm publish --no-git-checks . | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
- run: (git pull --rebase && git push --follow-tags) || (git pull --rebase && git push --follow-tags) | ||
# hack - reuse actions/setup-node@v3 just to set a new registry | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: "20" | ||
registry-url: "https://npm.pkg.github.com" | ||
# Disable for now, until github supports PATs for writing github packages (https://github.com/github/roadmap/issues/558) | ||
# - run: pnpm publish --no-git-checks . | ||
# env: | ||
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: "Update Doc" | ||
uses: peter-evans/repository-dispatch@v2 | ||
with: | ||
event-type: doc-build | ||
token: ${{ secrets.BOT_ACCESS_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./McpClient"; | ||
export * from "./Agent"; | ||
export type { ChatCompletionInputMessageTool } from "./McpClient"; | ||
export type { ServerConfig } from "./types"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pnpm-lock.yaml | ||
# In order to avoid code samples to have tabs, they don't display well on npm | ||
README.md | ||
dist |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# @huggingface/tiny-agents | ||
|
||
 | ||
|
||
A squad of lightweight composable AI applications built on Hugging Face's Inference Client and MCP stack. | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @huggingface/tiny-agents | ||
# or | ||
pnpm add @huggingface/tiny-agents | ||
``` | ||
|
||
## CLI Usage | ||
|
||
```bash | ||
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 | ||
``` | ||
|
||
## Define your own agent | ||
|
||
The simplest way to create your own agent is to create a folder containing an `agent.json` file: | ||
|
||
```bash | ||
mkdir my-agent | ||
touch my-agent/agent.json | ||
``` | ||
|
||
```json | ||
{ | ||
"model": "Qwen/Qwen2.5-72B-Instruct", // model id | ||
"provider": "nebius", // or you can also use a local endpoint base url with `endpointUrl` | ||
"servers": [ | ||
{ | ||
"type": "stdio", | ||
"config": { | ||
"command": "npx", | ||
"args": ["@playwright/mcp@latest"] | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
|
||
Where `servers` is a list of MCP servers (we support Stdio, SSE, and HTTP servers). | ||
|
||
Optionally, you can add a `PROMPT.md` file to override the default Agent prompt. | ||
|
||
Then just point tiny-agents to your local folder: | ||
|
||
```bash | ||
npx @huggingface/tiny-agents run ./my-agent | ||
``` | ||
|
||
Voilà! 🔥 | ||
|
||
> [!NOTE] | ||
> 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. | ||
### Advanced: Programmatic Usage | ||
|
||
```typescript | ||
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); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
## License | ||
|
||
MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "@huggingface/tiny-agents", | ||
"packageManager": "[email protected]", | ||
"version": "0.1.0", | ||
"description": "Lightweight, composable agents for AI applications", | ||
"repository": "https://github.com/huggingface/huggingface.js.git", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"bin": { | ||
"tiny-agents": "./dist/cli.js" | ||
}, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
} | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"source": "index.ts", | ||
"scripts": { | ||
"lint": "eslint --quiet --fix --ext .cjs,.ts .", | ||
"lint:check": "eslint --ext .cjs,.ts .", | ||
"format": "prettier --write .", | ||
"format:check": "prettier --check .", | ||
"prepublishOnly": "pnpm run build", | ||
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration", | ||
"prepare": "pnpm run build", | ||
"test": "vitest run", | ||
"check": "tsc", | ||
"cli": "tsx src/cli.ts" | ||
}, | ||
"files": [ | ||
"src", | ||
"dist", | ||
"tsconfig.json" | ||
], | ||
"keywords": [ | ||
"huggingface", | ||
"agent", | ||
"ai", | ||
"llm", | ||
"tiny-agent" | ||
], | ||
"author": "Hugging Face", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@huggingface/inference": "workspace:^", | ||
"@huggingface/mcp-client": "workspace:^", | ||
"@huggingface/tasks": "workspace:^", | ||
"@modelcontextprotocol/sdk": "^1.11.4", | ||
"zod": "^3.25.7" | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
being able to run OR serve from the same config is 👌