agent0-js 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -86,6 +86,18 @@ Execute an agent and get the complete response.
86
86
  interface RunOptions {
87
87
  agentId: string; // The ID of the agent to run
88
88
  variables?: Record<string, string>; // Variables to pass to the agent
89
+ overrides?: ModelOverrides; // Runtime model configuration overrides
90
+ extraMessages?: Message[]; // Extra messages to append to the prompt
91
+ }
92
+
93
+ interface ModelOverrides {
94
+ model?: { // Override the model
95
+ provider_id?: string; // Override provider ID
96
+ name?: string; // Override model name
97
+ };
98
+ maxOutputTokens?: number; // Override max output tokens
99
+ temperature?: number; // Override temperature
100
+ maxStepCount?: number; // Override max step count
89
101
  }
90
102
  ```
91
103
 
@@ -226,6 +238,78 @@ const response = await client.generate({
226
238
  // Prompt becomes: "Hello Sarah, let's talk about machine learning"
227
239
  ```
228
240
 
241
+ ### Model Overrides
242
+
243
+ The `overrides` option allows you to dynamically configure the model at runtime. This is useful for:
244
+ - **Load Balancing**: Distribute requests across different providers
245
+ - **Fallbacks**: Switch to a backup model if the primary is unavailable
246
+ - **A/B Testing**: Test different models with the same agent configuration
247
+ - **Cost Optimization**: Use cheaper models for non-critical requests
248
+
249
+ ```typescript
250
+ // Override the model for a specific request
251
+ const response = await client.generate({
252
+ agentId: 'agent_123',
253
+ variables: { prompt: 'Hello world' },
254
+ overrides: {
255
+ model: { name: 'gpt-4o-mini' }, // Use a different model
256
+ temperature: 0.5, // Adjust temperature
257
+ maxOutputTokens: 500 // Limit output length
258
+ }
259
+ });
260
+
261
+ // Implement a simple fallback pattern
262
+ async function runWithFallback(agentId: string, variables: Record<string, string>) {
263
+ try {
264
+ return await client.generate({ agentId, variables });
265
+ } catch (error) {
266
+ // Fallback to a different provider/model
267
+ return await client.generate({
268
+ agentId,
269
+ variables,
270
+ overrides: {
271
+ model: {
272
+ provider_id: 'backup-provider-id',
273
+ name: 'claude-3-haiku-20240307'
274
+ }
275
+ }
276
+ });
277
+ }
278
+ }
279
+ ```
280
+
281
+ ### Extra Messages
282
+
283
+ The `extraMessages` option allows you to programmatically append additional messages to the agent's prompt. These messages are used as-is without any variable substitution, making them ideal for:
284
+ - **Dynamic Context**: Add conversation history or context at runtime
285
+ - **Multi-turn Conversations**: Build chat applications by appending user/assistant turns
286
+ - **Retrieved Content**: Inject RAG results or retrieved documents
287
+
288
+ ```typescript
289
+ // Add conversation history to the agent
290
+ const response = await client.generate({
291
+ agentId: 'agent_123',
292
+ variables: { topic: 'AI' },
293
+ extraMessages: [
294
+ { role: 'user', content: 'What is machine learning?' },
295
+ { role: 'assistant', content: 'Machine learning is a subset of AI...' },
296
+ { role: 'user', content: 'Tell me more about neural networks' }
297
+ ]
298
+ });
299
+
300
+ // Inject retrieved context (RAG pattern)
301
+ const retrievedDocs = await searchDocuments(query);
302
+ const response = await client.generate({
303
+ agentId: 'rag-agent',
304
+ extraMessages: [
305
+ {
306
+ role: 'user',
307
+ content: `Context:\n${retrievedDocs.join('\n')}\n\nQuestion: ${query}`
308
+ }
309
+ ]
310
+ });
311
+ ```
312
+
229
313
  ### Error Handling
230
314
 
