@amitdeshmukh/ax-crew 8.0.2 → 8.1.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 +2 -1
- package/CHANGELOG.md +24 -1
- package/README.md +106 -7
- package/dist/agents/agentConfig.d.ts +3 -1
- package/dist/agents/agentConfig.js +3 -0
- package/dist/agents/index.d.ts +27 -3
- package/dist/agents/index.js +222 -129
- package/dist/index.d.ts +2 -2
- package/dist/types.d.ts +19 -1
- package/examples/graphjin-database-agent.ts +15 -9
- package/examples/rlm-long-task.ts +126 -0
- package/examples/rlm-shared-fields.ts +181 -0
- package/package.json +3 -3
- package/src/agents/agentConfig.ts +8 -1
- package/src/agents/index.ts +317 -145
- package/src/index.ts +4 -2
- package/src/types.ts +21 -1
- package/tests/execution-mode-metrics.test.ts +231 -0
- package/examples/factory.ts +0 -174
- package/examples/google-gemini-test.ts +0 -291
- package/examples/graphjin-README.md +0 -167
- package/examples/planner.ts +0 -107
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
import { AxJSRuntime, AxJSRuntimePermission } from "@ax-llm/ax";
|
|
3
|
+
import { AxCrew } from "../dist/index.js";
|
|
4
|
+
import type { AxCrewConfig } from "../dist/index.js";
|
|
5
|
+
|
|
6
|
+
dotenv.config();
|
|
7
|
+
|
|
8
|
+
const runtime = new AxJSRuntime({
|
|
9
|
+
permissions: [AxJSRuntimePermission.TIMING],
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const config: AxCrewConfig = {
|
|
13
|
+
crew: [
|
|
14
|
+
{
|
|
15
|
+
name: "PolicyLookupAgent",
|
|
16
|
+
description: "Looks up policy details in the provided knowledge base.",
|
|
17
|
+
executionMode: "axagent",
|
|
18
|
+
signature:
|
|
19
|
+
'question:string -> answer:string "Looks up company policies and returns a concise answer"',
|
|
20
|
+
provider: "google-gemini",
|
|
21
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
22
|
+
ai: {
|
|
23
|
+
model: "gemini-2.5-flash",
|
|
24
|
+
temperature: 0,
|
|
25
|
+
},
|
|
26
|
+
axAgentOptions: {
|
|
27
|
+
// Mandatory for AxAgent RLM mode (even if empty)
|
|
28
|
+
contextFields: [],
|
|
29
|
+
runtime,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "BillingHelperAgent",
|
|
34
|
+
description: "Answers billing and account questions.",
|
|
35
|
+
executionMode: "axagent",
|
|
36
|
+
signature:
|
|
37
|
+
'question:string -> answer:string "Resolves billing and account questions"',
|
|
38
|
+
provider: "google-gemini",
|
|
39
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
40
|
+
ai: {
|
|
41
|
+
model: "gemini-2.5-flash",
|
|
42
|
+
temperature: 0,
|
|
43
|
+
},
|
|
44
|
+
axAgentOptions: {
|
|
45
|
+
contextFields: [],
|
|
46
|
+
runtime,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "SentimentClassifierAgent",
|
|
51
|
+
description: "Classifies customer message sentiment.",
|
|
52
|
+
executionMode: "axagent",
|
|
53
|
+
signature: 'question:string -> sentiment:string "positive, negative, or neutral"',
|
|
54
|
+
provider: "google-gemini",
|
|
55
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
56
|
+
ai: {
|
|
57
|
+
model: "gemini-2.5-flash",
|
|
58
|
+
temperature: 0,
|
|
59
|
+
},
|
|
60
|
+
axAgentOptions: {
|
|
61
|
+
contextFields: [],
|
|
62
|
+
// Opt out of parent shared fields for this specialist.
|
|
63
|
+
fields: { excluded: ["knowledgeBase", "userId"] },
|
|
64
|
+
runtime,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "CustomerSupportAgent",
|
|
69
|
+
description: "Routes queries to specialists and returns a final answer.",
|
|
70
|
+
executionMode: "axagent",
|
|
71
|
+
signature: "query:string, knowledgeBase:string, userId:string -> answer:string",
|
|
72
|
+
provider: "google-gemini",
|
|
73
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
74
|
+
ai: {
|
|
75
|
+
model: "gemini-2.5-flash",
|
|
76
|
+
temperature: 0,
|
|
77
|
+
},
|
|
78
|
+
agents: [
|
|
79
|
+
"PolicyLookupAgent",
|
|
80
|
+
"BillingHelperAgent",
|
|
81
|
+
"SentimentClassifierAgent",
|
|
82
|
+
],
|
|
83
|
+
options: {
|
|
84
|
+
debug: true,
|
|
85
|
+
},
|
|
86
|
+
axAgentOptions: {
|
|
87
|
+
// Mandatory and central to shared-field example
|
|
88
|
+
contextFields: ["knowledgeBase"],
|
|
89
|
+
fields: { shared: ["knowledgeBase", "userId"] },
|
|
90
|
+
runtime,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const knowledgeBase = `
|
|
97
|
+
=== COMPANY POLICIES ===
|
|
98
|
+
|
|
99
|
+
REFUND POLICY:
|
|
100
|
+
- Full refund within 30 days of purchase for unused items.
|
|
101
|
+
- Partial refund (50%) for items returned between 31-60 days.
|
|
102
|
+
- No refunds after 60 days.
|
|
103
|
+
- Digital products are non-refundable after download.
|
|
104
|
+
|
|
105
|
+
SHIPPING POLICY:
|
|
106
|
+
- Standard shipping: 5-7 business days, free for orders over $50.
|
|
107
|
+
- Express shipping: 2-3 business days, $12.99 flat rate.
|
|
108
|
+
- International shipping: 10-15 business days, varies by destination.
|
|
109
|
+
|
|
110
|
+
LOYALTY PROGRAM:
|
|
111
|
+
- Bronze tier: 0-499 points - 5% discount on all orders.
|
|
112
|
+
- Silver tier: 500-1499 points - 10% discount + free standard shipping.
|
|
113
|
+
- Gold tier: 1500+ points - 15% discount + free express shipping + early access to sales.
|
|
114
|
+
- Points earned: $1 spent = 1 point.
|
|
115
|
+
|
|
116
|
+
=== ACCOUNT DATA (userId: cust-42) ===
|
|
117
|
+
|
|
118
|
+
Name: Alice Johnson
|
|
119
|
+
Tier: Silver (720 points)
|
|
120
|
+
Recent Orders:
|
|
121
|
+
- Order #A100: Widget Pro, purchased 12 days ago, $89.99, delivered
|
|
122
|
+
- Order #A101: Smart Lamp, purchased 45 days ago, $34.50, delivered
|
|
123
|
+
- Order #A102: USB-C Hub, purchased 3 days ago, $24.99, shipped
|
|
124
|
+
Payment Method: Visa ending in 4242
|
|
125
|
+
`.trim();
|
|
126
|
+
|
|
127
|
+
const main = async (): Promise<void> => {
|
|
128
|
+
const crew = new AxCrew(config);
|
|
129
|
+
try {
|
|
130
|
+
await crew.addAllAgents();
|
|
131
|
+
|
|
132
|
+
const supportAgent = crew.agents?.get("CustomerSupportAgent");
|
|
133
|
+
if (!supportAgent) throw new Error("Failed to initialize CustomerSupportAgent");
|
|
134
|
+
|
|
135
|
+
const result = await supportAgent.forward({
|
|
136
|
+
query:
|
|
137
|
+
"I want to return the Smart Lamp from order #A101. Am I eligible for a full refund? " +
|
|
138
|
+
"Also, how many more points do I need to reach Gold tier?",
|
|
139
|
+
knowledgeBase,
|
|
140
|
+
userId: "cust-42",
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
console.log("\n=== Support Answer ===");
|
|
144
|
+
console.log(result.answer);
|
|
145
|
+
|
|
146
|
+
const supportMetrics = (supportAgent as any).getMetrics?.();
|
|
147
|
+
const policyMetrics = (crew.agents?.get("PolicyLookupAgent") as any)?.getMetrics?.();
|
|
148
|
+
const billingMetrics = (crew.agents?.get("BillingHelperAgent") as any)?.getMetrics?.();
|
|
149
|
+
const sentimentMetrics = (crew.agents?.get("SentimentClassifierAgent") as any)?.getMetrics?.();
|
|
150
|
+
const crewMetrics = crew.getCrewMetrics();
|
|
151
|
+
|
|
152
|
+
console.log("\n=== Cost & Usage (Agents) ===");
|
|
153
|
+
console.log(
|
|
154
|
+
`CustomerSupportAgent USD=${supportMetrics?.estimatedCostUSD ?? 0}, tokens=${supportMetrics?.tokens?.totalTokens ?? 0}`
|
|
155
|
+
);
|
|
156
|
+
console.log(
|
|
157
|
+
`PolicyLookupAgent USD=${policyMetrics?.estimatedCostUSD ?? 0}, tokens=${policyMetrics?.tokens?.totalTokens ?? 0}`
|
|
158
|
+
);
|
|
159
|
+
console.log(
|
|
160
|
+
`BillingHelperAgent USD=${billingMetrics?.estimatedCostUSD ?? 0}, tokens=${billingMetrics?.tokens?.totalTokens ?? 0}`
|
|
161
|
+
);
|
|
162
|
+
console.log(
|
|
163
|
+
`SentimentClassifierAgent USD=${sentimentMetrics?.estimatedCostUSD ?? 0}, tokens=${sentimentMetrics?.tokens?.totalTokens ?? 0}`
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
console.log("\n=== Cost & Usage (Crew) ===");
|
|
167
|
+
console.log(`Estimated USD: ${crewMetrics?.estimatedCostUSD ?? 0}`);
|
|
168
|
+
console.log(
|
|
169
|
+
`Tokens: prompt=${crewMetrics?.tokens?.promptTokens ?? 0}, completion=${crewMetrics?.tokens?.completionTokens ?? 0}, total=${crewMetrics?.tokens?.totalTokens ?? 0}`
|
|
170
|
+
);
|
|
171
|
+
} finally {
|
|
172
|
+
crew.destroy();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
main()
|
|
177
|
+
.then(() => process.exit(0))
|
|
178
|
+
.catch((error: unknown) => {
|
|
179
|
+
console.error(error);
|
|
180
|
+
process.exit(1);
|
|
181
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@amitdeshmukh/ax-crew",
|
|
4
|
-
"version": "8.0
|
|
4
|
+
"version": "8.1.0",
|
|
5
5
|
"description": "Build and launch a crew of AI agents with shared state. Built with axllm.dev",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"uuid": "^10.0.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@ax-llm/ax": "^
|
|
28
|
-
"@ax-llm/ax-tools": "^
|
|
27
|
+
"@ax-llm/ax": "^19.0.11",
|
|
28
|
+
"@ax-llm/ax-tools": "^19.0.11",
|
|
29
29
|
"@opentelemetry/api": "^1.9.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
@@ -6,6 +6,8 @@ import { AxMCPStdioTransport } from '@ax-llm/ax-tools'
|
|
|
6
6
|
// Resolve env by provided key name
|
|
7
7
|
import type {
|
|
8
8
|
AgentConfig,
|
|
9
|
+
AgentExecutionMode,
|
|
10
|
+
AxCrewAxAgentOptions,
|
|
9
11
|
AxCrewConfig,
|
|
10
12
|
AxCrewOptions,
|
|
11
13
|
FunctionRegistryType,
|
|
@@ -204,11 +206,16 @@ const parseAgentConfig = async (
|
|
|
204
206
|
// Add MCP functions to functions
|
|
205
207
|
...mcpFunctions
|
|
206
208
|
];
|
|
209
|
+
|
|
210
|
+
const executionMode: AgentExecutionMode =
|
|
211
|
+
agentConfigData.executionMode === 'axgen' ? 'axgen' : 'axagent';
|
|
207
212
|
|
|
208
213
|
// Return AI instance and Agent parameters
|
|
209
214
|
return {
|
|
210
215
|
ai: aiInstance,
|
|
211
216
|
name: agentName,
|
|
217
|
+
executionMode,
|
|
218
|
+
axAgentOptions: (agentConfigData.axAgentOptions ?? {}) as AxCrewAxAgentOptions,
|
|
212
219
|
description: agentConfigData.description,
|
|
213
220
|
definition: (agentConfigData as any).definition ?? (agentConfigData as any).prompt,
|
|
214
221
|
signature: agentConfigData.signature,
|
|
@@ -246,4 +253,4 @@ function resolveApiKey(varName: string): string | undefined {
|
|
|
246
253
|
} catch {
|
|
247
254
|
return undefined;
|
|
248
255
|
}
|
|
249
|
-
}
|
|
256
|
+
}
|