@amitdeshmukh/ax-crew 4.1.2 → 6.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 +43 -0
- package/README.md +8 -51
- package/dist/agents/agentConfig.d.ts +6 -6
- package/dist/agents/agentConfig.js +45 -96
- package/dist/agents/agentUseCosts.d.ts +14 -0
- package/dist/agents/agentUseCosts.js +14 -0
- package/dist/agents/compose.d.ts +15 -0
- package/dist/agents/compose.js +58 -0
- package/dist/agents/index.d.ts +42 -5
- package/dist/agents/index.js +41 -4
- package/dist/functions/index.d.ts +11 -0
- package/dist/functions/index.js +11 -1
- package/dist/index.d.ts +25 -8
- package/dist/index.js +26 -1
- package/dist/metrics/registry.d.ts +27 -0
- package/dist/metrics/registry.js +27 -0
- package/dist/types.d.ts +45 -6
- package/examples/basic-researcher-writer.ts +5 -3
- package/examples/mcp-agent.ts +20 -43
- package/examples/perplexityDeepSearch.ts +6 -5
- package/examples/providerArgs.ts +42 -0
- package/examples/search-tweets.ts +5 -4
- package/examples/solve-math-problem.ts +7 -5
- package/examples/streaming.ts +2 -2
- package/package.json +4 -4
- package/src/agents/agentConfig.ts +49 -106
- package/src/agents/agentUseCosts.ts +14 -0
- package/src/agents/compose.ts +80 -0
- package/src/agents/index.ts +44 -7
- package/src/functions/index.ts +11 -1
- package/src/index.ts +25 -11
- package/src/metrics/registry.ts +27 -0
- package/src/types.ts +49 -21
- package/dist/config/index.d.ts +0 -5
- package/dist/config/index.js +0 -30
- package/src/config/index.ts +0 -40
package/dist/agents/index.js
CHANGED
|
@@ -156,17 +156,43 @@ class StatefulAxAgent extends AxAgent {
|
|
|
156
156
|
// Get the accumulated costs for all runs of this agent
|
|
157
157
|
getAccumulatedCosts() { return null; }
|
|
158
158
|
// Metrics API for this agent
|
|
159
|
+
/**
|
|
160
|
+
* Get the current metrics snapshot for this agent.
|
|
161
|
+
* Includes request counts, error rates, token usage, estimated USD cost, and function call stats.
|
|
162
|
+
*
|
|
163
|
+
* @returns A metrics snapshot scoped to this agent within its crew.
|
|
164
|
+
*/
|
|
159
165
|
getMetrics() {
|
|
160
166
|
const crewId = this.state?.crewId || (this.state.get?.('crewId')) || 'default';
|
|
161
167
|
return MetricsRegistry.snapshot({ crewId, agent: this.agentName });
|
|
162
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Reset all tracked metrics for this agent (does not affect other agents).
|
|
171
|
+
* Call this to start fresh measurement windows for the agent.
|
|
172
|
+
*/
|
|
163
173
|
resetMetrics() {
|
|
164
174
|
const crewId = this.state?.crewId || (this.state.get?.('crewId')) || 'default';
|
|
165
175
|
MetricsRegistry.reset({ crewId, agent: this.agentName });
|
|
166
176
|
}
|
|
167
177
|
}
|
|
168
178
|
/**
|
|
169
|
-
*
|
|
179
|
+
* AxCrew orchestrates a set of Ax agents that share state,
|
|
180
|
+
* tools (functions), optional MCP servers, streaming, and a built-in metrics
|
|
181
|
+
* registry for tokens, requests, and estimated cost.
|
|
182
|
+
*
|
|
183
|
+
* Typical usage:
|
|
184
|
+
* const crew = new AxCrew(config, AxCrewFunctions)
|
|
185
|
+
* await crew.addAllAgents()
|
|
186
|
+
* const planner = crew.agents?.get("Planner")
|
|
187
|
+
* const res = await planner?.forward({ task: "Plan something" })
|
|
188
|
+
*
|
|
189
|
+
* Key behaviors:
|
|
190
|
+
* - Validates and instantiates agents from a config-first model
|
|
191
|
+
* - Shares a mutable state object across all agents in the crew
|
|
192
|
+
* - Supports sub-agents and a function registry per agent
|
|
193
|
+
* - Tracks per-agent and crew-level metrics via MetricsRegistry
|
|
194
|
+
* - Provides helpers to add agents (individually, a subset, or all) and
|
|
195
|
+
* to reset metrics/costs when needed
|
|
170
196
|
*/
|
|
171
197
|
class AxCrew {
|
|
172
198
|
crewConfig;
|
|
@@ -176,7 +202,7 @@ class AxCrew {
|
|
|
176
202
|
state;
|
|
177
203
|
/**
|
|
178
204
|
* Creates an instance of AxCrew.
|
|
179
|
-
* @param {
|
|
205
|
+
* @param {AxCrewConfig} crewConfig - JSON object with crew configuration.
|
|
180
206
|
* @param {FunctionRegistryType} [functionsRegistry={}] - The registry of functions to use in the crew.
|
|
181
207
|
* @param {string} [crewId=uuidv4()] - The unique identifier for the crew.
|
|
182
208
|
*/
|
|
@@ -186,7 +212,7 @@ class AxCrew {
|
|
|
186
212
|
throw new Error('Invalid crew configuration');
|
|
187
213
|
}
|
|
188
214
|
// Validate each agent in the crew
|
|
189
|
-
crewConfig.crew.forEach(agent => {
|
|
215
|
+
crewConfig.crew.forEach((agent) => {
|
|
190
216
|
if (!agent.name || agent.name.trim() === '') {
|
|
191
217
|
throw new Error('Agent name cannot be empty');
|
|
192
218
|
}
|
|
@@ -376,7 +402,8 @@ class AxCrew {
|
|
|
376
402
|
this.state.reset();
|
|
377
403
|
}
|
|
378
404
|
/**
|
|
379
|
-
* Resets all cost tracking for the crew
|
|
405
|
+
* Resets all cost and usage tracking for the entire crew.
|
|
406
|
+
* Also calls each agent's `resetUsage` (if available) and clears crew-level metrics.
|
|
380
407
|
*/
|
|
381
408
|
resetCosts() {
|
|
382
409
|
// Reset AxAgent built-in usage and our metrics registry
|
|
@@ -395,9 +422,19 @@ class AxCrew {
|
|
|
395
422
|
MetricsRegistry.reset({ crewId: this.crewId });
|
|
396
423
|
}
|
|
397
424
|
// Metrics API
|
|
425
|
+
/**
|
|
426
|
+
* Get an aggregate metrics snapshot for the entire crew.
|
|
427
|
+
* Sums requests, errors, tokens, and estimated cost across all agents in the crew.
|
|
428
|
+
*
|
|
429
|
+
* @returns Crew-level metrics snapshot.
|
|
430
|
+
*/
|
|
398
431
|
getCrewMetrics() {
|
|
399
432
|
return MetricsRegistry.snapshotCrew(this.crewId);
|
|
400
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Reset all tracked metrics for the entire crew.
|
|
436
|
+
* Use to clear totals before a new measurement period.
|
|
437
|
+
*/
|
|
401
438
|
resetCrewMetrics() {
|
|
402
439
|
MetricsRegistry.reset({ crewId: this.crewId });
|
|
403
440
|
}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in function registry for AxCrew agents.
|
|
3
|
+
*
|
|
4
|
+
* Contains common utility tools/functions that can be referenced by name from
|
|
5
|
+
* agent configs (e.g., "functions": ["CurrentDateTime", "DaysBetweenDates"]).
|
|
6
|
+
* You can pass this object to the AxCrew constructor or merge with your
|
|
7
|
+
* own registry.
|
|
8
|
+
* Example:
|
|
9
|
+
* const crew = new AxCrew(config, AxCrewFunctions); or
|
|
10
|
+
* const crew = new AxCrew(config, { ...AxCrewFunctions, ...myFunctions });
|
|
11
|
+
*/
|
|
1
12
|
declare const AxCrewFunctions: {
|
|
2
13
|
CurrentDateTime: import("@ax-llm/ax").AxFunction;
|
|
3
14
|
DaysBetweenDates: import("@ax-llm/ax").AxFunction;
|
package/dist/functions/index.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { CurrentDateTime, DaysBetweenDates } from './dateTime.js';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Built-in function registry for AxCrew agents.
|
|
4
|
+
*
|
|
5
|
+
* Contains common utility tools/functions that can be referenced by name from
|
|
6
|
+
* agent configs (e.g., "functions": ["CurrentDateTime", "DaysBetweenDates"]).
|
|
7
|
+
* You can pass this object to the AxCrew constructor or merge with your
|
|
8
|
+
* own registry.
|
|
9
|
+
* Example:
|
|
10
|
+
* const crew = new AxCrew(config, AxCrewFunctions); or
|
|
11
|
+
* const crew = new AxCrew(config, { ...AxCrewFunctions, ...myFunctions });
|
|
12
|
+
*/
|
|
3
13
|
const AxCrewFunctions = {
|
|
4
14
|
CurrentDateTime,
|
|
5
15
|
DaysBetweenDates
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { AxCrew } from './agents/index.js';
|
|
2
2
|
import { AxCrewFunctions } from './functions/index.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AxCrewConfig, AgentConfig } from './types.js';
|
|
4
4
|
import type { UsageCost, AggregatedMetrics, AggregatedCosts, StateInstance, FunctionRegistryType } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Metrics types and helpers for request counts, token usage, and estimated cost.
|
|
7
|
+
*
|
|
8
|
+
* Re-exports the metrics module for convenience:
|
|
9
|
+
* - Types: TokenUsage, MetricsSnapshot, etc.
|
|
10
|
+
* - Namespace: MetricsRegistry (record/snapshot/reset helpers)
|
|
11
|
+
*/
|
|
5
12
|
export * from './metrics/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* MetricsRegistry provides functions to record requests, tokens, and cost,
|
|
15
|
+
* and to snapshot/reset metrics at agent or crew granularity.
|
|
16
|
+
*/
|
|
6
17
|
export { MetricsRegistry } from './metrics/index.js';
|
|
7
18
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
19
|
+
* Create and manage a crew of Ax agents that share state and metrics.
|
|
20
|
+
* See the `AxCrew` class for full documentation.
|
|
21
|
+
*/
|
|
22
|
+
declare const _AxCrew: typeof AxCrew;
|
|
23
|
+
/**
|
|
24
|
+
* Built-in function registry with common tools that can be referenced by name
|
|
25
|
+
* from agent configs, or extended with your own functions.
|
|
11
26
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
27
|
+
declare const _AxCrewFunctions: typeof AxCrewFunctions;
|
|
28
|
+
export {
|
|
29
|
+
/** See class JSDoc on the `AxCrew` implementation. */
|
|
30
|
+
_AxCrew as AxCrew,
|
|
31
|
+
/** Built-in function registry; see file docs in `src/functions/index.ts`. */
|
|
32
|
+
_AxCrewFunctions as AxCrewFunctions, FunctionRegistryType, type AggregatedMetrics, type AggregatedCosts, type AgentConfig, type AxCrewConfig, type StateInstance, type UsageCost, };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
import { AxCrew } from './agents/index.js';
|
|
2
2
|
import { AxCrewFunctions } from './functions/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Metrics types and helpers for request counts, token usage, and estimated cost.
|
|
5
|
+
*
|
|
6
|
+
* Re-exports the metrics module for convenience:
|
|
7
|
+
* - Types: TokenUsage, MetricsSnapshot, etc.
|
|
8
|
+
* - Namespace: MetricsRegistry (record/snapshot/reset helpers)
|
|
9
|
+
*/
|
|
3
10
|
export * from './metrics/index.js';
|
|
11
|
+
/**
|
|
12
|
+
* MetricsRegistry provides functions to record requests, tokens, and cost,
|
|
13
|
+
* and to snapshot/reset metrics at agent or crew granularity.
|
|
14
|
+
*/
|
|
4
15
|
export { MetricsRegistry } from './metrics/index.js';
|
|
5
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Create and manage a crew of Ax agents that share state and metrics.
|
|
18
|
+
* See the `AxCrew` class for full documentation.
|
|
19
|
+
*/
|
|
20
|
+
const _AxCrew = AxCrew;
|
|
21
|
+
/**
|
|
22
|
+
* Built-in function registry with common tools that can be referenced by name
|
|
23
|
+
* from agent configs, or extended with your own functions.
|
|
24
|
+
*/
|
|
25
|
+
const _AxCrewFunctions = AxCrewFunctions;
|
|
26
|
+
export {
|
|
27
|
+
/** See class JSDoc on the `AxCrew` implementation. */
|
|
28
|
+
_AxCrew as AxCrew,
|
|
29
|
+
/** Built-in function registry; see file docs in `src/functions/index.ts`. */
|
|
30
|
+
_AxCrewFunctions as AxCrewFunctions, };
|
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
import type { LabelKeys, MetricsSnapshot, TokenUsage } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Record a completed request.
|
|
4
|
+
* @param labels Crew/agent/provider/model identifiers
|
|
5
|
+
* @param streaming Whether this was a streaming request
|
|
6
|
+
* @param durationMs Duration in milliseconds
|
|
7
|
+
*/
|
|
2
8
|
export declare function recordRequest(labels: LabelKeys, streaming: boolean, durationMs: number): void;
|
|
9
|
+
/**
|
|
10
|
+
* Record an error occurrence for the given labels.
|
|
11
|
+
*/
|
|
3
12
|
export declare function recordError(labels: LabelKeys): void;
|
|
13
|
+
/**
|
|
14
|
+
* Record token usage for a request (prompt and completion).
|
|
15
|
+
*/
|
|
4
16
|
export declare function recordTokens(labels: LabelKeys, usage: TokenUsage): void;
|
|
17
|
+
/**
|
|
18
|
+
* Add estimated cost (USD) to the cumulative total for the labels.
|
|
19
|
+
*/
|
|
5
20
|
export declare function recordEstimatedCost(labels: LabelKeys, usd: number): void;
|
|
21
|
+
/**
|
|
22
|
+
* Record a function call invocation and add its latency to totals.
|
|
23
|
+
*/
|
|
6
24
|
export declare function recordFunctionCall(labels: LabelKeys, latencyMs: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Get a metrics snapshot for specific labels (crew + agent + optional provider/model).
|
|
27
|
+
*/
|
|
7
28
|
export declare function snapshot(labels: LabelKeys): MetricsSnapshot;
|
|
29
|
+
/**
|
|
30
|
+
* Reset metrics for specific labels, or clear all if no labels provided.
|
|
31
|
+
*/
|
|
8
32
|
export declare function reset(labels?: LabelKeys): void;
|
|
33
|
+
/**
|
|
34
|
+
* Aggregate a crew-wide metrics snapshot across all agents in the crew.
|
|
35
|
+
*/
|
|
9
36
|
export declare function snapshotCrew(crewId: string): MetricsSnapshot;
|
package/dist/metrics/registry.js
CHANGED
|
@@ -24,6 +24,12 @@ function getOrInit(labels) {
|
|
|
24
24
|
}
|
|
25
25
|
return c;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Record a completed request.
|
|
29
|
+
* @param labels Crew/agent/provider/model identifiers
|
|
30
|
+
* @param streaming Whether this was a streaming request
|
|
31
|
+
* @param durationMs Duration in milliseconds
|
|
32
|
+
*/
|
|
27
33
|
export function recordRequest(labels, streaming, durationMs) {
|
|
28
34
|
const c = getOrInit(labels);
|
|
29
35
|
c.requests += 1;
|
|
@@ -32,26 +38,41 @@ export function recordRequest(labels, streaming, durationMs) {
|
|
|
32
38
|
c.durationMsSum += durationMs;
|
|
33
39
|
c.durationCount += 1;
|
|
34
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Record an error occurrence for the given labels.
|
|
43
|
+
*/
|
|
35
44
|
export function recordError(labels) {
|
|
36
45
|
const c = getOrInit(labels);
|
|
37
46
|
c.errors += 1;
|
|
38
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Record token usage for a request (prompt and completion).
|
|
50
|
+
*/
|
|
39
51
|
export function recordTokens(labels, usage) {
|
|
40
52
|
const c = getOrInit(labels);
|
|
41
53
|
c.inputTokens += usage.promptTokens || 0;
|
|
42
54
|
c.outputTokens += usage.completionTokens || 0;
|
|
43
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Add estimated cost (USD) to the cumulative total for the labels.
|
|
58
|
+
*/
|
|
44
59
|
export function recordEstimatedCost(labels, usd) {
|
|
45
60
|
const c = getOrInit(labels);
|
|
46
61
|
const current = new Big(c.estimatedCostUSD || 0);
|
|
47
62
|
const addition = new Big(usd || 0);
|
|
48
63
|
c.estimatedCostUSD = Number(current.plus(addition));
|
|
49
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Record a function call invocation and add its latency to totals.
|
|
67
|
+
*/
|
|
50
68
|
export function recordFunctionCall(labels, latencyMs) {
|
|
51
69
|
const c = getOrInit(labels);
|
|
52
70
|
c.functionCalls += 1;
|
|
53
71
|
c.functionLatencyMs += latencyMs || 0;
|
|
54
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Get a metrics snapshot for specific labels (crew + agent + optional provider/model).
|
|
75
|
+
*/
|
|
55
76
|
export function snapshot(labels) {
|
|
56
77
|
const c = getOrInit(labels);
|
|
57
78
|
const totalTokens = c.inputTokens + c.outputTokens;
|
|
@@ -78,6 +99,9 @@ export function snapshot(labels) {
|
|
|
78
99
|
},
|
|
79
100
|
};
|
|
80
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Reset metrics for specific labels, or clear all if no labels provided.
|
|
104
|
+
*/
|
|
81
105
|
export function reset(labels) {
|
|
82
106
|
if (!labels) {
|
|
83
107
|
store.clear();
|
|
@@ -86,6 +110,9 @@ export function reset(labels) {
|
|
|
86
110
|
const k = keyOf(labels);
|
|
87
111
|
store.delete(k);
|
|
88
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Aggregate a crew-wide metrics snapshot across all agents in the crew.
|
|
115
|
+
*/
|
|
89
116
|
export function snapshotCrew(crewId) {
|
|
90
117
|
const empty = {
|
|
91
118
|
requests: 0,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AxFunction, AxSignature, AxModelConfig, AxMCPStreamableHTTPTransportOptions, AxProgramForwardOptions } from '@ax-llm/ax';
|
|
2
|
-
export type Provider = '
|
|
1
|
+
import type { AxFunction, AxSignature, AxModelConfig, AxMCPStreamableHTTPTransportOptions, AxProgramForwardOptions, AxAIArgs } from '@ax-llm/ax';
|
|
2
|
+
export type Provider = AxAIArgs<any>['name'];
|
|
3
3
|
/**
|
|
4
4
|
* A state instance that is shared between agents.
|
|
5
5
|
* This can be used to store data that becomes available to all agents and functions in an out-of-band manner.
|
|
@@ -165,6 +165,11 @@ interface AgentConfig {
|
|
|
165
165
|
};
|
|
166
166
|
debug?: boolean;
|
|
167
167
|
apiURL?: string;
|
|
168
|
+
/**
|
|
169
|
+
* Provider-specific arguments that are forwarded to the underlying Ax factory.
|
|
170
|
+
* Example (azure-openai): { resourceName, deploymentName, version }
|
|
171
|
+
*/
|
|
172
|
+
providerArgs?: Record<string, unknown>;
|
|
168
173
|
options?: Partial<AxProgramForwardOptions<any>> & Record<string, any>;
|
|
169
174
|
functions?: string[];
|
|
170
175
|
agents?: string[];
|
|
@@ -172,9 +177,43 @@ interface AgentConfig {
|
|
|
172
177
|
mcpServers?: Record<string, MCPTransportConfig>;
|
|
173
178
|
}
|
|
174
179
|
/**
|
|
175
|
-
* The
|
|
180
|
+
* The configuration object for an AxCrew instance.
|
|
181
|
+
*
|
|
182
|
+
* @property {AgentConfig[]} crew - The agents that make up the crew.
|
|
183
|
+
* @example
|
|
184
|
+
* const config: AxCrewConfig = {
|
|
185
|
+
* crew: [
|
|
186
|
+
* {
|
|
187
|
+
* name: "Agent1",
|
|
188
|
+
* description: "Agent 1 description",
|
|
189
|
+
* signature: "signature",
|
|
190
|
+
* provider: "provider",
|
|
191
|
+
* providerKeyName: "providerKeyName",
|
|
192
|
+
* ai: {
|
|
193
|
+
* model: "model",
|
|
194
|
+
* temperature: 0,
|
|
195
|
+
* },
|
|
196
|
+
* options: {
|
|
197
|
+
* debug: true,
|
|
198
|
+
* },
|
|
199
|
+
* functions: ["function1", "function2"],
|
|
200
|
+
* agents: ["agent2"],
|
|
201
|
+
* },
|
|
202
|
+
* {
|
|
203
|
+
* name: "Agent2",
|
|
204
|
+
* description: "Agent 2 description",
|
|
205
|
+
* signature: "signature",
|
|
206
|
+
* provider: "provider",
|
|
207
|
+
* providerKeyName: "providerKeyName",
|
|
208
|
+
* ai: {
|
|
209
|
+
* model: "model",
|
|
210
|
+
* temperature: 0,
|
|
211
|
+
* }
|
|
212
|
+
* ]
|
|
213
|
+
* }
|
|
214
|
+
* const crew = new AxCrew(config);
|
|
176
215
|
*/
|
|
177
|
-
|
|
216
|
+
interface AxCrewConfig {
|
|
178
217
|
crew: AgentConfig[];
|
|
179
|
-
}
|
|
180
|
-
export { type AgentConfig, type
|
|
218
|
+
}
|
|
219
|
+
export { type AgentConfig, type AxCrewConfig, type AggregatedMetrics, type StateInstance, type FunctionRegistryType, type MCPStdioTransportConfig, type MCPHTTPSSETransportConfig, type MCPStreamableHTTPTransportConfig, type MCPTransportConfig, type ModelUsage, type ModelInfo, type UsageCost, type AggregatedCosts };
|
|
@@ -2,6 +2,8 @@ import { AxCrew } from "../dist/index.js";
|
|
|
2
2
|
import { AxCrewFunctions } from "../dist/functions/index.js";
|
|
3
3
|
import type { AxCrewConfig } from "../dist/index.js";
|
|
4
4
|
import type { Provider } from "../dist/types.js";
|
|
5
|
+
import dotenv from "dotenv";
|
|
6
|
+
dotenv.config();
|
|
5
7
|
|
|
6
8
|
// Example agent configuration
|
|
7
9
|
const agentConfig: AxCrewConfig = {
|
|
@@ -26,10 +28,10 @@ const agentConfig: AxCrewConfig = {
|
|
|
26
28
|
name: "writer",
|
|
27
29
|
description: "A writing agent that creates content",
|
|
28
30
|
signature: "topic:string -> article:string",
|
|
29
|
-
provider: "
|
|
30
|
-
providerKeyName: "
|
|
31
|
+
provider: "google-gemini" as Provider,
|
|
32
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
31
33
|
ai: {
|
|
32
|
-
model: "
|
|
34
|
+
model: "gemini-2.5-flash-lite",
|
|
33
35
|
maxTokens: 4000,
|
|
34
36
|
stream: true
|
|
35
37
|
},
|
package/examples/mcp-agent.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AxCrew
|
|
1
|
+
import { AxCrew } from "../dist/index.js";
|
|
2
|
+
import type { AxCrewConfig } from "../dist/types.js";
|
|
2
3
|
|
|
3
4
|
import dotenv from "dotenv";
|
|
4
5
|
dotenv.config();
|
|
@@ -7,31 +8,23 @@ dotenv.config();
|
|
|
7
8
|
const config = {
|
|
8
9
|
crew: [
|
|
9
10
|
{
|
|
10
|
-
name: "
|
|
11
|
-
description: "A specialized agent with access to
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
providerKeyName: "ANTHROPIC_API_KEY",
|
|
11
|
+
name: "Context7DocsAgent",
|
|
12
|
+
description: "A specialized agent with access to Context7 Docs APIs that can: search for and get details about API docs",
|
|
13
|
+
signature: 'apiDocQuery:string "a question to be answered" -> apiDocAnswer:string "the answer to the question"',
|
|
14
|
+
provider: "google-gemini",
|
|
15
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
16
16
|
ai: {
|
|
17
|
-
model: "
|
|
17
|
+
model: "gemini-2.5-pro",
|
|
18
18
|
temperature: 0,
|
|
19
|
-
|
|
20
|
-
stream: true
|
|
19
|
+
stream: false
|
|
21
20
|
},
|
|
22
21
|
options: {
|
|
23
22
|
debug: true
|
|
24
23
|
},
|
|
25
24
|
"mcpServers": {
|
|
26
|
-
"
|
|
25
|
+
"context7": {
|
|
27
26
|
"command": "npx",
|
|
28
|
-
"args": [
|
|
29
|
-
"-y",
|
|
30
|
-
"@modelcontextprotocol/server-google-maps"
|
|
31
|
-
],
|
|
32
|
-
"env": {
|
|
33
|
-
"GOOGLE_MAPS_API_KEY": process.env.GOOGLE_MAPS_API_KEY
|
|
34
|
-
}
|
|
27
|
+
"args": ["-y", "@upstash/context7-mcp", "--api-key", process.env.CONTEXT7_API_KEY]
|
|
35
28
|
}
|
|
36
29
|
},
|
|
37
30
|
},
|
|
@@ -41,35 +34,19 @@ const config = {
|
|
|
41
34
|
prompt: "You are a manager agent that orchestrates tools and sub-agents. Read the user's objective, optionally produce a short plan, then call the MapsAgent when geospatial knowledge is needed. Keep answers direct and avoid extraneous commentary.",
|
|
42
35
|
signature:
|
|
43
36
|
'question:string "a question to be answered" -> answer:string "the answer to the question"',
|
|
44
|
-
provider: "
|
|
45
|
-
providerKeyName: "
|
|
37
|
+
provider: "google-gemini",
|
|
38
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
46
39
|
ai: {
|
|
47
|
-
model: "
|
|
40
|
+
model: "gemini-2.5-pro",
|
|
48
41
|
maxTokens: 1000,
|
|
49
42
|
temperature: 0,
|
|
50
|
-
stream:
|
|
43
|
+
stream: false
|
|
51
44
|
},
|
|
52
45
|
options: {
|
|
53
46
|
debug: true,
|
|
54
47
|
},
|
|
55
|
-
agents: ["
|
|
56
|
-
}
|
|
57
|
-
{
|
|
58
|
-
name: "MathAgent",
|
|
59
|
-
description: "Solves math problems",
|
|
60
|
-
signature:
|
|
61
|
-
'mathProblem:string "a sentence describing a math problem to be solved using Python code" -> solution:string "the answer to the math problem"',
|
|
62
|
-
provider: "google-gemini",
|
|
63
|
-
providerKeyName: "GEMINI_API_KEY",
|
|
64
|
-
ai: {
|
|
65
|
-
model: "gemini-1.5-pro",
|
|
66
|
-
temperature: 0,
|
|
67
|
-
stream: true
|
|
68
|
-
},
|
|
69
|
-
options: {
|
|
70
|
-
debug: false,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
48
|
+
agents: ["Context7DocsAgent"]
|
|
49
|
+
}
|
|
73
50
|
],
|
|
74
51
|
};
|
|
75
52
|
|
|
@@ -81,9 +58,9 @@ await crew.addAllAgents();
|
|
|
81
58
|
|
|
82
59
|
// Get agent instances
|
|
83
60
|
const managerAgent = crew.agents?.get("ManagerAgent");
|
|
84
|
-
const
|
|
61
|
+
const context7DocsAgent = crew.agents?.get("Context7DocsAgent");
|
|
85
62
|
|
|
86
|
-
const userQuery: string = "
|
|
63
|
+
const userQuery: string = "How do i create an agent in the @amitdeshmukh/ax-crew framework and configure it to use an MCP server? Give me a concrete example.";
|
|
87
64
|
|
|
88
65
|
console.log(`\n\nQuestion: ${userQuery}`);
|
|
89
66
|
|
|
@@ -97,7 +74,7 @@ const main = async (): Promise<void> => {
|
|
|
97
74
|
// Print metrics
|
|
98
75
|
console.log("\nMetrics:\n+++++++++++++++++++++++++++++++++");
|
|
99
76
|
console.log("Manager Agent Metrics:", JSON.stringify((managerAgent as any)?.getMetrics?.(), null, 2));
|
|
100
|
-
console.log("
|
|
77
|
+
console.log("Context7 Docs Agent Metrics:", JSON.stringify((context7DocsAgent as any)?.getMetrics?.(), null, 2));
|
|
101
78
|
console.log("Crew Metrics:", JSON.stringify((crew as any)?.getCrewMetrics?.(), null, 2));
|
|
102
79
|
};
|
|
103
80
|
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { AxCrew } from "../dist/index.js";
|
|
2
|
+
import type { AxCrewConfig } from "../dist/types.js";
|
|
2
3
|
|
|
3
4
|
import dotenv from "dotenv";
|
|
4
5
|
dotenv.config();
|
|
5
6
|
|
|
6
7
|
// Define the crew configuration
|
|
7
|
-
const config = {
|
|
8
|
+
const config: AxCrewConfig = {
|
|
8
9
|
crew: [
|
|
9
10
|
{
|
|
10
11
|
name: "DeepResearchAgent",
|
|
11
12
|
description: "A specialized agent that performs deep research using perplexity",
|
|
12
|
-
signature: 'researchTopic:string "a topic of interest" ->
|
|
13
|
-
provider: "
|
|
14
|
-
providerKeyName: "
|
|
13
|
+
signature: 'researchTopic:string "a topic of interest" -> researchResult:string "The result of the research"',
|
|
14
|
+
provider: "google-gemini",
|
|
15
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
15
16
|
ai: {
|
|
16
|
-
model: "
|
|
17
|
+
model: "gemini-2.5-flash-lite",
|
|
17
18
|
temperature: 0.1,
|
|
18
19
|
},
|
|
19
20
|
options: {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AxCrew } from "../dist/index.js";
|
|
2
|
+
import type { AxCrewConfig } from "../dist/types.js";
|
|
3
|
+
|
|
4
|
+
const crewConfig: AxCrewConfig = {
|
|
5
|
+
crew: [
|
|
6
|
+
{
|
|
7
|
+
name: "TestAgent",
|
|
8
|
+
description: "Test Agent for testing provider arguments",
|
|
9
|
+
provider: "azure-openai",
|
|
10
|
+
providerKeyName: "AZURE_OPENAI_API_KEY",
|
|
11
|
+
signature: "userQuery:string -> answer:string",
|
|
12
|
+
ai: {
|
|
13
|
+
model: "gpt-5-mini",
|
|
14
|
+
temperature: 0,
|
|
15
|
+
stream: false
|
|
16
|
+
},
|
|
17
|
+
providerArgs: {
|
|
18
|
+
resourceName: "your-resource-name",
|
|
19
|
+
deploymentName: "your-deployment-name",
|
|
20
|
+
version: "2025-01-01-preview"
|
|
21
|
+
},
|
|
22
|
+
functions: [],
|
|
23
|
+
options: {
|
|
24
|
+
debug: true,
|
|
25
|
+
stream: false
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const crew = new AxCrew(crewConfig);
|
|
32
|
+
await crew.addAllAgents();
|
|
33
|
+
|
|
34
|
+
const testAgent = crew.agents?.get("TestAgent");
|
|
35
|
+
|
|
36
|
+
const response = await testAgent?.forward({
|
|
37
|
+
userQuery: "What is the capital of France?"
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
console.log(response?.answer);
|
|
41
|
+
|
|
42
|
+
console.log(testAgent?.getAccumulatedCosts());
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { AxCrew } from "../dist/index.js";
|
|
2
|
+
import type { AxCrewConfig } from "../dist/types.js";
|
|
2
3
|
|
|
3
4
|
import dotenv from "dotenv";
|
|
4
5
|
dotenv.config();
|
|
5
6
|
|
|
6
7
|
// Define the crew configuration
|
|
7
|
-
const config = {
|
|
8
|
+
const config: AxCrewConfig = {
|
|
8
9
|
crew: [
|
|
9
10
|
{
|
|
10
11
|
name: "XSearchAgent",
|
|
11
12
|
description: "A specialized agent that can search X (Twitter) posts for the latest news and updates about specific topics, people, or events. It can find trending posts, recent tweets, and real-time information from X platform.",
|
|
12
|
-
signature: 'searchQuery:string "a search query" ->
|
|
13
|
+
signature: 'searchQuery:string "a search query" -> searchResults:string "the response to the user query citing relevant sources including X posts and other web sources"',
|
|
13
14
|
provider: "grok",
|
|
14
15
|
providerKeyName: "GROK_API_KEY",
|
|
15
16
|
ai: {
|
|
@@ -55,8 +56,8 @@ const main = async (): Promise<void> => {
|
|
|
55
56
|
if (response) {
|
|
56
57
|
try {
|
|
57
58
|
for await (const chunk of response) {
|
|
58
|
-
if (chunk.delta && typeof chunk.delta === 'object' && '
|
|
59
|
-
process.stdout.write(chunk.delta.
|
|
59
|
+
if (chunk.delta && typeof chunk.delta === 'object' && 'searchResults' in chunk.delta) {
|
|
60
|
+
process.stdout.write(chunk.delta.searchResults);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
console.log('\n');
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AxCrew } from "../dist/index.js";
|
|
2
2
|
import type { AxCrewConfig } from "../src/index.js";
|
|
3
|
+
import dotenv from "dotenv";
|
|
4
|
+
dotenv.config();
|
|
3
5
|
|
|
4
6
|
// Define the crew configuration
|
|
5
7
|
const config: AxCrewConfig = {
|
|
@@ -12,11 +14,11 @@ const config: AxCrewConfig = {
|
|
|
12
14
|
provider: "google-gemini",
|
|
13
15
|
providerKeyName: "GEMINI_API_KEY",
|
|
14
16
|
ai: {
|
|
15
|
-
model: "gemini-
|
|
17
|
+
model: "gemini-2.5-flash-lite",
|
|
16
18
|
temperature: 0,
|
|
17
19
|
},
|
|
18
20
|
options: {
|
|
19
|
-
debug:
|
|
21
|
+
debug: true,
|
|
20
22
|
codeExecution: true,
|
|
21
23
|
},
|
|
22
24
|
},
|
|
@@ -25,10 +27,10 @@ const config: AxCrewConfig = {
|
|
|
25
27
|
description: "Completes a user specified task",
|
|
26
28
|
signature:
|
|
27
29
|
'question:string "a question to be answered" -> answer:string "the answer to the question"',
|
|
28
|
-
provider: "
|
|
29
|
-
providerKeyName: "
|
|
30
|
+
provider: "google-gemini",
|
|
31
|
+
providerKeyName: "GEMINI_API_KEY",
|
|
30
32
|
ai: {
|
|
31
|
-
model: "
|
|
33
|
+
model: "gemini-2.5-flash-lite",
|
|
32
34
|
maxTokens: 1000,
|
|
33
35
|
temperature: 0,
|
|
34
36
|
},
|
package/examples/streaming.ts
CHANGED
|
@@ -15,7 +15,7 @@ const config: AxCrewConfig = {
|
|
|
15
15
|
provider: "google-gemini",
|
|
16
16
|
providerKeyName: "GEMINI_API_KEY",
|
|
17
17
|
ai: {
|
|
18
|
-
model: "gemini-2.
|
|
18
|
+
model: "gemini-2.5-flash",
|
|
19
19
|
maxTokens: 1000,
|
|
20
20
|
temperature: 0,
|
|
21
21
|
},
|
|
@@ -33,7 +33,7 @@ const config: AxCrewConfig = {
|
|
|
33
33
|
provider: "google-gemini",
|
|
34
34
|
providerKeyName: "GEMINI_API_KEY",
|
|
35
35
|
ai: {
|
|
36
|
-
model: "gemini-
|
|
36
|
+
model: "gemini-2.5-pro",
|
|
37
37
|
temperature: 0,
|
|
38
38
|
},
|
|
39
39
|
options: {
|