Skip to content

Commit 2c4bb34

Browse files
committed
A lot of vibe coding....
1 parent 61ef178 commit 2c4bb34

File tree

8 files changed

+171
-44
lines changed

8 files changed

+171
-44
lines changed

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/README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,26 @@ yarn add @huggingface/tiny-agents
1212
pnpm add @huggingface/tiny-agents
1313
```
1414

15-
## Usage
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+
34+
## Programmatic Usage
1635

1736
```typescript
1837
import { Agent } from '@huggingface/tiny-agents';
@@ -46,11 +65,6 @@ for await (const chunk of agent.run("What are the top 5 trending models on Huggi
4665
}
4766
```
4867

49-
## CLI Usage
50-
51-
```bash
52-
npx @huggingface/tiny-agents
53-
```
5468

5569
## License
5670

packages/tiny-agents/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"node": ">=18"
2525
},
2626
"source": "index.ts",
27+
"type": "module",
2728
"scripts": {
2829
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
2930
"lint:check": "eslint --ext .cjs,.ts .",
@@ -34,7 +35,7 @@
3435
"prepare": "pnpm run build",
3536
"test": "vitest run",
3637
"check": "tsc",
37-
"cli": "tsx cli.ts"
38+
"cli": "tsx src/cli.ts"
3839
},
3940
"files": [
4041
"src",
@@ -52,6 +53,7 @@
5253
"license": "MIT",
5354
"dependencies": {
5455
"@huggingface/inference": "workspace:^",
55-
"@huggingface/mcp-client": "workspace:^"
56+
"@huggingface/mcp-client": "workspace:^",
57+
"zod": "^3.24.4"
5658
}
5759
}

packages/tiny-agents/pnpm-lock.yaml

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"model": "Qwen/Qwen3-32B",
3+
"provider": "novita",
4+
"servers": [
5+
{
6+
"type": "sse",
7+
"config": {
8+
"url": "https://evalstate-flux1-schnell.hf.space/gradio_api/mcp/sse"
9+
}
10+
}
11+
]
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
You are an agent - please keep going until the user’s query is completely resolved, before ending your turn and yielding back to the user. Only terminate your turn when you are sure that the problem is solved, or if you need more info from the user to solve the problem.
2+
3+
If you are not sure about anything pertaining to the user’s request, use your tools to read files and gather the relevant information: do NOT guess or make up an answer.
4+
5+
You MUST plan extensively before each function call, and reflect extensively on the outcomes of the previous function calls. DO NOT do this entire process by making function calls only, as this can impair your ability to solve the problem and think insightfully.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"model": "Qwen/Qwen2.5-72B-Instruct",
3+
"provider": "nebius",
4+
"servers": [
5+
{
6+
"type": "stdio",
7+
"config": {
8+
"command": "npx",
9+
"args": ["@playwright/mcp@latest"]
10+
}
11+
}
12+
]
13+
}

packages/tiny-agents/src/cli.ts

Lines changed: 88 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,109 @@
11
#!/usr/bin/env node
22
import * as readline from "node:readline/promises";
33
import { stdin, stdout } from "node:process";
4-
import { join } from "node:path";
5-
import { homedir } from "node:os";
4+
import { dirname, join } from "node:path";
5+
import { fileURLToPath } from "node:url";
66
import { parseArgs } from "node:util";
7+
import { z } from "zod";
78
import type { InferenceProviderOrPolicy } from "@huggingface/inference";
9+
import { PROVIDERS_OR_POLICIES } from "@huggingface/inference";
810
import { version as packageVersion } from "../package.json";
11+
import { readFile } from "node:fs/promises";
12+
import type { ServerConfig } from "@huggingface/mcp-client";
913

10-
const SERVERS: ServerConfig[] = [
11-
{
12-
// Filesystem "official" mcp-server with access to your Desktop
13-
command: "npx",
14-
args: [
15-
"-y",
16-
"@modelcontextprotocol/server-filesystem",
17-
process.platform === "darwin" ? join(homedir(), "Desktop") : homedir(),
18-
],
19-
},
20-
{
21-
// Playwright MCP
22-
command: "npx",
23-
args: ["@playwright/mcp@latest"],
24-
},
25-
];
14+
const USAGE_HELP = `
15+
Usage:
16+
tiny-agents [flags]
17+
tiny-agents run "agent/id"
18+
tiny-agents serve "agent/id"
19+
20+
Available Commands:
21+
run Run the Agent in command-line
22+
serve Run the Agent as an OpenAI-compatible HTTP server
23+
24+
Flags:
25+
-h, --help help for tiny-agents
26+
-v, --version Show version information
27+
`.trim();
28+
29+
const CLI_COMMANDS = ["run", "serve"] as const;
30+
function isValidCommand(command: string): command is (typeof CLI_COMMANDS)[number] {
31+
return (CLI_COMMANDS as unknown as string[]).includes(command);
32+
}
33+
34+
const FILENAME_CONFIG = "agent.json";
35+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
36+
const FILENAME_PROMPT = "PROMPT.md";
2637

2738
async function main() {
2839
const {
29-
values: { url: urls },
40+
values: { help, version },
41+
positionals,
3042
} = parseArgs({
3143
options: {
32-
url: {
33-
type: "string",
34-
multiple: true,
44+
help: {
45+
type: "boolean",
46+
short: "h",
47+
},
48+
version: {
49+
type: "boolean",
50+
short: "v",
3551
},
3652
},
53+
allowPositionals: true,
3754
});
38-
if (urls?.length) {
39-
while (SERVERS.length) {
40-
SERVERS.pop();
41-
}
42-
for (const url of urls) {
43-
try {
44-
SERVERS.push(urlToServerConfig(url, process.env.HF_TOKEN));
45-
} catch (error) {
46-
console.error(`Error adding server from URL "${url}": ${error.message}`);
47-
}
48-
}
49-
}
50-
51-
if (process.argv.includes("--version")) {
55+
if (version) {
5256
console.log(packageVersion);
5357
process.exit(0);
5458
}
59+
const command = positionals[0];
60+
const loadFrom = positionals[1];
61+
if (help) {
62+
console.log(USAGE_HELP);
63+
process.exit(0);
64+
}
65+
if (positionals.length !== 2 || !isValidCommand(command)) {
66+
console.error(`You need to call run or serve, followed by an agent id (local path or Hub identifier).`);
67+
console.log(USAGE_HELP);
68+
process.exit(1);
69+
}
70+
71+
if (command === "serve") {
72+
console.error(`Serve is not implemented yet, coming soon!`);
73+
process.exit(1);
74+
} else {
75+
const srcDir = dirname(fileURLToPath(import.meta.url));
76+
const configPath = join(srcDir, "agents", loadFrom, FILENAME_CONFIG);
77+
let configJson: string;
78+
try {
79+
configJson = await readFile(configPath, { encoding: "utf8" });
80+
} catch {
81+
console.error(`Config file not found!`);
82+
process.exit(1);
83+
}
84+
const ConfigSchema = z.object({
85+
model: z.string(),
86+
provider: z.enum<InferenceProviderOrPolicy>(PROVIDERS_OR_POLICIES),
87+
servers: z.array(z.custom<ServerConfig>()),
88+
});
89+
90+
let config: z.infer<typeof ConfigSchema>;
91+
try {
92+
const parsedConfig = JSON.parse(configJson);
93+
config = ConfigSchema.parse(parsedConfig);
94+
} catch (error) {
95+
console.error("Invalid configuration file:", error instanceof Error ? error.message : error);
96+
process.exit(1);
97+
}
98+
const agent = new Agent({
99+
provider: config.provider,
100+
model: config.model,
101+
apiKey: process.env.HF_TOKEN,
102+
servers: config.servers,
103+
});
104+
console.log(agent);
105+
// TODO: hook main loop from mcp-client/cli.ts
106+
}
55107
}
56108

57109
main();

0 commit comments

Comments
 (0)