@amitdeshmukh/ax-crew 8.5.0 → 8.7.0
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/.claude/settings.local.json +3 -1
- package/.claude/skills/ax-crew/SKILL.md +466 -0
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +7 -7
- package/examples/run-crew-workflow.ts +2 -2
- package/package.json +3 -1
- package/scripts/install-skills.mjs +59 -0
- package/scripts/uninstall-skills.mjs +25 -0
- package/src/skills/ax-crew-ace.md +165 -0
- package/src/skills/ax-crew-agent-config.md +181 -0
- package/src/skills/ax-crew-code-execution.md +166 -0
- package/src/skills/ax-crew-execution-modes.md +287 -0
- package/src/skills/ax-crew-few-shot.md +165 -0
- package/src/skills/ax-crew-functions.md +218 -0
- package/src/skills/ax-crew-mcp.md +221 -0
- package/src/skills/ax-crew-metrics.md +170 -0
- package/src/skills/ax-crew-patterns.md +286 -0
- package/src/skills/ax-crew-providers.md +204 -0
- package/src/skills/ax-crew-signatures.md +169 -0
- package/src/skills/ax-crew-state.md +168 -0
- package/src/skills/ax-crew-streaming.md +143 -0
- package/src/skills/ax-crew-sub-agents.md +203 -0
- package/src/skills/ax-crew-telemetry.md +161 -0
- package/src/skills/ax-crew.md +124 -0
- package/examples/run-manager.ts +0 -98
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ax-crew-ace
|
|
3
|
+
version: __VERSION__
|
|
4
|
+
description: "ACE (Agentic Context Engineering) for AxCrew: feedback loops, online learning, playbook persistence, and optimization."
|
|
5
|
+
tags: [ace, agentic-context-engineering, feedback, learning, playbook, online-update, optimize]
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# ACE (Agentic Context Engineering)
|
|
9
|
+
|
|
10
|
+
ACE enables agents to learn from human feedback at runtime. Feedback is analyzed, categorized into playbook sections, and injected into the agent's system prompt on every subsequent `forward()` call.
|
|
11
|
+
|
|
12
|
+
## ACEConfig Shape
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
interface ACEConfig {
|
|
16
|
+
teacher?: {
|
|
17
|
+
provider?: Provider;
|
|
18
|
+
providerKeyName?: string;
|
|
19
|
+
apiURL?: string;
|
|
20
|
+
ai?: AxModelConfig & { model: string };
|
|
21
|
+
providerArgs?: Record<string, unknown>;
|
|
22
|
+
};
|
|
23
|
+
persistence?: {
|
|
24
|
+
playbookPath?: string;
|
|
25
|
+
initialPlaybook?: Record<string, any>;
|
|
26
|
+
autoPersist?: boolean;
|
|
27
|
+
onPersist?: (pb: any) => Promise<void> | void;
|
|
28
|
+
onLoad?: () => Promise<any> | any;
|
|
29
|
+
};
|
|
30
|
+
options?: {
|
|
31
|
+
maxEpochs?: number;
|
|
32
|
+
allowDynamicSections?: boolean;
|
|
33
|
+
tokenBudget?: number;
|
|
34
|
+
reflectorPrompt?: string;
|
|
35
|
+
curatorPrompt?: string;
|
|
36
|
+
};
|
|
37
|
+
metric?: {
|
|
38
|
+
metricFnName?: string;
|
|
39
|
+
primaryOutputField?: string;
|
|
40
|
+
};
|
|
41
|
+
compileOnStart?: boolean;
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Agent-Level ACE API
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// StatefulAxAgent methods:
|
|
49
|
+
await agent.initACE(aceConfig); // called automatically during addAgent()
|
|
50
|
+
await agent.applyOnlineUpdate({ example, prediction, feedback }); // learn from feedback
|
|
51
|
+
agent.getPlaybook(); // returns current ACEPlaybook
|
|
52
|
+
agent.applyPlaybook(playbook); // set playbook directly
|
|
53
|
+
await agent.optimizeOffline({ metric, examples }); // offline compilation
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Crew-Level Feedback Routing
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// AxCrew tracks which agents participated in a task and routes feedback to all of them:
|
|
60
|
+
crew.trackAgentExecution(taskId, agentName, input); // automatic during forward()
|
|
61
|
+
crew.recordAgentResult(taskId, agentName, result); // automatic during forward()
|
|
62
|
+
await crew.applyTaskFeedback({ taskId, feedback, strategy: "all" | "primary" | "weighted" });
|
|
63
|
+
crew.getTaskAgentInvolvement(taskId); // inspect execution history
|
|
64
|
+
crew.cleanupOldExecutions(maxAgeMs); // prevent memory leaks
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Playbook Persistence
|
|
68
|
+
|
|
69
|
+
Three persistence options (checked in order):
|
|
70
|
+
1. `onLoad` callback -- custom async loader
|
|
71
|
+
2. `initialPlaybook` -- inline playbook object
|
|
72
|
+
3. `playbookPath` -- JSON file on disk (auto-created)
|
|
73
|
+
|
|
74
|
+
Auto-save: set `autoPersist: true` with `playbookPath` or `onPersist` callback.
|
|
75
|
+
|
|
76
|
+
## Canonical Pattern
|
|
77
|
+
|
|
78
|
+
Adapted from `examples/ace-customer-support.ts` -- an agent that learns customer support exception policies from supervisor feedback.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
import { AxCrew } from "ax-crew";
|
|
82
|
+
import type { AxCrewConfig, Provider } from "ax-crew";
|
|
83
|
+
|
|
84
|
+
const config: AxCrewConfig = {
|
|
85
|
+
crew: [
|
|
86
|
+
{
|
|
87
|
+
name: "SupportAgent",
|
|
88
|
+
description: "Customer support agent. Follow company policies strictly.",
|
|
89
|
+
signature: "ticket:string, policies:string[] -> response:string, decision:string",
|
|
90
|
+
provider: "google-gemini" as Provider,
|
|
91
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
92
|
+
ai: { model: "gemini-flash-latest", temperature: 0.7 },
|
|
93
|
+
options: { stream: false },
|
|
94
|
+
ace: {
|
|
95
|
+
teacher: {
|
|
96
|
+
provider: "google-gemini" as Provider,
|
|
97
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
98
|
+
ai: { model: "gemini-flash-latest" },
|
|
99
|
+
},
|
|
100
|
+
options: { maxEpochs: 1, allowDynamicSections: true },
|
|
101
|
+
persistence: {
|
|
102
|
+
playbookPath: "playbooks/support.json",
|
|
103
|
+
autoPersist: true,
|
|
104
|
+
},
|
|
105
|
+
metric: { primaryOutputField: "response" },
|
|
106
|
+
compileOnStart: false,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
async function main() {
|
|
113
|
+
const crew = new AxCrew(config);
|
|
114
|
+
await crew.addAgentsToCrew(["SupportAgent"]);
|
|
115
|
+
const agent = crew.agents!.get("SupportAgent")!;
|
|
116
|
+
|
|
117
|
+
// Run the agent
|
|
118
|
+
const result = await agent.forward({
|
|
119
|
+
ticket: "Customer wants refund on sale item (defective on arrival)",
|
|
120
|
+
policies: ["No refunds on sale items", "Returns within 30 days only"],
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
console.log(result.response, result.decision);
|
|
124
|
+
|
|
125
|
+
// Apply feedback -- agent learns for future calls
|
|
126
|
+
const taskId = (result as any)._taskId;
|
|
127
|
+
if (taskId) {
|
|
128
|
+
await crew.applyTaskFeedback({
|
|
129
|
+
taskId,
|
|
130
|
+
feedback: "Defective products must always be refunded regardless of sale status",
|
|
131
|
+
strategy: "all",
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Or apply directly to agent (without task routing)
|
|
136
|
+
await (agent as any).applyOnlineUpdate({
|
|
137
|
+
example: { ticket: "..." },
|
|
138
|
+
prediction: result,
|
|
139
|
+
feedback: "Medical emergencies extend the 30-day window to 60 days",
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Inspect learned playbook
|
|
143
|
+
const playbook = (agent as any).getPlaybook();
|
|
144
|
+
console.log(JSON.stringify(playbook, null, 2));
|
|
145
|
+
|
|
146
|
+
crew.cleanupOldExecutions(60000);
|
|
147
|
+
crew.destroy();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
main().catch(console.error);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Do Not Generate
|
|
154
|
+
|
|
155
|
+
- Do NOT call `initACE()` manually -- it is called automatically when `addAgent()` / `addAgentsToCrew()` detects an `ace` config on the agent.
|
|
156
|
+
- Do NOT set `compileOnStart: true` without providing `examples` and a `metric` -- offline compilation requires both.
|
|
157
|
+
- Do NOT mutate the playbook object directly -- use `applyOnlineUpdate()` or `applyPlaybook()`.
|
|
158
|
+
- Do NOT forget `autoPersist: true` if you want playbook changes saved to disk automatically.
|
|
159
|
+
- Do NOT use `strategy: "weighted"` expecting differentiated weights -- it currently behaves the same as `"all"`.
|
|
160
|
+
|
|
161
|
+
## References
|
|
162
|
+
|
|
163
|
+
- [ace-customer-support.ts](https://github.com/amitdeshmukh/ax-crew/blob/main/examples/ace-customer-support.ts)
|
|
164
|
+
- [src/agents/ace.ts](https://github.com/amitdeshmukh/ax-crew/blob/main/src/agents/ace.ts)
|
|
165
|
+
- [AxACE upstream docs](https://axllm.dev/ace/)
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ax-crew-agent-config
|
|
3
|
+
version: __VERSION__
|
|
4
|
+
description: "AgentConfig - agent configuration: provider, signature, model, temperature, definition, prompt, executionMode, axAgentOptions, providerArgs"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# AgentConfig
|
|
8
|
+
|
|
9
|
+
Every agent in a crew is defined by an `AgentConfig` object inside `AxCrewConfig.crew[]`.
|
|
10
|
+
|
|
11
|
+
## All Fields
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
interface AgentConfig {
|
|
15
|
+
// Required
|
|
16
|
+
name: string; // Unique agent name
|
|
17
|
+
description: string; // Short description (used as default system prompt)
|
|
18
|
+
signature: string | AxSignature; // DSPy-style signature, e.g. "query:string -> answer:string"
|
|
19
|
+
provider: Provider; // "openai" | "anthropic" | "google-gemini" | "azure-openai" | ...
|
|
20
|
+
ai: AxModelConfig & { // Model configuration
|
|
21
|
+
model: string; // model name (required)
|
|
22
|
+
temperature?: number; // sampling temperature
|
|
23
|
+
maxTokens?: number; // max output tokens
|
|
24
|
+
stream?: boolean; // enable streaming at AI level
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Optional
|
|
28
|
+
providerKeyName?: string; // Env var name for API key (e.g. "OPENAI_API_KEY")
|
|
29
|
+
apiURL?: string; // Custom API endpoint (e.g. ollama on localhost)
|
|
30
|
+
providerArgs?: Record<string, unknown>; // Provider-specific args forwarded to Ax factory
|
|
31
|
+
definition?: string; // Detailed system prompt (must be >= 100 chars per Ax)
|
|
32
|
+
prompt?: string; // Alias for definition (used if definition is omitted)
|
|
33
|
+
debug?: boolean; // Enable debug logging
|
|
34
|
+
options?: Partial<AxProgramForwardOptions<any>> & Record<string, any>; // Forward options + provider-specific keys
|
|
35
|
+
functions?: string[]; // Function names from the registry
|
|
36
|
+
agents?: string[]; // Sub-agent names (must be added to crew first)
|
|
37
|
+
examples?: Array<Record<string, any>>; // DSPy few-shot examples
|
|
38
|
+
mcpServers?: Record<string, MCPTransportConfig>; // MCP server configs
|
|
39
|
+
executionMode?: "axagent" | "axgen"; // Execution engine (default: "axgen")
|
|
40
|
+
axAgentOptions?: AxCrewAxAgentOptions; // AxAgent-specific options (only for executionMode: "axagent")
|
|
41
|
+
ace?: ACEConfig; // Optional AxACE optimization config
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Canonical Pattern
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { AxCrew } from '@amitdeshmukh/ax-crew';
|
|
49
|
+
import type { AxCrewConfig } from '@amitdeshmukh/ax-crew';
|
|
50
|
+
|
|
51
|
+
const config: AxCrewConfig = {
|
|
52
|
+
crew: [
|
|
53
|
+
{
|
|
54
|
+
name: "analyzer",
|
|
55
|
+
description: "Analyzes user queries and provides structured responses",
|
|
56
|
+
signature: "userQuery:string -> analysis:string, confidence:number",
|
|
57
|
+
provider: "anthropic",
|
|
58
|
+
providerKeyName: "ANTHROPIC_API_KEY",
|
|
59
|
+
ai: {
|
|
60
|
+
model: "claude-sonnet-4-20250514",
|
|
61
|
+
temperature: 0.5,
|
|
62
|
+
maxTokens: 2000,
|
|
63
|
+
},
|
|
64
|
+
options: { debug: true, stream: false },
|
|
65
|
+
functions: ["CurrentDateTime"],
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
async function main() {
|
|
71
|
+
const crew = new AxCrew(config);
|
|
72
|
+
await crew.addAllAgents();
|
|
73
|
+
const analyzer = crew.agents?.get("analyzer");
|
|
74
|
+
const result = await analyzer?.forward({ userQuery: "What is quantum computing?" });
|
|
75
|
+
console.log(result?.analysis, result?.confidence);
|
|
76
|
+
crew.destroy();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
main().catch(console.error);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Provider Key Pattern
|
|
83
|
+
|
|
84
|
+
The `providerKeyName` field specifies which environment variable holds the API key. The key is read from `process.env` at agent creation time.
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
{
|
|
88
|
+
provider: "openai",
|
|
89
|
+
providerKeyName: "OPENAI_API_KEY", // reads process.env.OPENAI_API_KEY
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Azure OpenAI Example
|
|
94
|
+
|
|
95
|
+
Use `providerArgs` for provider-specific configuration:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { AxCrew } from '@amitdeshmukh/ax-crew';
|
|
99
|
+
import type { AxCrewConfig } from '@amitdeshmukh/ax-crew';
|
|
100
|
+
|
|
101
|
+
const config: AxCrewConfig = {
|
|
102
|
+
crew: [
|
|
103
|
+
{
|
|
104
|
+
name: "TestAgent",
|
|
105
|
+
description: "Test Agent for Azure OpenAI",
|
|
106
|
+
provider: "azure-openai",
|
|
107
|
+
providerKeyName: "AZURE_OPENAI_API_KEY",
|
|
108
|
+
signature: "userQuery:string -> answer:string",
|
|
109
|
+
ai: {
|
|
110
|
+
model: "gpt-5-mini",
|
|
111
|
+
temperature: 0,
|
|
112
|
+
stream: false
|
|
113
|
+
},
|
|
114
|
+
providerArgs: {
|
|
115
|
+
resourceName: "your-resource-name",
|
|
116
|
+
deploymentName: "your-deployment-name",
|
|
117
|
+
version: "2025-01-01-preview"
|
|
118
|
+
},
|
|
119
|
+
options: { debug: true, stream: false }
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
async function main() {
|
|
125
|
+
const crew = new AxCrew(config);
|
|
126
|
+
await crew.addAllAgents();
|
|
127
|
+
const agent = crew.agents?.get("TestAgent");
|
|
128
|
+
const response = await agent?.forward({ userQuery: "What is the capital of France?" });
|
|
129
|
+
console.log(response?.answer);
|
|
130
|
+
crew.destroy();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
main().catch(console.error);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Execution Mode
|
|
137
|
+
|
|
138
|
+
| Mode | Engine | When to use |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `"axgen"` (default) | `AxGen` | Standard prompt-response with tool calling |
|
|
141
|
+
| `"axagent"` | `AxAgent` | Full agent capabilities: RLM, context fields, actor/responder split |
|
|
142
|
+
|
|
143
|
+
When `executionMode: "axagent"`, use `axAgentOptions` for agent-specific settings:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
{
|
|
147
|
+
executionMode: "axagent",
|
|
148
|
+
axAgentOptions: {
|
|
149
|
+
contextFields: ["conversationHistory"],
|
|
150
|
+
// agents: { ... }, // Agent graph config
|
|
151
|
+
// functions: { ... }, // Function graph config
|
|
152
|
+
// actorOptions: { description: "..." },
|
|
153
|
+
// responderOptions: { description: "..." },
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Signature Format
|
|
159
|
+
|
|
160
|
+
DSPy-style string signatures with optional field descriptions:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
"input1:type, input2:type -> output1:type, output2:type"
|
|
164
|
+
"topic:string \"The topic\" -> article:string \"The written article\""
|
|
165
|
+
"query:string -> results:string[]"
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Supported types: `string`, `number`, `boolean`, `string[]`, `number[]`, etc.
|
|
169
|
+
|
|
170
|
+
## Do Not Generate
|
|
171
|
+
|
|
172
|
+
- Do NOT omit `name`, `description`, `signature`, `provider`, or `ai.model` -- all are required.
|
|
173
|
+
- Do NOT set `definition` to less than 100 characters if you provide it (Ax enforces this minimum).
|
|
174
|
+
- Do NOT confuse `options.stream` (forward option) with `ai.stream` (AI-level streaming config).
|
|
175
|
+
- Do NOT use `providerArgs` for API keys; use `providerKeyName` instead.
|
|
176
|
+
- Do NOT list sub-agents in `agents` that haven't been added to the crew before the parent agent.
|
|
177
|
+
|
|
178
|
+
## References
|
|
179
|
+
|
|
180
|
+
- [basic-researcher-writer.ts](https://github.com/amitdeshmukh/ax-crew/blob/main/examples/basic-researcher-writer.ts)
|
|
181
|
+
- [providerArgs.ts](https://github.com/amitdeshmukh/ax-crew/blob/main/examples/providerArgs.ts)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ax-crew-code-execution
|
|
3
|
+
description: AxCrew code execution with AxJSRuntime for sandboxed JavaScript execution. Covers AxJSRuntime setup, permissions, executionMode axagent, RLM mode, and runtime configuration for autonomous code generation and execution.
|
|
4
|
+
version: "__VERSION__"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# AxCrew Code Execution
|
|
8
|
+
|
|
9
|
+
AxJSRuntime from `@ax-llm/ax` provides sandboxed JavaScript execution for agents in RLM (Reasoning Language Model) mode. The agent generates and runs code autonomously to solve tasks.
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { AxJSRuntime, AxJSRuntimePermission } from '@ax-llm/ax';
|
|
15
|
+
import { AxCrew } from 'ax-crew';
|
|
16
|
+
import type { AxCrewConfig } from 'ax-crew';
|
|
17
|
+
|
|
18
|
+
const runtime = new AxJSRuntime({
|
|
19
|
+
permissions: [AxJSRuntimePermission.TIMING],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const config: AxCrewConfig = {
|
|
23
|
+
crew: [
|
|
24
|
+
{
|
|
25
|
+
name: "Analyzer",
|
|
26
|
+
description: "Analyzes data with code execution capabilities.",
|
|
27
|
+
executionMode: "axagent", // REQUIRED for runtime
|
|
28
|
+
signature:
|
|
29
|
+
'context:string, query:string -> answer:string, keyFindings:string[] "Analyzes context and returns findings"',
|
|
30
|
+
provider: "google-gemini",
|
|
31
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
32
|
+
ai: { model: "gemini-2.5-flash", temperature: 0 },
|
|
33
|
+
axAgentOptions: {
|
|
34
|
+
contextFields: ["context"], // fields managed as RLM context
|
|
35
|
+
runtime, // AxJSRuntime instance
|
|
36
|
+
maxTurns: 20,
|
|
37
|
+
maxSubAgentCalls: 40,
|
|
38
|
+
mode: "simple",
|
|
39
|
+
contextManagement: {
|
|
40
|
+
errorPruning: true,
|
|
41
|
+
hindsightEvaluation: true,
|
|
42
|
+
pruneRank: 2,
|
|
43
|
+
tombstoning: {
|
|
44
|
+
model: "gemini-2.5-flash",
|
|
45
|
+
modelConfig: { maxTokens: 60 },
|
|
46
|
+
},
|
|
47
|
+
stateInspection: { contextThreshold: 3000 },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
async function main() {
|
|
55
|
+
const crew = new AxCrew(config);
|
|
56
|
+
try {
|
|
57
|
+
await crew.addAllAgents();
|
|
58
|
+
|
|
59
|
+
const analyzer = crew.agents?.get("Analyzer");
|
|
60
|
+
if (!analyzer) throw new Error("Failed to initialize Analyzer");
|
|
61
|
+
|
|
62
|
+
const result = await analyzer.forward({
|
|
63
|
+
context: "Region,Month,Revenue\nNorth,Jan,48000\nNorth,Feb,54000\nSouth,Jan,39200",
|
|
64
|
+
query: "Which region has the highest total revenue?",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log(result.answer);
|
|
68
|
+
console.log(result.keyFindings);
|
|
69
|
+
} finally {
|
|
70
|
+
crew.destroy();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main().catch(console.error);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Key Requirements
|
|
78
|
+
|
|
79
|
+
1. **`executionMode: "axagent"`** -- required for runtime support. The default `"axgen"` mode does not support code execution.
|
|
80
|
+
2. **`axAgentOptions.runtime`** -- pass an `AxJSRuntime` instance.
|
|
81
|
+
3. **`axAgentOptions.contextFields`** -- array of input field names managed as RLM context (can be empty `[]`).
|
|
82
|
+
|
|
83
|
+
## Shared Runtime Across Agents
|
|
84
|
+
|
|
85
|
+
A single `AxJSRuntime` instance can be shared across multiple agents:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const runtime = new AxJSRuntime({
|
|
89
|
+
permissions: [AxJSRuntimePermission.TIMING],
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const config: AxCrewConfig = {
|
|
93
|
+
crew: [
|
|
94
|
+
{
|
|
95
|
+
name: "PolicyLookup",
|
|
96
|
+
description: "Looks up policies",
|
|
97
|
+
executionMode: "axagent",
|
|
98
|
+
signature: "question:string -> answer:string",
|
|
99
|
+
provider: "google-gemini",
|
|
100
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
101
|
+
ai: { model: "gemini-2.5-flash", temperature: 0 },
|
|
102
|
+
axAgentOptions: { contextFields: [], runtime },
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "BillingHelper",
|
|
106
|
+
description: "Handles billing queries",
|
|
107
|
+
executionMode: "axagent",
|
|
108
|
+
signature: "question:string -> answer:string",
|
|
109
|
+
provider: "google-gemini",
|
|
110
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
111
|
+
ai: { model: "gemini-2.5-flash", temperature: 0 },
|
|
112
|
+
axAgentOptions: { contextFields: [], runtime },
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## AxJSRuntimePermission
|
|
119
|
+
|
|
120
|
+
Controls what the sandboxed code can access:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { AxJSRuntimePermission } from '@ax-llm/ax';
|
|
124
|
+
|
|
125
|
+
const runtime = new AxJSRuntime({
|
|
126
|
+
permissions: [
|
|
127
|
+
AxJSRuntimePermission.TIMING, // access to Date, performance.now()
|
|
128
|
+
],
|
|
129
|
+
});
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Minimal RLM Agent (No Context Management)
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
const config: AxCrewConfig = {
|
|
136
|
+
crew: [
|
|
137
|
+
{
|
|
138
|
+
name: "Coder",
|
|
139
|
+
description: "Executes JavaScript code to solve tasks",
|
|
140
|
+
executionMode: "axagent",
|
|
141
|
+
signature: "task:string -> result:string",
|
|
142
|
+
provider: "openai",
|
|
143
|
+
ai: { model: "gpt-4o", temperature: 0 },
|
|
144
|
+
axAgentOptions: {
|
|
145
|
+
contextFields: [],
|
|
146
|
+
runtime: new AxJSRuntime({
|
|
147
|
+
permissions: [AxJSRuntimePermission.TIMING],
|
|
148
|
+
}),
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
};
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Do Not Generate
|
|
156
|
+
|
|
157
|
+
- Do NOT use `executionMode: "axgen"` with `runtime` -- code execution requires `"axagent"` mode
|
|
158
|
+
- Do NOT use Google's `codeExecution` tool option -- use `AxJSRuntime` instead for sandboxed execution
|
|
159
|
+
- Do NOT omit `contextFields` in `axAgentOptions` when using `executionMode: "axagent"` -- it is mandatory (use `[]` if no context fields)
|
|
160
|
+
- Do NOT create a new `AxJSRuntime` per request -- reuse a single instance across agents and calls
|
|
161
|
+
- Do NOT confuse `axAgentOptions.runtime` with Node.js runtime -- it is a sandboxed JS execution environment
|
|
162
|
+
|
|
163
|
+
## References
|
|
164
|
+
|
|
165
|
+
- [rlm-long-task.ts](../examples/rlm-long-task.ts) -- full RLM agent with context management
|
|
166
|
+
- [rlm-shared-fields.ts](../examples/rlm-shared-fields.ts) -- shared runtime across sub-agents
|