@amitdeshmukh/ax-crew 5.0.0 → 7.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/.claude/settings.local.json +7 -0
- package/CHANGELOG.md +40 -0
- package/README.md +143 -59
- package/dist/agents/agentConfig.d.ts +6 -6
- package/dist/agents/agentConfig.js +46 -124
- package/dist/agents/compose.d.ts +15 -0
- package/dist/agents/compose.js +58 -0
- package/dist/agents/index.d.ts +22 -4
- package/dist/agents/index.js +24 -5
- 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/types.d.ts +53 -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 +2 -1
- package/examples/search-tweets.ts +5 -4
- package/examples/solve-math-problem.ts +7 -5
- package/examples/streaming.ts +2 -2
- package/examples/telemetry-demo.ts +166 -0
- package/package.json +5 -4
- package/src/agents/agentConfig.ts +53 -142
- package/src/agents/compose.ts +80 -0
- package/src/agents/index.ts +30 -8
- package/src/functions/index.ts +11 -1
- package/src/index.ts +25 -11
- package/src/types.ts +59 -21
- package/tests/telemetry.test.ts +81 -0
- package/dist/config/index.d.ts +0 -5
- package/dist/config/index.js +0 -30
- package/src/config/index.ts +0 -40
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
|
|
|
5
5
|
import type {
|
|
6
6
|
UsageCost,
|
|
@@ -9,28 +9,42 @@ import type {
|
|
|
9
9
|
StateInstance,
|
|
10
10
|
FunctionRegistryType
|
|
11
11
|
} from './types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Metrics types and helpers for request counts, token usage, and estimated cost.
|
|
14
|
+
*
|
|
15
|
+
* Re-exports the metrics module for convenience:
|
|
16
|
+
* - Types: TokenUsage, MetricsSnapshot, etc.
|
|
17
|
+
* - Namespace: MetricsRegistry (record/snapshot/reset helpers)
|
|
18
|
+
*/
|
|
12
19
|
export * from './metrics/index.js';
|
|
20
|
+
/**
|
|
21
|
+
* MetricsRegistry provides functions to record requests, tokens, and cost,
|
|
22
|
+
* and to snapshot/reset metrics at agent or crew granularity.
|
|
23
|
+
*/
|
|
13
24
|
export { MetricsRegistry } from './metrics/index.js';
|
|
14
25
|
|
|
15
|
-
// Main AxCrew configuration interface
|
|
16
26
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
27
|
+
* Create and manage a crew of Ax agents that share state and metrics.
|
|
28
|
+
* See the `AxCrew` class for full documentation.
|
|
29
|
+
*/
|
|
30
|
+
const _AxCrew: typeof AxCrew = AxCrew;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Built-in function registry with common tools that can be referenced by name
|
|
34
|
+
* from agent configs, or extended with your own functions.
|
|
20
35
|
*/
|
|
21
|
-
|
|
22
|
-
crew: AgentConfig[];
|
|
23
|
-
}
|
|
36
|
+
const _AxCrewFunctions: typeof AxCrewFunctions = AxCrewFunctions;
|
|
24
37
|
|
|
25
38
|
export {
|
|
26
|
-
AxCrew
|
|
27
|
-
|
|
39
|
+
/** See class JSDoc on the `AxCrew` implementation. */
|
|
40
|
+
_AxCrew as AxCrew,
|
|
41
|
+
/** Built-in function registry; see file docs in `src/functions/index.ts`. */
|
|
42
|
+
_AxCrewFunctions as AxCrewFunctions,
|
|
28
43
|
FunctionRegistryType,
|
|
29
44
|
// Type exports
|
|
30
45
|
type AggregatedMetrics,
|
|
31
46
|
type AggregatedCosts,
|
|
32
47
|
type AgentConfig,
|
|
33
|
-
type CrewConfigInput,
|
|
34
48
|
type AxCrewConfig,
|
|
35
49
|
type StateInstance,
|
|
36
50
|
type UsageCost,
|
package/src/types.ts
CHANGED
|
@@ -3,26 +3,13 @@ import type {
|
|
|
3
3
|
AxSignature,
|
|
4
4
|
AxModelConfig,
|
|
5
5
|
AxMCPStreamableHTTPTransportOptions,
|
|
6
|
-
AxProgramForwardOptions
|
|
6
|
+
AxProgramForwardOptions,
|
|
7
|
+
AxAIArgs
|
|
7
8
|
} from '@ax-llm/ax';
|
|
8
9
|
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
| 'openai'
|
|
13
|
-
| 'anthropic'
|
|
14
|
-
| 'google-gemini'
|
|
15
|
-
| 'mistral'
|
|
16
|
-
| 'groq'
|
|
17
|
-
| 'cohere'
|
|
18
|
-
| 'together'
|
|
19
|
-
| 'deepseek'
|
|
20
|
-
| 'ollama'
|
|
21
|
-
| 'huggingface'
|
|
22
|
-
| 'openrouter'
|
|
23
|
-
| 'azure-openai'
|
|
24
|
-
| 'reka'
|
|
25
|
-
| 'x-grok'
|
|
10
|
+
// Provider ids are derived from Ax's factory arg type so new providers added in Ax
|
|
11
|
+
// are picked up at compile time without updating AxCrew.
|
|
12
|
+
export type Provider = AxAIArgs<any>['name'];
|
|
26
13
|
|
|
27
14
|
/**
|
|
28
15
|
* A state instance that is shared between agents.
|
|
@@ -209,13 +196,64 @@ interface AgentConfig {
|
|
|
209
196
|
}
|
|
210
197
|
|
|
211
198
|
/**
|
|
212
|
-
* The
|
|
199
|
+
* The configuration object for an AxCrew instance.
|
|
200
|
+
*
|
|
201
|
+
* @property {AgentConfig[]} crew - The agents that make up the crew.
|
|
202
|
+
* @example
|
|
203
|
+
* const config: AxCrewConfig = {
|
|
204
|
+
* crew: [
|
|
205
|
+
* {
|
|
206
|
+
* name: "Agent1",
|
|
207
|
+
* description: "Agent 1 description",
|
|
208
|
+
* signature: "signature",
|
|
209
|
+
* provider: "provider",
|
|
210
|
+
* providerKeyName: "providerKeyName",
|
|
211
|
+
* ai: {
|
|
212
|
+
* model: "model",
|
|
213
|
+
* temperature: 0,
|
|
214
|
+
* },
|
|
215
|
+
* options: {
|
|
216
|
+
* debug: true,
|
|
217
|
+
* },
|
|
218
|
+
* functions: ["function1", "function2"],
|
|
219
|
+
* agents: ["agent2"],
|
|
220
|
+
* },
|
|
221
|
+
* {
|
|
222
|
+
* name: "Agent2",
|
|
223
|
+
* description: "Agent 2 description",
|
|
224
|
+
* signature: "signature",
|
|
225
|
+
* provider: "provider",
|
|
226
|
+
* providerKeyName: "providerKeyName",
|
|
227
|
+
* ai: {
|
|
228
|
+
* model: "model",
|
|
229
|
+
* temperature: 0,
|
|
230
|
+
* }
|
|
231
|
+
* ]
|
|
232
|
+
* }
|
|
233
|
+
* const crew = new AxCrew(config);
|
|
213
234
|
*/
|
|
214
|
-
|
|
235
|
+
interface AxCrewConfig {
|
|
236
|
+
crew: AgentConfig[]
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Options for the AxCrew instance, specifically allowing optional OpenTelemetry injection.
|
|
241
|
+
*
|
|
242
|
+
* @property {Object} [telemetry] - Telemetry configuration.
|
|
243
|
+
* @property {any} [telemetry.tracer] - OpenTelemetry Tracer instance.
|
|
244
|
+
* @property {any} [telemetry.meter] - OpenTelemetry Meter instance.
|
|
245
|
+
*/
|
|
246
|
+
interface AxCrewOptions {
|
|
247
|
+
telemetry?: {
|
|
248
|
+
tracer?: any;
|
|
249
|
+
meter?: any;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
215
252
|
|
|
216
253
|
export {
|
|
217
254
|
type AgentConfig,
|
|
218
|
-
type
|
|
255
|
+
type AxCrewConfig,
|
|
256
|
+
type AxCrewOptions,
|
|
219
257
|
type AggregatedMetrics,
|
|
220
258
|
type StateInstance,
|
|
221
259
|
type FunctionRegistryType,
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
|
|
2
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
+
import { AxCrew } from '../src/index.js';
|
|
4
|
+
import type { AxCrewConfig } from '../src/types.js';
|
|
5
|
+
import * as axModule from '@ax-llm/ax';
|
|
6
|
+
|
|
7
|
+
// Mock the entire @ax-llm/ax module
|
|
8
|
+
vi.mock('@ax-llm/ax', async (importOriginal) => {
|
|
9
|
+
const actual = await importOriginal() as typeof axModule;
|
|
10
|
+
return {
|
|
11
|
+
...actual,
|
|
12
|
+
// Spy on the ai factory function
|
|
13
|
+
ai: vi.fn().mockImplementation((args) => {
|
|
14
|
+
// Return a dummy object that mimics enough of AxAI to satisfy AxCrew
|
|
15
|
+
return {
|
|
16
|
+
getName: () => args.name,
|
|
17
|
+
chat: vi.fn(),
|
|
18
|
+
defaults: { model: args.config?.model },
|
|
19
|
+
options: args.options // Store options so we can potentially inspect if needed, though we rely on the spy
|
|
20
|
+
};
|
|
21
|
+
}),
|
|
22
|
+
// We need to keep other exports working if they are used
|
|
23
|
+
AxAgent: actual.AxAgent,
|
|
24
|
+
AxAI: actual.AxAI,
|
|
25
|
+
AxDefaultCostTracker: actual.AxDefaultCostTracker
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('AxCrew Telemetry', () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
vi.clearAllMocks();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should pass telemetry options to the underlying AxAI factory', async () => {
|
|
35
|
+
const mockTracer = { isMockTracer: true };
|
|
36
|
+
const mockMeter = { isMockMeter: true };
|
|
37
|
+
|
|
38
|
+
const crewConfig: AxCrewConfig = {
|
|
39
|
+
crew: [
|
|
40
|
+
{
|
|
41
|
+
name: "telemetry-agent",
|
|
42
|
+
description: "An agent for testing telemetry propagation",
|
|
43
|
+
signature: "in:string -> out:string",
|
|
44
|
+
provider: "openai",
|
|
45
|
+
providerKeyName: "OPENAI_API_KEY",
|
|
46
|
+
ai: { model: "gpt-4o-mini" }
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Set dummy key
|
|
52
|
+
process.env.OPENAI_API_KEY = 'dummy-key';
|
|
53
|
+
|
|
54
|
+
const options = {
|
|
55
|
+
telemetry: {
|
|
56
|
+
tracer: mockTracer,
|
|
57
|
+
meter: mockMeter
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Initialize Crew with telemetry options (3rd argument now)
|
|
62
|
+
const crew = new AxCrew(crewConfig, {}, options as any);
|
|
63
|
+
|
|
64
|
+
// Create the agent
|
|
65
|
+
await crew.addAgent("telemetry-agent");
|
|
66
|
+
|
|
67
|
+
// Check if the 'ai' mock was called with the expected arguments
|
|
68
|
+
expect(axModule.ai).toHaveBeenCalled();
|
|
69
|
+
|
|
70
|
+
// Get the arguments of the first call to ai()
|
|
71
|
+
const callArgs = vi.mocked(axModule.ai).mock.calls[0][0];
|
|
72
|
+
|
|
73
|
+
// Verify the structure
|
|
74
|
+
expect(callArgs).toBeDefined();
|
|
75
|
+
expect(callArgs.options).toBeDefined();
|
|
76
|
+
|
|
77
|
+
// Assert tracer and meter were passed correctly
|
|
78
|
+
expect(callArgs.options.tracer).toBe(mockTracer);
|
|
79
|
+
expect(callArgs.options.meter).toBe(mockMeter);
|
|
80
|
+
});
|
|
81
|
+
});
|
package/dist/config/index.d.ts
DELETED
package/dist/config/index.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
|
-
dotenv.config();
|
|
3
|
-
// AI API keys
|
|
4
|
-
const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
|
|
5
|
-
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
|
6
|
-
const AZURE_OPENAI_API_KEY = process.env.AZURE_OPENAI_API_KEY;
|
|
7
|
-
const COHERE_API_KEY = process.env.COHERE_API_KEY;
|
|
8
|
-
const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
|
|
9
|
-
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
|
|
10
|
-
const GROQ_API_KEY = process.env.GROQ_API_KEY;
|
|
11
|
-
const TOGETHER_API_KEY = process.env.TOGETHER_API_KEY;
|
|
12
|
-
const MISTRAL_API_KEY = process.env.MISTRAL_API_KEY;
|
|
13
|
-
const HUGGINGFACE_API_KEY = process.env.HUGGINGFACE_API_KEY;
|
|
14
|
-
const REKA_API_KEY = process.env.REKA_API_KEY;
|
|
15
|
-
const GROK_API_KEY = process.env.GROK_API_KEY;
|
|
16
|
-
const PROVIDER_API_KEYS = {
|
|
17
|
-
COHERE_API_KEY,
|
|
18
|
-
GEMINI_API_KEY,
|
|
19
|
-
OPENAI_API_KEY,
|
|
20
|
-
AZURE_OPENAI_API_KEY,
|
|
21
|
-
ANTHROPIC_API_KEY,
|
|
22
|
-
DEEPSEEK_API_KEY,
|
|
23
|
-
GROQ_API_KEY,
|
|
24
|
-
TOGETHER_API_KEY,
|
|
25
|
-
MISTRAL_API_KEY,
|
|
26
|
-
HUGGINGFACE_API_KEY,
|
|
27
|
-
REKA_API_KEY,
|
|
28
|
-
GROK_API_KEY
|
|
29
|
-
};
|
|
30
|
-
export { PROVIDER_API_KEYS, };
|
package/src/config/index.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
|
-
dotenv.config();
|
|
3
|
-
|
|
4
|
-
// AI API keys
|
|
5
|
-
const ANTHROPIC_API_KEY: string | undefined = process.env.ANTHROPIC_API_KEY;
|
|
6
|
-
const OPENAI_API_KEY: string | undefined = process.env.OPENAI_API_KEY;
|
|
7
|
-
const AZURE_OPENAI_API_KEY: string | undefined = process.env.AZURE_OPENAI_API_KEY;
|
|
8
|
-
const COHERE_API_KEY: string | undefined = process.env.COHERE_API_KEY;
|
|
9
|
-
const DEEPSEEK_API_KEY: string | undefined = process.env.DEEPSEEK_API_KEY;
|
|
10
|
-
const GEMINI_API_KEY: string | undefined = process.env.GEMINI_API_KEY;
|
|
11
|
-
const GROQ_API_KEY: string | undefined = process.env.GROQ_API_KEY;
|
|
12
|
-
const TOGETHER_API_KEY: string | undefined = process.env.TOGETHER_API_KEY;
|
|
13
|
-
const MISTRAL_API_KEY: string | undefined = process.env.MISTRAL_API_KEY;
|
|
14
|
-
const HUGGINGFACE_API_KEY: string | undefined = process.env.HUGGINGFACE_API_KEY;
|
|
15
|
-
const REKA_API_KEY: string | undefined = process.env.REKA_API_KEY;
|
|
16
|
-
const GROK_API_KEY: string | undefined = process.env.GROK_API_KEY;
|
|
17
|
-
// Note: Ollama typically doesn't require an API key for local usage
|
|
18
|
-
|
|
19
|
-
interface ProviderApiKeys {
|
|
20
|
-
[key: string]: string | undefined;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const PROVIDER_API_KEYS: ProviderApiKeys = {
|
|
24
|
-
COHERE_API_KEY,
|
|
25
|
-
GEMINI_API_KEY,
|
|
26
|
-
OPENAI_API_KEY,
|
|
27
|
-
AZURE_OPENAI_API_KEY,
|
|
28
|
-
ANTHROPIC_API_KEY,
|
|
29
|
-
DEEPSEEK_API_KEY,
|
|
30
|
-
GROQ_API_KEY,
|
|
31
|
-
TOGETHER_API_KEY,
|
|
32
|
-
MISTRAL_API_KEY,
|
|
33
|
-
HUGGINGFACE_API_KEY,
|
|
34
|
-
REKA_API_KEY,
|
|
35
|
-
GROK_API_KEY
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export {
|
|
39
|
-
PROVIDER_API_KEYS,
|
|
40
|
-
};
|