agent0-js 0.0.12 → 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 +50 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
- package/src/index.ts +13 -0
- package/src/types.ts +11 -0
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,6 +86,7 @@ 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
|
|
@@ -454,6 +456,54 @@ const response = await client.generate({
|
|
|
454
456
|
// Prompt becomes: "Hello Sarah, let's talk about machine learning"
|
|
455
457
|
```
|
|
456
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
|
+
|
|
457
507
|
### Model Overrides
|
|
458
508
|
|
|
459
509
|
The `overrides` option allows you to dynamically configure the model at runtime. This is useful for:
|
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, CustomTool, 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,6 +27,7 @@ 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,
|
|
@@ -38,6 +39,7 @@ class Agent0 {
|
|
|
38
39
|
async *stream(options) {
|
|
39
40
|
const response = await this.fetchApi("/api/v1/run", {
|
|
40
41
|
agent_id: options.agentId,
|
|
42
|
+
environment: options.environment,
|
|
41
43
|
variables: options.variables,
|
|
42
44
|
overrides: options.overrides,
|
|
43
45
|
extra_messages: options.extraMessages,
|
package/dist/types.d.ts
CHANGED
|
@@ -50,8 +50,16 @@ export interface CustomTool {
|
|
|
50
50
|
/** JSON Schema defining the parameters this tool accepts */
|
|
51
51
|
inputSchema?: Record<string, unknown>;
|
|
52
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";
|
|
53
59
|
export interface RunOptions {
|
|
54
60
|
agentId: string;
|
|
61
|
+
/** Environment to run ('staging' or 'production'). Defaults to 'production'. */
|
|
62
|
+
environment?: Environment;
|
|
55
63
|
variables?: Record<string, string>;
|
|
56
64
|
/** Runtime model overrides for load balancing, fallbacks, etc. */
|
|
57
65
|
overrides?: ModelOverrides;
|
package/package.json
CHANGED
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,6 +56,7 @@ 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,
|
|
@@ -61,6 +72,7 @@ export class Agent0 {
|
|
|
61
72
|
): AsyncGenerator<TextStreamPart<ToolSet>, void, unknown> {
|
|
62
73
|
const response = await this.fetchApi("/api/v1/run", {
|
|
63
74
|
agent_id: options.agentId,
|
|
75
|
+
environment: this.resolveEnvironment(options.environment),
|
|
64
76
|
variables: options.variables,
|
|
65
77
|
overrides: options.overrides,
|
|
66
78
|
extra_messages: options.extraMessages,
|
|
@@ -142,6 +154,7 @@ export type {
|
|
|
142
154
|
EmbedModel,
|
|
143
155
|
EmbedOptions,
|
|
144
156
|
EmbedResponse,
|
|
157
|
+
Environment,
|
|
145
158
|
GenerateResponse,
|
|
146
159
|
ModelOverrides,
|
|
147
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
|
/**
|
|
@@ -55,8 +57,17 @@ export interface CustomTool {
|
|
|
55
57
|
inputSchema?: Record<string, unknown>;
|
|
56
58
|
}
|
|
57
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
|
+
|
|
58
67
|
export interface RunOptions {
|
|
59
68
|
agentId: string;
|
|
69
|
+
/** Environment to run ('staging' or 'production'). Defaults to 'production'. */
|
|
70
|
+
environment?: Environment;
|
|
60
71
|
variables?: Record<string, string>;
|
|
61
72
|
/** Runtime model overrides for load balancing, fallbacks, etc. */
|
|
62
73
|
overrides?: ModelOverrides;
|