agent0-js 0.0.11 → 0.0.13

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
@@ -73,6 +73,7 @@ const client = new Agent0({
73
73
  |--------|------|----------|---------|-------------|
74
74
  | `apiKey` | `string` | Yes | - | Your Agent0 API key |
75
75
  | `baseUrl` | `string` | No | `https://app.agent0.com` | The base URL for the Agent0 API |
76
+ | `environment` | `'staging' \| 'production'` | No | `'production'` | Default environment for all runs (can be overridden per-run) |
76
77
 
77
78
  ## Methods
78
79
 
@@ -85,9 +86,17 @@ Execute an agent and get the complete response.
85
86
  ```typescript
86
87
  interface RunOptions {
87
88
  agentId: string; // The ID of the agent to run
89
+ environment?: 'staging' | 'production'; // Environment to run (default: 'production')
88
90
  variables?: Record<string, string>; // Variables to pass to the agent
89
91
  overrides?: ModelOverrides; // Runtime model configuration overrides
90
92
  extraMessages?: Message[]; // Extra messages to append to the prompt
93
+ extraTools?: CustomTool[]; // Additional custom tools to add at runtime
94
+ }
95
+
96
+ interface CustomTool {
97
+ title: string; // Unique title for the tool (lowercase with underscores)
98
+ description: string; // Description of what the tool does
99
+ inputSchema?: Record<string, unknown>; // JSON Schema for the tool's parameters
91
100
  }
92
101
 
93
102
  interface ModelOverrides {
@@ -447,6 +456,54 @@ const response = await client.generate({
447
456
  // Prompt becomes: "Hello Sarah, let's talk about machine learning"
448
457
  ```
449
458
 
459
+ ### Staging and Production Environments
460
+
461
+ Agent0 supports deploying different versions of your agent to staging and production environments. This allows you to test changes before rolling them out to production.
462
+
463
+ The environment can be set at two levels with the following priority:
464
+ 1. **Run-level** (highest priority): Set `environment` in `generate()` or `stream()` options
465
+ 2. **Constructor-level**: Set `environment` when creating the `Agent0` client
466
+ 3. **Default**: Falls back to `'production'`
467
+
468
+ ```typescript
469
+ // Set default environment at constructor level
470
+ const stagingClient = new Agent0({
471
+ apiKey: process.env.AGENT0_API_KEY!,
472
+ environment: 'staging' // All runs will use staging by default
473
+ });
474
+
475
+ // This uses 'staging' from constructor
476
+ const response1 = await stagingClient.generate({
477
+ agentId: 'agent_123',
478
+ variables: { name: 'Test User' }
479
+ });
480
+
481
+ // Override constructor setting at run level
482
+ const response2 = await stagingClient.generate({
483
+ agentId: 'agent_123',
484
+ environment: 'production', // Overrides the constructor's 'staging'
485
+ variables: { name: 'Real User' }
486
+ });
487
+
488
+ // Default client (no constructor environment) uses 'production'
489
+ const defaultClient = new Agent0({
490
+ apiKey: process.env.AGENT0_API_KEY!
491
+ });
492
+
493
+ // This uses 'production' (the default)
494
+ const response3 = await defaultClient.generate({
495
+ agentId: 'agent_123',
496
+ variables: { name: 'User' }
497
+ });
498
+
499
+ // Run-level environment takes precedence
500
+ const response4 = await defaultClient.generate({
501
+ agentId: 'agent_123',
502
+ environment: 'staging',
503
+ variables: { name: 'Test User' }
504
+ });
505
+ ```
506
+
450
507
  ### Model Overrides
451
508
 
452
509
  The `overrides` option allows you to dynamically configure the model at runtime. This is useful for:
@@ -592,6 +649,95 @@ const response = await client.generate({
592
649
  });
593
650
  ```
594
651
 
652
+ ### Custom Tools (extraTools)
653
+
654
+ The `extraTools` option allows you to add custom tool definitions at runtime. These tools are merged with any tools defined in the agent configuration. Custom tools enable function calling without requiring an MCP server - the LLM will generate tool calls, but **execution must be handled externally** by your application.
655
+
656
+ This is useful for:
657
+ - **Dynamic Tool Injection**: Add context-specific tools at runtime
658
+ - **Function Calling Patterns**: Define tools that your application will execute
659
+ - **Hybrid Agents**: Combine MCP server tools with custom tools
660
+
661
+ ```typescript
662
+ // Define custom tools for function calling
663
+ const response = await client.generate({
664
+ agentId: 'agent_123',
665
+ extraTools: [
666
+ {
667
+ title: 'get_weather',
668
+ description: 'Get the current weather for a location',
669
+ inputSchema: {
670
+ type: 'object',
671
+ properties: {
672
+ location: {
673
+ type: 'string',
674
+ description: 'City name or zip code'
675
+ },
676
+ units: {
677
+ type: 'string',
678
+ enum: ['celsius', 'fahrenheit'],
679
+ description: 'Temperature units'
680
+ }
681
+ },
682
+ required: ['location']
683
+ }
684
+ },
685
+ {
686
+ title: 'search_database',
687
+ description: 'Search the company database for information',
688
+ inputSchema: {
689
+ type: 'object',
690
+ properties: {
691
+ query: { type: 'string', description: 'Search query' },
692
+ limit: { type: 'number', description: 'Max results to return' }
693
+ },
694
+ required: ['query']
695
+ }
696
+ }
697
+ ]
698
+ });
699
+
700
+ // The response may contain tool calls that your app needs to handle
701
+ for (const message of response.messages) {
702
+ if (message.role === 'assistant') {
703
+ for (const part of message.content) {
704
+ if (part.type === 'tool-call') {
705
+ console.log('Tool called:', part.toolName);
706
+ console.log('Arguments:', part.args);
707
+ // Execute the tool and provide results back to the agent
708
+ }
709
+ }
710
+ }
711
+ }
712
+ ```
713
+
714
+ **Streaming with Custom Tools:**
715
+
716
+ ```typescript
717
+ const stream = client.stream({
718
+ agentId: 'agent_123',
719
+ extraTools: [
720
+ {
721
+ title: 'lookup_user',
722
+ description: 'Look up user information by ID',
723
+ inputSchema: {
724
+ type: 'object',
725
+ properties: {
726
+ userId: { type: 'string' }
727
+ },
728
+ required: ['userId']
729
+ }
730
+ }
731
+ ]
732
+ });
733
+
734
+ for await (const chunk of stream) {
735
+ if (chunk.type === 'tool-call') {
736
+ console.log(`Tool ${chunk.toolName} called with:`, chunk.args);
737
+ }
738
+ }
739
+ ```
740
+
595
741
  ### Error Handling
596
742
 
597
743
  ```typescript
package/dist/index.d.ts CHANGED
@@ -24,4 +24,4 @@ export declare class Agent0 {
24
24
  */
25
25
  embedMany(options: EmbedManyOptions): Promise<EmbedManyResponse>;
26
26
  }
27
- export type { Agent0Config, EmbedManyOptions, EmbedManyResponse, EmbedModel, EmbedOptions, EmbedResponse, GenerateResponse, ModelOverrides, ProviderOptions, RunOptions, } from "./types";
27
+ export type { Agent0Config, CustomTool, EmbedManyOptions, EmbedManyResponse, EmbedModel, EmbedOptions, EmbedResponse, Environment, GenerateResponse, ModelOverrides, ProviderOptions, RunOptions, } from "./types";
package/dist/index.js CHANGED
@@ -27,9 +27,11 @@ class Agent0 {
27
27
  async generate(options) {
28
28
  const response = await this.fetchApi("/api/v1/run", {
29
29
  agent_id: options.agentId,
30
+ environment: options.environment,
30
31
  variables: options.variables,
31
32
  overrides: options.overrides,
32
33
  extra_messages: options.extraMessages,
34
+ extra_tools: options.extraTools,
33
35
  stream: false,
34
36
  });
35
37
  return await response.json();
@@ -37,9 +39,11 @@ class Agent0 {
37
39
  async *stream(options) {
38
40
  const response = await this.fetchApi("/api/v1/run", {
39
41
  agent_id: options.agentId,
42
+ environment: options.environment,
40
43
  variables: options.variables,
41
44
  overrides: options.overrides,
42
45
  extra_messages: options.extraMessages,
46
+ extra_tools: options.extraTools,
43
47
  stream: true,
44
48
  });
45
49
  if (!response.body) {
package/dist/types.d.ts CHANGED
@@ -37,13 +37,36 @@ export interface ModelOverrides {
37
37
  /** Provider-specific options for reasoning/thinking configuration */
38
38
  providerOptions?: ProviderOptions;
39
39
  }
40
+ /**
41
+ * A custom tool defined at runtime.
42
+ * Custom tools have title, description, and inputSchema but no execute function.
43
+ * The LLM will generate tool calls for these, but execution must be handled externally.
44
+ */
45
+ export interface CustomTool {
46
+ /** Unique title for the tool (lowercase with underscores recommended) */
47
+ title: string;
48
+ /** Description of what the tool does - helps the AI understand when to use it */
49
+ description: string;
50
+ /** JSON Schema defining the parameters this tool accepts */
51
+ inputSchema?: Record<string, unknown>;
52
+ }
53
+ /**
54
+ * Environment to run the agent in.
55
+ * - 'staging': Run the staging-deployed version of the agent
56
+ * - 'production': Run the production-deployed version of the agent (default)
57
+ */
58
+ export type Environment = "staging" | "production";
40
59
  export interface RunOptions {
41
60
  agentId: string;
61
+ /** Environment to run ('staging' or 'production'). Defaults to 'production'. */
62
+ environment?: Environment;
42
63
  variables?: Record<string, string>;
43
64
  /** Runtime model overrides for load balancing, fallbacks, etc. */
44
65
  overrides?: ModelOverrides;
45
66
  /** Extra messages to append to the agent's prompt (used as-is, no variable substitution) */
46
67
  extraMessages?: ModelMessage[];
68
+ /** Additional custom tools to add at runtime. These are merged with any tools defined in the agent. */
69
+ extraTools?: CustomTool[];
47
70
  }
48
71
  export interface GenerateResponse {
49
72
  messages: ModelMessage[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent0-js",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
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
@@ -5,6 +5,7 @@ import type {
5
5
  EmbedManyResponse,
6
6
  EmbedOptions,
7
7
  EmbedResponse,
8
+ Environment,
8
9
  GenerateResponse,
9
10
  RunOptions,
10
11
  } from "./types";
@@ -12,10 +13,19 @@ import type {
12
13
  export class Agent0 {
13
14
  private apiKey: string;
14
15
  private baseUrl: string;
16
+ private environment?: Environment;
15
17
 
16
18
  constructor(config: Agent0Config) {
17
19
  this.apiKey = config.apiKey;
18
20
  this.baseUrl = config.baseUrl || "https://app.agent0.com"; // Default URL, can be overridden
21
+ this.environment = config.environment;
22
+ }
23
+
24
+ /**
25
+ * Resolve the environment to use: run-level > constructor-level > default 'production'
26
+ */
27
+ private resolveEnvironment(runEnvironment?: Environment): Environment {
28
+ return runEnvironment ?? this.environment ?? "production";
19
29
  }
20
30
 
21
31
  private async fetchApi(endpoint: string, body: unknown): Promise<Response> {
@@ -46,9 +56,11 @@ export class Agent0 {
46
56
  async generate(options: RunOptions): Promise<GenerateResponse> {
47
57
  const response = await this.fetchApi("/api/v1/run", {
48
58
  agent_id: options.agentId,
59
+ environment: this.resolveEnvironment(options.environment),
49
60
  variables: options.variables,
50
61
  overrides: options.overrides,
51
62
  extra_messages: options.extraMessages,
63
+ extra_tools: options.extraTools,
52
64
  stream: false,
53
65
  });
54
66
 
@@ -60,9 +72,11 @@ export class Agent0 {
60
72
  ): AsyncGenerator<TextStreamPart<ToolSet>, void, unknown> {
61
73
  const response = await this.fetchApi("/api/v1/run", {
62
74
  agent_id: options.agentId,
75
+ environment: this.resolveEnvironment(options.environment),
63
76
  variables: options.variables,
64
77
  overrides: options.overrides,
65
78
  extra_messages: options.extraMessages,
79
+ extra_tools: options.extraTools,
66
80
  stream: true,
67
81
  });
68
82
 
@@ -134,11 +148,13 @@ export class Agent0 {
134
148
  // Re-export types for convenience
135
149
  export type {
136
150
  Agent0Config,
151
+ CustomTool,
137
152
  EmbedManyOptions,
138
153
  EmbedManyResponse,
139
154
  EmbedModel,
140
155
  EmbedOptions,
141
156
  EmbedResponse,
157
+ Environment,
142
158
  GenerateResponse,
143
159
  ModelOverrides,
144
160
  ProviderOptions,
package/src/types.ts CHANGED
@@ -6,6 +6,8 @@ import type { embed, embedMany, ModelMessage } from "ai";
6
6
  export interface Agent0Config {
7
7
  apiKey: string;
8
8
  baseUrl?: string;
9
+ /** Default environment to use for all runs. Can be overridden per-run. Defaults to 'production'. */
10
+ environment?: Environment;
9
11
  }
10
12
 
11
13
  /**
@@ -41,13 +43,38 @@ export interface ModelOverrides {
41
43
  providerOptions?: ProviderOptions;
42
44
  }
43
45
 
46
+ /**
47
+ * A custom tool defined at runtime.
48
+ * Custom tools have title, description, and inputSchema but no execute function.
49
+ * The LLM will generate tool calls for these, but execution must be handled externally.
50
+ */
51
+ export interface CustomTool {
52
+ /** Unique title for the tool (lowercase with underscores recommended) */
53
+ title: string;
54
+ /** Description of what the tool does - helps the AI understand when to use it */
55
+ description: string;
56
+ /** JSON Schema defining the parameters this tool accepts */
57
+ inputSchema?: Record<string, unknown>;
58
+ }
59
+
60
+ /**
61
+ * Environment to run the agent in.
62
+ * - 'staging': Run the staging-deployed version of the agent
63
+ * - 'production': Run the production-deployed version of the agent (default)
64
+ */
65
+ export type Environment = "staging" | "production";
66
+
44
67
  export interface RunOptions {
45
68
  agentId: string;
69
+ /** Environment to run ('staging' or 'production'). Defaults to 'production'. */
70
+ environment?: Environment;
46
71
  variables?: Record<string, string>;
47
72
  /** Runtime model overrides for load balancing, fallbacks, etc. */
48
73
  overrides?: ModelOverrides;
49
74
  /** Extra messages to append to the agent's prompt (used as-is, no variable substitution) */
50
75
  extraMessages?: ModelMessage[];
76
+ /** Additional custom tools to add at runtime. These are merged with any tools defined in the agent. */
77
+ extraTools?: CustomTool[];
51
78
  }
52
79
 
53
80
  export interface GenerateResponse {