231
315
  ```typescript
package/dist/index.js CHANGED
@@ -27,6 +27,8 @@ class Agent0 {
27
27
  const response = await this.fetchApi('/api/v1/run', {
28
28
  agent_id: options.agentId,
29
29
  variables: options.variables,
30
+ overrides: options.overrides,
31
+ extra_messages: options.extraMessages,
30
32
  stream: false,
31
33
  });
32
34
  return await response.json();
@@ -35,6 +37,8 @@ class Agent0 {
35
37
  const response = await this.fetchApi('/api/v1/run', {
36
38
  agent_id: options.agentId,
37
39
  variables: options.variables,
40
+ overrides: options.overrides,
41
+ extra_messages: options.extraMessages,
38
42
  stream: true,
39
43
  });
40
44
  if (!response.body) {
package/dist/types.d.ts CHANGED
@@ -3,9 +3,30 @@ export interface Agent0Config {
3
3
  apiKey: string;
4
4
  baseUrl?: string;
5
5
  }
6
+ /**
7
+ * Model configuration overrides for runtime customization.
8
+ * Allows downstream applications to implement load balancing, fallbacks, and dynamic model switching.
9
+ */
10
+ export interface ModelOverrides {
11
+ /** Override the model provider and name */
12
+ model?: {
13
+ provider_id?: string;
14
+ name?: string;
15
+ };
16
+ /** Override max output tokens */
17
+ maxOutputTokens?: number;
18
+ /** Override temperature */
19
+ temperature?: number;
20
+ /** Override max step count */
21
+ maxStepCount?: number;
22
+ }
6
23
  export interface RunOptions {
7
24
  agentId: string;
8
25
  variables?: Record<string, string>;
26
+ /** Runtime model overrides for load balancing, fallbacks, etc. */
27
+ overrides?: ModelOverrides;
28
+ /** Extra messages to append to the agent's prompt (used as-is, no variable substitution) */
29
+ extraMessages?: ModelMessage[];
9
30
  }
10
31
  export interface GenerateResponse {
11
32
  messages: ModelMessage[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent0-js",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "TypeScript SDK for Agent0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -36,6 +36,8 @@ export class Agent0 {
36
36
  const response = await this.fetchApi('/api/v1/run', {
37
37
  agent_id: options.agentId,
38
38
  variables: options.variables,
39
+ overrides: options.overrides,
40
+ extra_messages: options.extraMessages,
39
41
  stream: false,
40
42
  });
41
43
 
@@ -46,6 +48,8 @@ export class Agent0 {
46
48
  const response = await this.fetchApi('/api/v1/run', {
47
49
  agent_id: options.agentId,
48
50
  variables: options.variables,
51
+ overrides: options.overrides,
52
+ extra_messages: options.extraMessages,
49
53
  stream: true,
50
54
  });
51
55
 
package/src/types.ts CHANGED
@@ -5,9 +5,31 @@ export interface Agent0Config {
5
5
  baseUrl?: string;
6
6
  }
7
7
 
8
+ /**
9
+ * Model configuration overrides for runtime customization.
10
+ * Allows downstream applications to implement load balancing, fallbacks, and dynamic model switching.
11
+ */
12
+ export interface ModelOverrides {
13
+ /** Override the model provider and name */
14
+ model?: {
15
+ provider_id?: string;
16
+ name?: string;
17
+ };
18
+ /** Override max output tokens */
19
+ maxOutputTokens?: number;
20
+ /** Override temperature */
21
+ temperature?: number;
22
+ /** Override max step count */
23
+ maxStepCount?: number;
24
+ }
25
+
8
26
  export interface RunOptions {
9
27
  agentId: string;
10
28
  variables?: Record<string, string>;
29
+ /** Runtime model overrides for load balancing, fallbacks, etc. */
30
+ overrides?: ModelOverrides;
31
+ /** Extra messages to append to the agent's prompt (used as-is, no variable substitution) */
32
+ extraMessages?: ModelMessage[];
11
33
  }
12
34
 
13
35
  export interface GenerateResponse {