Skip to content

Commit e4d382c

Browse files
authored
Tiny agents custom endpoint (#1470)
1 parent 94a757e commit e4d382c

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

packages/tiny-agents/README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pnpm add @huggingface/tiny-agents
1616

1717
```bash
1818
npx @huggingface/tiny-agents [command] "agent/id"
19-
2019
```
2120

2221
```
@@ -41,8 +40,8 @@ touch my-agent/agent.json
4140

4241
```json
4342
{
44-
"model": "Qwen/Qwen2.5-72B-Instruct", // model id
45-
"provider": "nebius", // or you can also use a local endpoint base url with `endpointUrl`
43+
"model": "Qwen/Qwen2.5-72B-Instruct",
44+
"provider": "nebius",
4645
"servers": [
4746
{
4847
"type": "stdio",
@@ -55,6 +54,25 @@ touch my-agent/agent.json
5554
}
5655
```
5756

57+
Or using a local or remote endpoint URL:
58+
59+
```json
60+
{
61+
"model": "Qwen/Qwen3-32B",
62+
"endpointUrl": "http://localhost:1234/v1",
63+
"servers": [
64+
{
65+
"type": "stdio",
66+
"config": {
67+
"command": "npx",
68+
"args": ["@playwright/mcp@latest"]
69+
}
70+
}
71+
]
72+
}
73+
74+
```
75+
5876
Where `servers` is a list of MCP servers (we support Stdio, SSE, and HTTP servers).
5977

6078
Optionally, you can add a `PROMPT.md` file to override the default Agent prompt.

packages/tiny-agents/src/cli.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,17 @@ async function main() {
114114

115115
const { configJson, prompt } = await loadConfigFrom(loadFrom);
116116

117-
const ConfigSchema = z.object({
118-
model: z.string(),
119-
provider: z.enum(PROVIDERS_OR_POLICIES),
120-
servers: z.array(ServerConfigSchema),
121-
});
117+
const ConfigSchema = z
118+
.object({
119+
model: z.string(),
120+
provider: z.enum(PROVIDERS_OR_POLICIES).optional(),
121+
endpointUrl: z.string().optional(),
122+
apiKey: z.string().optional(),
123+
servers: z.array(ServerConfigSchema),
124+
})
125+
.refine((data) => data.provider !== undefined || data.endpointUrl !== undefined, {
126+
message: "At least one of 'provider' or 'endpointUrl' is required",
127+
});
122128

123129
let config: z.infer<typeof ConfigSchema>;
124130
try {
@@ -129,13 +135,24 @@ async function main() {
129135
process.exit(1);
130136
}
131137

132-
const agent = new Agent({
133-
provider: config.provider,
134-
model: config.model,
135-
apiKey: process.env.HF_TOKEN ?? "",
136-
servers: config.servers,
137-
prompt,
138-
});
138+
const agent = new Agent(
139+
config.endpointUrl
140+
? {
141+
endpointUrl: config.endpointUrl,
142+
model: config.model,
143+
apiKey: config.apiKey ?? process.env.API_KEY ?? process.env.HF_TOKEN,
144+
servers: config.servers,
145+
prompt,
146+
}
147+
: {
148+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
149+
provider: config.provider!,
150+
model: config.model,
151+
apiKey: config.apiKey ?? process.env.API_KEY ?? process.env.HF_TOKEN,
152+
servers: config.servers,
153+
prompt,
154+
}
155+
);
139156

140157
if (command === "serve") {
141158
error(`Serve is not implemented yet, coming soon!`);

0 commit comments

Comments
 (0)