agent0-js 0.0.5 → 0.0.7

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,36 @@ 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
101
+ providerOptions?: ProviderOptions; // Provider-specific reasoning options
102
+ }
103
+
104
+ interface ProviderOptions {
105
+ openai?: {
106
+ reasoningEffort?: 'minimal' | 'low' | 'medium' | 'high';
107
+ reasoningSummary?: 'auto' | 'detailed';
108
+ };
109
+ xai?: {
110
+ reasoningEffort?: 'low' | 'medium' | 'high';
111
+ };
112
+ google?: {
113
+ thinkingConfig?: {
114
+ thinkingBudget?: number;
115
+ thinkingLevel?: 'low' | 'medium' | 'high';
116
+ includeThoughts?: boolean;
117
+ };
118
+ };
89
119
  }
90
120
  ```
91
121
 
@@ -226,6 +256,151 @@ const response = await client.generate({
226
256
  // Prompt becomes: "Hello Sarah, let's talk about machine learning"
227
257
  ```
228
258
 
259
+ ### Model Overrides
260
+
261
+ The `overrides` option allows you to dynamically configure the model at runtime. This is useful for:
262
+ - **Load Balancing**: Distribute requests across different providers
263
+ - **Fallbacks**: Switch to a backup model if the primary is unavailable
264
+ - **A/B Testing**: Test different models with the same agent configuration
265
+ - **Cost Optimization**: Use cheaper models for non-critical requests
266
+
267
+ ```typescript
268
+ // Override the model for a specific request
269
+ const response = await client.generate({
270
+ agentId: 'agent_123',
271
+ variables: { prompt: 'Hello world' },
272
+ overrides: {
273
+ model: { name: 'gpt-4o-mini' }, // Use a different model
274
+ temperature: 0.5, // Adjust temperature
275
+ maxOutputTokens: 500 // Limit output length
276
+ }
277
+ });
278
+
279
+ // Implement a simple fallback pattern
280
+ async function runWithFallback(agentId: string, variables: Record<string, string>) {
281
+ try {
282
+ return await client.generate({ agentId, variables });
283
+ } catch (error) {
284
+ // Fallback to a different provider/model
285
+ return await client.generate({
286
+ agentId,
287
+ variables,
288
+ overrides: {
289
+ model: {
290
+ provider_id: 'backup-provider-id',
291
+ name: 'claude-3-haiku-20240307'
292
+ }
293
+ }
294
+ });
295
+ }
296
+ }
297
+ ```
298
+
299
+ ### Provider Options
300
+
301
+ The `providerOptions` option allows you to configure provider-specific reasoning and thinking behavior. Different providers have different options:
302
+
303
+ **OpenAI / Azure** - Use `reasoningEffort` to control how much reasoning the model does, and `reasoningSummary` to control whether the model returns its reasoning process:
304
+
305
+ ```typescript
306
+ const response = await client.generate({
307
+ agentId: 'agent_123',
308
+ overrides: {
309
+ providerOptions: {
310
+ openai: {
311
+ reasoningEffort: 'high', // 'minimal' | 'low' | 'medium' | 'high'
312
+ reasoningSummary: 'auto' // 'auto' | 'detailed' - controls reasoning output
313
+ }
314
+ }
315
+ }
316
+ });
317
+ ```
318
+
319
+ - `reasoningSummary: 'auto'` - Returns a condensed summary of the reasoning process
320
+ - `reasoningSummary: 'detailed'` - Returns more comprehensive reasoning
321
+ - When enabled, reasoning summaries appear in the stream as events with type `'reasoning'` and in non-streaming responses within the `reasoning` field
322
+
323
+ **xAI (Grok)** - Use `reasoningEffort` to control reasoning:
324
+
325
+ ```typescript
326
+ const response = await client.generate({
327
+ agentId: 'agent_123',
328
+ overrides: {
329
+ providerOptions: {
330
+ xai: {
331
+ reasoningEffort: 'high' // 'low' | 'medium' | 'high'
332
+ }
333
+ }
334
+ }
335
+ });
336
+ ```
337
+
338
+ **Google Generative AI / Google Vertex** - Use `thinkingConfig` to control thinking (use either `thinkingLevel` or `thinkingBudget`, not both):
339
+
340
+ ```typescript
341
+ // Using thinkingLevel (recommended for most cases)
342
+ const response = await client.generate({
343
+ agentId: 'agent_123',
344
+ overrides: {
345
+ providerOptions: {
346
+ google: {
347
+ thinkingConfig: {
348
+ thinkingLevel: 'high', // 'low' | 'medium' | 'high'
349
+ includeThoughts: true // Include thinking in response
350
+ }
351
+ }
352
+ }
353
+ }
354
+ });
355
+
356
+ // OR using thinkingBudget (for fine-grained control)
357
+ const response = await client.generate({
358
+ agentId: 'agent_123',
359
+ overrides: {
360
+ providerOptions: {
361
+ google: {
362
+ thinkingConfig: {
363
+ thinkingBudget: 8192, // Number of thinking tokens
364
+ includeThoughts: true
365
+ }
366
+ }
367
+ }
368
+ }
369
+ });
370
+ ```
371
+
372
+ ### Extra Messages
373
+
374
+ 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:
375
+ - **Dynamic Context**: Add conversation history or context at runtime
376
+ - **Multi-turn Conversations**: Build chat applications by appending user/assistant turns
377
+ - **Retrieved Content**: Inject RAG results or retrieved documents
378
+
379
+ ```typescript
380
+ // Add conversation history to the agent
381
+ const response = await client.generate({
382
+ agentId: 'agent_123',
383
+ variables: { topic: 'AI' },
384
+ extraMessages: [
385
+ { role: 'user', content: 'What is machine learning?' },
386
+ { role: 'assistant', content: 'Machine learning is a subset of AI...' },
387
+ { role: 'user', content: 'Tell me more about neural networks' }
388
+ ]
389
+ });
390
+
391
+ // Inject retrieved context (RAG pattern)
392
+ const retrievedDocs = await searchDocuments(query);
393
+ const response = await client.generate({
394
+ agentId: 'rag-agent',
395
+ extraMessages: [
396
+ {
397
+ role: 'user',
398
+ content: `Context:\n${retrievedDocs.join('\n')}\n\nQuestion: ${query}`
399
+ }
400
+ ]
401
+ });
402
+ ```
403
+
229
404
  ### Error Handling
