@amitdeshmukh/ax-crew 8.7.1 → 9.0.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/CHANGELOG.md +49 -0
- package/README.md +10 -10
- package/axcrew.webp +0 -0
- package/dist/agents/agentConfig.d.ts +2 -0
- package/dist/agents/agentConfig.js +11 -4
- package/dist/agents/crew.d.ts +59 -0
- package/dist/agents/crew.js +355 -0
- package/dist/agents/deferredTools.d.ts +49 -0
- package/dist/agents/deferredTools.js +237 -0
- package/dist/agents/index.d.ts +4 -266
- package/dist/agents/index.js +3 -1014
- package/dist/agents/lazyAgent.d.ts +33 -0
- package/dist/agents/lazyAgent.js +78 -0
- package/dist/agents/statefulAgent.d.ts +93 -0
- package/dist/agents/statefulAgent.js +473 -0
- package/dist/index.d.ts +2 -2
- package/dist/types.d.ts +18 -1
- package/examples/graphjin-database-agent.ts +68 -57
- package/examples/write-post-and-publish-to-wordpress.ts +1 -1
- package/package.json +1 -1
- package/scripts/install-skills.mjs +62 -30
- package/scripts/uninstall-skills.mjs +19 -13
- package/src/agents/agentConfig.ts +14 -8
- package/src/agents/crew.ts +443 -0
- package/src/agents/deferredTools.ts +275 -0
- package/src/agents/index.ts +4 -1281
- package/src/agents/lazyAgent.ts +95 -0
- package/src/agents/statefulAgent.ts +659 -0
- package/src/index.ts +7 -4
- package/src/skills/{ax-crew-ace.md → axcrew-ace.md} +9 -4
- package/src/skills/{ax-crew-agent-config.md → axcrew-agent-config.md} +7 -4
- package/src/skills/{ax-crew-code-execution.md → axcrew-code-execution.md} +7 -4
- package/src/skills/{ax-crew-execution-modes.md → axcrew-execution-modes.md} +10 -6
- package/src/skills/{ax-crew-few-shot.md → axcrew-few-shot.md} +8 -4
- package/src/skills/{ax-crew-functions.md → axcrew-functions.md} +10 -7
- package/src/skills/{ax-crew-mcp.md → axcrew-mcp.md} +50 -6
- package/src/skills/{ax-crew-metrics.md → axcrew-metrics.md} +9 -6
- package/src/skills/{ax-crew-patterns.md → axcrew-patterns.md} +56 -8
- package/src/skills/{ax-crew-providers.md → axcrew-providers.md} +12 -7
- package/src/skills/{ax-crew-signatures.md → axcrew-signatures.md} +5 -5
- package/src/skills/{ax-crew-state.md → axcrew-state.md} +23 -20
- package/src/skills/{ax-crew-streaming.md → axcrew-streaming.md} +7 -4
- package/src/skills/{ax-crew-sub-agents.md → axcrew-sub-agents.md} +8 -4
- package/src/skills/{ax-crew-telemetry.md → axcrew-telemetry.md} +6 -3
- package/src/skills/{ax-crew.md → axcrew.md} +22 -6
- package/src/types.ts +19 -0
- package/.claude/settings.local.json +0 -13
- package/.claude/skills/ax-crew/SKILL.md +0 -466
- package/axcrew.png +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
|
-
name:
|
|
3
|
-
version:
|
|
2
|
+
name: axcrew
|
|
3
|
+
version: 8.7.3
|
|
4
4
|
description: "AxCrew - multi-agent orchestration: crew, agents, addAgent, addAllAgents, addAgentsToCrew, forward, streaming, sub-agents"
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -98,17 +98,33 @@ new AxCrew(crewConfig: AxCrewConfig, functionsRegistry?: FunctionRegistryType, o
|
|
|
98
98
|
| `crew.agents?.get("A")` | Retrieve a `StatefulAxAgent` |
|
|
99
99
|
| `await agent.forward({ key: "value" })` | Run the agent |
|
|
100
100
|
| `agent.streamingForward({ key: "value" })` | Stream output chunks |
|
|
101
|
-
| `crew.
|
|
101
|
+
| `crew.crewState` | Shared `StateInstance` across all agents |
|
|
102
102
|
| `crew.resetCosts()` | Reset usage/metrics for all agents |
|
|
103
103
|
| `crew.getCrewMetrics()` | Aggregate metrics snapshot |
|
|
104
104
|
| `crew.destroy()` | Clean up agents, state, execution history |
|
|
105
105
|
|
|
106
|
+
## Deferred Tool Loading
|
|
107
|
+
|
|
108
|
+
Agents with many MCP tools can use `deferredTools` in their agent config to avoid overwhelming the LLM context. When the total tool count exceeds a threshold (default 20), only core tools plus a `search_tools` meta-tool are visible to the agent. The LLM discovers additional tools by calling `search_tools`, which uses local multi-signal search (no API calls). Discovered tools persist across `forward()` calls, and related tools are proactively activated alongside the requested tool.
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
{
|
|
112
|
+
name: "BigToolAgent",
|
|
113
|
+
// ...
|
|
114
|
+
mcpServers: { /* ... */ },
|
|
115
|
+
deferredTools: { maxTools: 20 }, // optional, 20 is the default threshold
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
106
119
|
## Related Skills
|
|
107
120
|
|
|
108
121
|
- `ax-crew-agent-config` -- AgentConfig fields, provider setup, executionMode
|
|
109
122
|
- `ax-crew-functions` -- Function registry, custom tools, class-based functions
|
|
110
123
|
- `ax-crew-state` -- Shared state API, accessing state from functions
|
|
111
124
|
|
|
125
|
+
## Supporting files
|
|
126
|
+
- See [examples/basic-researcher-writer.ts](examples/basic-researcher-writer.ts) for a complete runnable example.
|
|
127
|
+
|
|
112
128
|
## Do Not Generate
|
|
113
129
|
|
|
114
130
|
- Do NOT instantiate `AxAgent` or `AxGen` directly; use `AxCrew` which wraps them as `StatefulAxAgent`.
|
|
@@ -119,6 +135,6 @@ new AxCrew(crewConfig: AxCrewConfig, functionsRegistry?: FunctionRegistryType, o
|
|
|
119
135
|
|
|
120
136
|
## References
|
|
121
137
|
|
|
122
|
-
- [basic-researcher-writer.ts](
|
|
123
|
-
- [write-post-and-publish-to-wordpress.ts](
|
|
124
|
-
- [providerArgs.ts](
|
|
138
|
+
- [basic-researcher-writer.ts](examples/basic-researcher-writer.ts)
|
|
139
|
+
- [write-post-and-publish-to-wordpress.ts](examples/write-post-and-publish-to-wordpress.ts)
|
|
140
|
+
- [providerArgs.ts](examples/providerArgs.ts)
|
package/src/types.ts
CHANGED
|
@@ -202,6 +202,22 @@ interface ACEConfig {
|
|
|
202
202
|
compileOnStart?: boolean;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Configuration for deferred tool loading.
|
|
207
|
+
* When an agent has many tools, only core tools are visible by default.
|
|
208
|
+
* A search_tools meta-function lets the LLM discover and activate deferred tools on demand.
|
|
209
|
+
*/
|
|
210
|
+
interface DeferredToolsConfig {
|
|
211
|
+
/** Enable deferred tool loading. Default: auto (true when tool count > threshold) */
|
|
212
|
+
enabled?: boolean;
|
|
213
|
+
/** Tool count threshold to activate deferred mode. Default: 20 */
|
|
214
|
+
threshold?: number;
|
|
215
|
+
/** Max tools returned per search. Default: 10 */
|
|
216
|
+
maxSearchResults?: number;
|
|
217
|
+
/** Tool names to always keep active (bypasses deferral) */
|
|
218
|
+
coreTools?: string[];
|
|
219
|
+
}
|
|
220
|
+
|
|
205
221
|
/**
|
|
206
222
|
* The configuration for an agent.
|
|
207
223
|
*
|
|
@@ -261,6 +277,8 @@ interface AgentConfig {
|
|
|
261
277
|
mcpServers?: Record<string, MCPTransportConfig>;
|
|
262
278
|
/** Optional AxACE configuration to enable optimization for this agent */
|
|
263
279
|
ace?: ACEConfig;
|
|
280
|
+
/** Deferred tool loading — reduces token usage when an agent has many tools */
|
|
281
|
+
deferredTools?: DeferredToolsConfig;
|
|
264
282
|
}
|
|
265
283
|
|
|
266
284
|
/**
|
|
@@ -335,6 +353,7 @@ export {
|
|
|
335
353
|
type ModelInfo,
|
|
336
354
|
type UsageCost,
|
|
337
355
|
type AggregatedCosts,
|
|
356
|
+
type DeferredToolsConfig,
|
|
338
357
|
// ACE exports
|
|
339
358
|
type ACEConfig,
|
|
340
359
|
type ACEMetricConfig,
|
|
@@ -1,466 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: ax-crew
|
|
3
|
-
description: Guide for building multi-agent AI systems with ax-crew. Use when creating agent crews, configuring agents, using MCP servers, shared state, sub-agents, streaming, ACE learning, function registries, metrics/cost tracking, telemetry, or agent workflows with @amitdeshmukh/ax-crew.
|
|
4
|
-
argument-hint: [topic]
|
|
5
|
-
allowed-tools: Read, Grep, Glob
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# ax-crew Library Guide
|
|
9
|
-
|
|
10
|
-
ax-crew (`@amitdeshmukh/ax-crew`) is a TypeScript framework for building teams of AI agents with shared state, tools, streaming, MCP integration, and built-in metrics/cost tracking. It is powered by [AxLLM](https://axllm.dev) (`@ax-llm/ax`).
|
|
11
|
-
|
|
12
|
-
**Package:** `@amitdeshmukh/ax-crew` (v8.5.0+)
|
|
13
|
-
**Peer deps:** `@ax-llm/ax`, `@ax-llm/ax-tools`, `@opentelemetry/api` (optional)
|
|
14
|
-
**Node.js:** >= 21
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
npm install @amitdeshmukh/ax-crew @ax-llm/ax @ax-llm/ax-tools
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Core Concepts
|
|
23
|
-
|
|
24
|
-
- **Config-first:** Define agents in a JSON/TypeScript config object, instantiate on demand.
|
|
25
|
-
- **Shared state:** Simple key/value store all agents can read/write via `crew.state`.
|
|
26
|
-
- **Sub-agents:** Agents can delegate to other agents listed in their `agents` field.
|
|
27
|
-
- **Functions (tools):** Register callable tools via a function registry, reference by name.
|
|
28
|
-
- **Execution modes:** `axgen` (default, structured generation) or `axagent` (agentic loop with RLM).
|
|
29
|
-
- **MCP:** Connect agents to external MCP servers (STDIO, HTTP SSE, Streamable HTTP).
|
|
30
|
-
- **ACE:** Agentic Context Engineering - agents learn from human feedback at runtime.
|
|
31
|
-
- **Metrics:** Per-agent and crew-level token usage, cost estimation, and request stats.
|
|
32
|
-
|
|
33
|
-
## Quick Start
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
import { AxCrew, AxCrewFunctions } from '@amitdeshmukh/ax-crew';
|
|
37
|
-
import type { AxCrewConfig } from '@amitdeshmukh/ax-crew';
|
|
38
|
-
|
|
39
|
-
const config: AxCrewConfig = {
|
|
40
|
-
crew: [
|
|
41
|
-
{
|
|
42
|
-
name: "Researcher",
|
|
43
|
-
description: "Finds information on a topic",
|
|
44
|
-
signature: 'query:string "research query" -> research:string "research findings"',
|
|
45
|
-
provider: "google-gemini",
|
|
46
|
-
providerKeyName: "GEMINI_API_KEY",
|
|
47
|
-
ai: { model: "gemini-2.5-flash", temperature: 0 },
|
|
48
|
-
functions: ["CurrentDateTime"]
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
name: "Writer",
|
|
52
|
-
description: "Writes articles based on research",
|
|
53
|
-
signature: 'topic:string -> article:string',
|
|
54
|
-
provider: "google-gemini",
|
|
55
|
-
providerKeyName: "GEMINI_API_KEY",
|
|
56
|
-
ai: { model: "gemini-2.5-flash", temperature: 0.7 },
|
|
57
|
-
agents: ["Researcher"] // Writer can delegate to Researcher
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const crew = new AxCrew(config, AxCrewFunctions);
|
|
63
|
-
await crew.addAllAgents();
|
|
64
|
-
|
|
65
|
-
const writer = crew.agents?.get("Writer");
|
|
66
|
-
const { article } = await writer.forward({ topic: "Quantum Computing" });
|
|
67
|
-
console.log(article);
|
|
68
|
-
|
|
69
|
-
// Metrics
|
|
70
|
-
console.log(crew.getCrewMetrics());
|
|
71
|
-
|
|
72
|
-
// Cleanup
|
|
73
|
-
crew.destroy();
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## Agent Configuration Reference
|
|
77
|
-
|
|
78
|
-
Each agent in the `crew` array accepts these fields:
|
|
79
|
-
|
|
80
|
-
| Field | Type | Required | Description |
|
|
81
|
-
|-------|------|----------|-------------|
|
|
82
|
-
| `name` | string | Yes | Unique agent name |
|
|
83
|
-
| `description` | string | Yes | What the agent does |
|
|
84
|
-
| `signature` | string | Yes | DSPy-format I/O schema: `input:type "desc" -> output:type "desc"` |
|
|
85
|
-
| `provider` | string | Yes | LLM provider: `google-gemini`, `anthropic`, `openai`, `azure-openai`, etc. |
|
|
86
|
-
| `providerKeyName` | string | No | Env var name for API key (e.g. `"GEMINI_API_KEY"`) |
|
|
87
|
-
| `ai` | object | Yes | `{ model: string, temperature?: number, maxTokens?: number, stream?: boolean }` |
|
|
88
|
-
| `executionMode` | string | No | `"axgen"` (default) or `"axagent"` |
|
|
89
|
-
| `definition` / `prompt` | string | No | System prompt (>= 100 chars). `definition` takes precedence. |
|
|
90
|
-
| `functions` | string[] | No | Tool names from the function registry |
|
|
91
|
-
| `agents` | string[] | No | Sub-agent names this agent can delegate to |
|
|
92
|
-
| `examples` | object[] | No | Few-shot examples matching the signature |
|
|
93
|
-
| `mcpServers` | object | No | MCP server configurations |
|
|
94
|
-
| `ace` | object | No | ACE learning configuration |
|
|
95
|
-
| `debug` | boolean | No | Enable debug logging |
|
|
96
|
-
| `apiURL` | string | No | Custom API endpoint (e.g. for Ollama) |
|
|
97
|
-
| `providerArgs` | object | No | Provider-specific args (e.g. Azure deployment details) |
|
|
98
|
-
| `options` | object | No | Forward options: `debug`, `stream`, `codeExecution`, `thinkingTokenBudget`, etc. |
|
|
99
|
-
| `axAgentOptions` | object | No | RLM options (only for `axagent` mode): `runtime`, `contextFields`, `mode`, `maxTurns` |
|
|
100
|
-
|
|
101
|
-
### Signature Format (DSPy)
|
|
102
|
-
|
|
103
|
-
```
|
|
104
|
-
"inputField:type \"description\" -> outputField:type \"description\""
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Supported types: `string`, `number`, `boolean`, `json`, `string[]`, etc.
|
|
108
|
-
|
|
109
|
-
Examples:
|
|
110
|
-
```
|
|
111
|
-
"query:string -> answer:string"
|
|
112
|
-
"task:string \"a task\" -> plan:string \"step-by-step plan\""
|
|
113
|
-
"question:string, context:string? -> answer:string, confidence:number"
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
## Adding Agents to the Crew
|
|
117
|
-
|
|
118
|
-
Three methods, from simplest to most controlled:
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
// 1. All agents (auto-handles dependencies)
|
|
122
|
-
await crew.addAllAgents();
|
|
123
|
-
|
|
124
|
-
// 2. Subset with auto dependency resolution
|
|
125
|
-
await crew.addAgentsToCrew(["Writer", "Researcher"]);
|
|
126
|
-
|
|
127
|
-
// 3. Manual (you handle dependency order)
|
|
128
|
-
await crew.addAgent("Researcher");
|
|
129
|
-
await crew.addAgent("Writer");
|
|
130
|
-
|
|
131
|
-
// 4. Lazy initialization (defers expensive init until delegation)
|
|
132
|
-
await crew.addLazyAgent("ExpensiveSubAgent");
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
`addLazyAgent()` builds the agent schema immediately (so parent agents can see it as a tool) but defers expensive initialization (MCP server startup, AI client creation) until the agent is actually called.
|
|
136
|
-
|
|
137
|
-
## Function Registry (Tools)
|
|
138
|
-
|
|
139
|
-
Two ways to define tools:
|
|
140
|
-
|
|
141
|
-
### Direct AxFunction objects
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
import type { AxFunction } from '@ax-llm/ax';
|
|
145
|
-
|
|
146
|
-
const myFunctions = {
|
|
147
|
-
SearchWeb: {
|
|
148
|
-
name: 'SearchWeb',
|
|
149
|
-
description: 'Searches the web',
|
|
150
|
-
parameters: {
|
|
151
|
-
type: 'object',
|
|
152
|
-
properties: { query: { type: 'string', description: 'search query' } }
|
|
153
|
-
},
|
|
154
|
-
func: async ({ query }) => { /* ... */ return results; }
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### Class-based (receives shared state)
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
class DatabaseQuery {
|
|
163
|
-
constructor(private state: Record<string, any>) {}
|
|
164
|
-
toFunction(): AxFunction {
|
|
165
|
-
return {
|
|
166
|
-
name: 'DatabaseQuery',
|
|
167
|
-
description: 'Queries the database',
|
|
168
|
-
parameters: {
|
|
169
|
-
type: 'object',
|
|
170
|
-
properties: { sql: { type: 'string', description: 'SQL query' } }
|
|
171
|
-
},
|
|
172
|
-
func: async ({ sql }) => {
|
|
173
|
-
const userId = this.state.userId; // Access shared state
|
|
174
|
-
return await db.query(sql, userId);
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const crew = new AxCrew(config, { DatabaseQuery, ...AxCrewFunctions });
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
Built-in functions: `CurrentDateTime`, `DaysBetweenDates` (via `AxCrewFunctions`).
|
|
184
|
-
|
|
185
|
-
## Shared State
|
|
186
|
-
|
|
187
|
-
```typescript
|
|
188
|
-
crew.state.set('userId', '123');
|
|
189
|
-
crew.state.get('userId'); // '123'
|
|
190
|
-
crew.state.getAll(); // { userId: '123' }
|
|
191
|
-
crew.state.reset(); // Clear all
|
|
192
|
-
|
|
193
|
-
// Agents share the same state
|
|
194
|
-
const agent = crew.agents?.get("MyAgent");
|
|
195
|
-
agent.state.set('key', 'value'); // Visible to all agents
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
## Streaming
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
// Method 1: streamingForward (async iterator)
|
|
202
|
-
const stream = await agent.streamingForward({ topic: "AI" });
|
|
203
|
-
for await (const chunk of stream) {
|
|
204
|
-
if (chunk.delta && 'answer' in chunk.delta) {
|
|
205
|
-
process.stdout.write(chunk.delta.answer);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Method 2: forward with onStream callback
|
|
210
|
-
await agent.forward(
|
|
211
|
-
{ topic: "AI" },
|
|
212
|
-
{ onStream: (chunk) => process.stdout.write(chunk) }
|
|
213
|
-
);
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
## MCP Server Integration
|
|
217
|
-
|
|
218
|
-
Three transport types, auto-detected by config shape:
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
mcpServers: {
|
|
222
|
-
// STDIO - local process
|
|
223
|
-
"filesystem": {
|
|
224
|
-
command: "npx",
|
|
225
|
-
args: ["-y", "@modelcontextprotocol/server-filesystem", "/path"],
|
|
226
|
-
env: { NODE_ENV: "production" }
|
|
227
|
-
},
|
|
228
|
-
// HTTP SSE - remote server
|
|
229
|
-
"api-server": {
|
|
230
|
-
sseUrl: "https://api.example.com/mcp/sse"
|
|
231
|
-
},
|
|
232
|
-
// Streamable HTTP - bidirectional
|
|
233
|
-
"stream-service": {
|
|
234
|
-
mcpEndpoint: "http://localhost:3002/stream",
|
|
235
|
-
options: { timeout: 30000 }
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### MCP Tool Filtering
|
|
241
|
-
|
|
242
|
-
Reduce token usage by exposing only needed tools:
|
|
243
|
-
|
|
244
|
-
```typescript
|
|
245
|
-
mcpServers: {
|
|
246
|
-
graphjin: {
|
|
247
|
-
mcpEndpoint: "http://localhost:8080/api/v1/mcp",
|
|
248
|
-
tools: ["list_workflows", "execute_workflow", "describe_table"] // Only these tools
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
## ACE (Agentic Context Engineering)
|
|
254
|
-
|
|
255
|
-
Enable agents to learn from human feedback at runtime:
|
|
256
|
-
|
|
257
|
-
```typescript
|
|
258
|
-
{
|
|
259
|
-
name: "SupportAgent",
|
|
260
|
-
// ... other config ...
|
|
261
|
-
ace: {
|
|
262
|
-
teacher: {
|
|
263
|
-
provider: "google-gemini",
|
|
264
|
-
providerKeyName: "GEMINI_API_KEY",
|
|
265
|
-
ai: { model: "gemini-flash-latest" }
|
|
266
|
-
},
|
|
267
|
-
options: { maxEpochs: 1, allowDynamicSections: true },
|
|
268
|
-
persistence: {
|
|
269
|
-
playbookPath: "playbooks/support.json",
|
|
270
|
-
autoPersist: true
|
|
271
|
-
},
|
|
272
|
-
metric: { primaryOutputField: "response" },
|
|
273
|
-
compileOnStart: false
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
### Applying Feedback
|
|
279
|
-
|
|
280
|
-
```typescript
|
|
281
|
-
const result = await agent.forward({ ticket: "..." });
|
|
282
|
-
|
|
283
|
-
// Teach the agent
|
|
284
|
-
await crew.applyTaskFeedback({
|
|
285
|
-
taskId: result._taskId,
|
|
286
|
-
feedback: "For loyal customers, extend return window to 60 days",
|
|
287
|
-
strategy: "all" // "all" | "primary" | "weighted"
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
// View learned rules
|
|
291
|
-
const playbook = agent.getPlaybook?.();
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
## Metrics & Cost Tracking
|
|
295
|
-
|
|
296
|
-
```typescript
|
|
297
|
-
// Per-agent metrics
|
|
298
|
-
const metrics = agent.getMetrics?.();
|
|
299
|
-
// { provider, model, requests: {...}, tokens: {...}, estimatedCostUSD, functions: {...} }
|
|
300
|
-
|
|
301
|
-
// Crew-level aggregated metrics
|
|
302
|
-
const crewMetrics = crew.getCrewMetrics();
|
|
303
|
-
|
|
304
|
-
// Reset
|
|
305
|
-
crew.resetCosts();
|
|
306
|
-
crew.resetMetrics();
|
|
307
|
-
```
|
|
308
|
-
|
|
309
|
-
## OpenTelemetry Integration
|
|
310
|
-
|
|
311
|
-
```typescript
|
|
312
|
-
import { trace, metrics } from '@opentelemetry/api';
|
|
313
|
-
|
|
314
|
-
const crew = new AxCrew(config, functions, undefined, {
|
|
315
|
-
telemetry: {
|
|
316
|
-
tracer: trace.getTracer('my-app'),
|
|
317
|
-
meter: metrics.getMeter('my-app')
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
## Execution Modes
|
|
323
|
-
|
|
324
|
-
### axgen (default)
|
|
325
|
-
Structured generation via AxGen. Sub-agents become callable tool functions. Best for deterministic, single-pass tasks.
|
|
326
|
-
|
|
327
|
-
### axagent
|
|
328
|
-
Agentic loop with RLM (Runtime Language Model) support. Best for multi-step reasoning.
|
|
329
|
-
|
|
330
|
-
```typescript
|
|
331
|
-
import { AxJSRuntime, AxJSRuntimePermission } from '@ax-llm/ax';
|
|
332
|
-
|
|
333
|
-
{
|
|
334
|
-
name: "DeepResearcher",
|
|
335
|
-
executionMode: "axagent",
|
|
336
|
-
signature: "query:string, context:string? -> answer:string",
|
|
337
|
-
// ... provider config ...
|
|
338
|
-
axAgentOptions: {
|
|
339
|
-
runtime: new AxJSRuntime({ permissions: [AxJSRuntimePermission.TIMING] }),
|
|
340
|
-
contextFields: ["context"],
|
|
341
|
-
mode: "simple",
|
|
342
|
-
maxTurns: 12
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
Both modes use the same `forward()` / `streamingForward()` API.
|
|
348
|
-
|
|
349
|
-
## Environment Setup
|
|
350
|
-
|
|
351
|
-
Set provider API keys as env vars. Each agent specifies which key via `providerKeyName`:
|
|
352
|
-
|
|
353
|
-
```bash
|
|
354
|
-
GEMINI_API_KEY=...
|
|
355
|
-
ANTHROPIC_API_KEY=...
|
|
356
|
-
OPENAI_API_KEY=...
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
AxCrew resolves keys via `process.env[providerKeyName]` (Node) or `globalThis[providerKeyName]` (browser).
|
|
360
|
-
|
|
361
|
-
## Cleanup
|
|
362
|
-
|
|
363
|
-
Always call `crew.destroy()` when done to clean up MCP servers and resources:
|
|
364
|
-
|
|
365
|
-
```typescript
|
|
366
|
-
try {
|
|
367
|
-
// ... use agents ...
|
|
368
|
-
} finally {
|
|
369
|
-
crew.destroy();
|
|
370
|
-
}
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
## Key Exports
|
|
374
|
-
|
|
375
|
-
```typescript
|
|
376
|
-
import {
|
|
377
|
-
AxCrew, // Main class
|
|
378
|
-
AxCrewFunctions, // Built-in function registry
|
|
379
|
-
MetricsRegistry, // Metrics helpers
|
|
380
|
-
} from '@amitdeshmukh/ax-crew';
|
|
381
|
-
|
|
382
|
-
import type {
|
|
383
|
-
AxCrewConfig, // Top-level config
|
|
384
|
-
AgentConfig, // Per-agent config
|
|
385
|
-
AxCrewOptions, // Constructor options (telemetry, debug)
|
|
386
|
-
StateInstance, // State API
|
|
387
|
-
FunctionRegistryType,// Function registry shape
|
|
388
|
-
ACEConfig, // ACE configuration
|
|
389
|
-
} from '@amitdeshmukh/ax-crew';
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
## Common Patterns
|
|
393
|
-
|
|
394
|
-
### Manager + Specialist Pattern
|
|
395
|
-
|
|
396
|
-
```typescript
|
|
397
|
-
const config: AxCrewConfig = {
|
|
398
|
-
crew: [
|
|
399
|
-
{
|
|
400
|
-
name: "SpecialistAgent",
|
|
401
|
-
description: "Handles domain-specific queries",
|
|
402
|
-
signature: 'query:string -> answer:string',
|
|
403
|
-
provider: "google-gemini",
|
|
404
|
-
providerKeyName: "GEMINI_API_KEY",
|
|
405
|
-
ai: { model: "gemini-2.5-pro", temperature: 0 },
|
|
406
|
-
mcpServers: { /* domain tools */ }
|
|
407
|
-
},
|
|
408
|
-
{
|
|
409
|
-
name: "ManagerAgent",
|
|
410
|
-
description: "Orchestrates specialists to answer questions",
|
|
411
|
-
prompt: "You orchestrate sub-agents to answer user questions. Delegate domain queries to specialists.",
|
|
412
|
-
signature: 'question:string -> answer:string',
|
|
413
|
-
provider: "google-gemini",
|
|
414
|
-
providerKeyName: "GEMINI_API_KEY",
|
|
415
|
-
ai: { model: "gemini-2.5-pro", temperature: 0 },
|
|
416
|
-
agents: ["SpecialistAgent"]
|
|
417
|
-
}
|
|
418
|
-
]
|
|
419
|
-
};
|
|
420
|
-
```
|
|
421
|
-
|
|
422
|
-
### Lazy Sub-Agent for Expensive Resources
|
|
423
|
-
|
|
424
|
-
```typescript
|
|
425
|
-
const crew = new AxCrew(config);
|
|
426
|
-
await crew.addLazyAgent("HeavyMCPAgent"); // Schema only, no MCP startup yet
|
|
427
|
-
await crew.addAgentsToCrew(["ManagerAgent"]); // Manager sees HeavyMCPAgent as a tool
|
|
428
|
-
// HeavyMCPAgent initializes only when Manager actually delegates to it
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
### Pipeline Pattern (Sequential Processing)
|
|
432
|
-
|
|
433
|
-
```typescript
|
|
434
|
-
const crew = new AxCrew(config);
|
|
435
|
-
await crew.addAllAgents();
|
|
436
|
-
|
|
437
|
-
const researcher = crew.agents?.get("Researcher");
|
|
438
|
-
const writer = crew.agents?.get("Writer");
|
|
439
|
-
|
|
440
|
-
const { research } = await researcher.forward({ query: "topic" });
|
|
441
|
-
crew.state.set("research", research);
|
|
442
|
-
const { article } = await writer.forward({ topic: "topic" });
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
## Examples
|
|
446
|
-
|
|
447
|
-
See the `examples/` directory for complete working examples:
|
|
448
|
-
|
|
449
|
-
- `basic-researcher-writer.ts` - Simple two-agent crew
|
|
450
|
-
- `mcp-agent.ts` - MCP server integration with sub-agents
|
|
451
|
-
- `streaming.ts` - Real-time token streaming
|
|
452
|
-
- `run-crew-workflow.ts` - Database workflows with MCP tool filtering
|
|
453
|
-
- `ace-customer-support.ts` - ACE learning from feedback
|
|
454
|
-
- `ace-flight-finder.ts` - Flight assistant with preference learning
|
|
455
|
-
- `rlm-long-task.ts` - RLM mode with context management
|
|
456
|
-
- `rlm-shared-fields.ts` - RLM with field propagation
|
|
457
|
-
- `telemetry-demo.ts` - OpenTelemetry with Jaeger
|
|
458
|
-
- `solve-math-problem.ts` - Code execution with sub-agents
|
|
459
|
-
|
|
460
|
-
## Troubleshooting
|
|
461
|
-
|
|
462
|
-
- **Missing API key:** Ensure `providerKeyName` matches an env var that is set before crew creation.
|
|
463
|
-
- **Circular dependencies:** AxCrew detects and reports circular `agents` references.
|
|
464
|
-
- **MCP server won't start:** Enable `debug: true` on the agent to see MCP init logs.
|
|
465
|
-
- **Sub-agent not visible:** Ensure the sub-agent is added to the crew before the parent agent, or use `addAllAgents()` / `addAgentsToCrew()` for automatic ordering.
|
|
466
|
-
- **definition too short:** Must be >= 100 characters. Use `prompt` as an alias.
|
package/axcrew.png
DELETED
|
Binary file
|