230
405
 
231
406
  ```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
@@ -1,11 +1,49 @@
1
+ import type { GoogleGenerativeAIProviderOptions } from "@ai-sdk/google";
2
+ import type { OpenAIResponsesProviderOptions } from "@ai-sdk/openai";
3
+ import type { XaiProviderOptions } from "@ai-sdk/xai";
1
4
  import type { ModelMessage } from "ai";
2
5
  export interface Agent0Config {
3
6
  apiKey: string;
4
7
  baseUrl?: string;
5
8
  }
9
+ /**
10
+ * Provider-specific options for reasoning/thinking configuration.
11
+ * Each provider has its own format for controlling reasoning behavior.
12
+ */
13
+ export interface ProviderOptions {
14
+ /** OpenAI reasoning effort options */
15
+ openai?: OpenAIResponsesProviderOptions;
16
+ /** xAI reasoning effort options */
17
+ xai?: XaiProviderOptions;
18
+ /** Google/Vertex thinking configuration */
19
+ google?: GoogleGenerativeAIProviderOptions;
20
+ }
21
+ /**
22
+ * Model configuration overrides for runtime customization.
23
+ * Allows downstream applications to implement load balancing, fallbacks, and dynamic model switching.
24
+ */
25
+ export interface ModelOverrides {
26
+ /** Override the model provider and name */
27
+ model?: {
28
+ provider_id?: string;
29
+ name?: string;
30
+ };
31
+ /** Override max output tokens */
32
+ maxOutputTokens?: number;
33
+ /** Override temperature */
34
+ temperature?: number;
35
+ /** Override max step count */
36
+ maxStepCount?: number;
37
+ /** Provider-specific options for reasoning/thinking configuration */
38
+ providerOptions?: ProviderOptions;
39
+ }
6
40
  export interface RunOptions {
7
41
  agentId: string;
8
42
  variables?: Record<string, string>;
43
+ /** Runtime model overrides for load balancing, fallbacks, etc. */
44
+ overrides?: ModelOverrides;
45
+ /** Extra messages to append to the agent's prompt (used as-is, no variable substitution) */
46
+ extraMessages?: ModelMessage[];
9
47
  }
10
48
  export interface GenerateResponse {
11
49
  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.7",
4
4
  "description": "TypeScript SDK for Agent0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,6 +17,9 @@
17
17
  "typescript": "^5.0.0"
18
18
  },
19
19
  "dependencies": {
20
+ "@ai-sdk/google": "3.0.0-beta.69",
21
+ "@ai-sdk/openai": "3.0.0-beta.90",
22
+ "@ai-sdk/xai": "3.0.0-beta.54",
20
23
  "ai": "^5.0.98"
21
24
  },
22
25
  "scripts": {
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
@@ -1,16 +1,56 @@
1
+ import type { GoogleGenerativeAIProviderOptions } from "@ai-sdk/google";
2
+ import type { OpenAIResponsesProviderOptions } from "@ai-sdk/openai";
3
+ import type { XaiProviderOptions } from "@ai-sdk/xai";
1
4
  import type { ModelMessage } from "ai";
2
5
 
3
6
  export interface Agent0Config {
4
- apiKey: string;
5
- baseUrl?: string;
7
+ apiKey: string;
8
+ baseUrl?: string;
9
+ }
10
+
11
+ /**
12
+ * Provider-specific options for reasoning/thinking configuration.
13
+ * Each provider has its own format for controlling reasoning behavior.
14
+ */
15
+ export interface ProviderOptions {
16
+ /** OpenAI reasoning effort options */
17
+ openai?: OpenAIResponsesProviderOptions;
18
+ /** xAI reasoning effort options */
19
+ xai?: XaiProviderOptions;
20
+ /** Google/Vertex thinking configuration */
21
+ google?: GoogleGenerativeAIProviderOptions;
22
+ }
23
+
24
+ /**
25
+ * Model configuration overrides for runtime customization.
26
+ * Allows downstream applications to implement load balancing, fallbacks, and dynamic model switching.
27
+ */
28
+ export interface ModelOverrides {
29
+ /** Override the model provider and name */
30
+ model?: {
31
+ provider_id?: string;
32
+ name?: string;
33
+ };
34
+ /** Override max output tokens */
35
+ maxOutputTokens?: number;
36
+ /** Override temperature */
37
+ temperature?: number;
38
+ /** Override max step count */
39
+ maxStepCount?: number;
40
+ /** Provider-specific options for reasoning/thinking configuration */
41
+ providerOptions?: ProviderOptions;
6
42
  }
7
43
 
8
44
  export interface RunOptions {
9
- agentId: string;
10
- variables?: Record<string, string>;
45
+ agentId: string;
46
+ variables?: Record<string, string>;
47
+ /** Runtime model overrides for load balancing, fallbacks, etc. */
48
+ overrides?: ModelOverrides;
49
+ /** Extra messages to append to the agent's prompt (used as-is, no variable substitution) */
50
+ extraMessages?: ModelMessage[];
11
51
  }
12
52
 
13
53
  export interface GenerateResponse {
14
- messages: ModelMessage[];
15
- text: string;
54
+ messages: ModelMessage[];
55
+ text: string;
16
56
  }