@amitdeshmukh/ax-crew 3.3.2 → 3.3.4

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 CHANGED
@@ -5,6 +5,24 @@ This Changelog format is based on [Keep a Changelog]
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/
6
6
  v2.0.0.html).
7
7
 
8
+ ## [3.3.4] - 2024-12-31
9
+
10
+ ### Removed
11
+ - Removed unused `js-yaml` dependency
12
+ - Updated `README.md` to highlight AxLLM 10.0.9 as peer dependency
13
+
14
+ ## [3.3.3] - 2024-12-12
15
+
16
+ ### Added
17
+ - TypeScript declaration file (`index.d.ts`)
18
+ - Improved type definitions for:
19
+ - `AxCrew` class and its methods
20
+ - `StatefulAxAgent` class
21
+ - State management interfaces
22
+ - Function registry types
23
+ - Configuration types
24
+ - TypeScript documentation in `README.md` with example
25
+
8
26
  ## [3.3.1] - 2024-12-11
9
27
 
10
28
  ### Changed
package/README.md CHANGED
@@ -16,12 +16,94 @@ Install this package:
16
16
  ```bash
17
17
  npm install @amitdeshmukh/ax-crew
18
18
  ```
19
- AxLLM is a peer dependency, so you will need to install it separately.
19
+ AxLLM is a peer dependency, so you will need to install it separately.
20
+
21
+ **Note:** Currently, we support AxLLM v10.0.9. We are working on updating this package to support the latest version of AxLLM as it introduces some breaking changes.
20
22
 
21
23
  ```bash
22
- npm install @ax-llm/ax@latest
24
+ npm install @ax-llm/ax@10.0.9
23
25
  ```
24
26
 
27
+ ### TypeScript Support
28
+ This package includes TypeScript declarations and provides full type safety. Here's how to use it with TypeScript:
29
+
30
+ ```typescript
31
+ import { AxCrew, AxCrewFunctions, FunctionRegistryType, StateInstance } from '@amitdeshmukh/ax-crew';
32
+ import type { AxFunction } from '@ax-llm/ax';
33
+
34
+ // Type-safe configuration
35
+ const config = {
36
+ crew: [{
37
+ name: "Planner",
38
+ description: "Creates a plan to complete a task",
39
+ signature: "task:string \"a task to be completed\" -> plan:string \"a plan to execute the task\"",
40
+ provider: "google-gemini",
41
+ providerKeyName: "GEMINI_API_KEY",
42
+ ai: {
43
+ model: "gemini-1.5-pro",
44
+ temperature: 0
45
+ }
46
+ }]
47
+ };
48
+
49
+ // Create custom functions with type safety
50
+ class MyCustomFunction {
51
+ constructor(private state: Record<string, any>) {}
52
+
53
+ toFunction(): AxFunction {
54
+ return {
55
+ name: 'MyCustomFunction',
56
+ description: 'Does something useful',
57
+ parameters: {
58
+ type: 'object',
59
+ properties: {
60
+ inputParam: { type: 'string', description: "input to the function" }
61
+ }
62
+ },
63
+ func: async ({ inputParam }) => {
64
+ // Implementation
65
+ return inputParam;
66
+ }
67
+ };
68
+ }
69
+ }
70
+
71
+ // Type-safe function registry
72
+ const myFunctions: FunctionRegistryType = {
73
+ MyCustomFunction
74
+ };
75
+
76
+ // Create crew with type checking
77
+ const crew = new AxCrew(config, myFunctions);
78
+
79
+ // Type-safe state management
80
+ crew.state.set('key', 'value');
81
+ const value: string = crew.state.get('key');
82
+
83
+ // Type-safe agent management
84
+ const agents = crew.addAgentsToCrew(['Planner']);
85
+ const planner = agents?.get('Planner');
86
+
87
+ if (planner) {
88
+ // Type-safe agent usage
89
+ const response = await planner.forward({ task: "Plan something" });
90
+ const cost = planner.getUsageCost();
91
+
92
+ if (cost) {
93
+ console.log(`Total cost: $${cost.totalCost}`);
94
+ console.log(`Total tokens: ${cost.tokenMetrics.totalTokens}`);
95
+ }
96
+ }
97
+ ```
98
+
99
+ Key TypeScript features:
100
+ - Full type definitions for all classes, methods, and properties
101
+ - Type-safe configuration objects
102
+ - Proper typing for function registries and custom functions
103
+ - Type checking for state management
104
+ - Comprehensive type safety for agent operations and responses
105
+ - Usage cost tracking with proper types
106
+
25
107
  ### Environment Setup
26
108
  Refer to the [.env.example](.env.example) file for the required environment variables. These will need to be set in the environment where the agents are run.
27
109
 
package/axllm.js CHANGED
@@ -10,7 +10,7 @@ const googleAI = new AxAI({
10
10
  temperature: 0,
11
11
  },
12
12
  options: {
13
- debug: true,
13
+ debug: false,
14
14
  codeExecution: true,
15
15
  },
16
16
  });
@@ -19,20 +19,22 @@ const openAI = new AxAI({
19
19
  name: "openai",
20
20
  apiKey: process.env.OPENAI_API_KEY,
21
21
  config: {
22
- model: "gpt-4-turbo",
22
+ model: "gpt-4o-mini",
23
23
  maxTokens: 1000,
24
24
  temperature: 0,
25
25
  },
26
- options: { debug: true },
26
+ options: { debug: false },
27
27
  });
28
28
 
29
29
  const MathAgent = new AxAgent({
30
+ ai: googleAI,
30
31
  name: "MathAgent",
31
32
  description: "Solves math problems",
32
- signature: `mathProblem:string "a sentence describing a math problem to be solved using Python code" -> solution:string "a precise answer to the math problem"`,
33
+ signature: `mathProblem:string "a sentence describing a math problem to be solved using Python code" -> solution:string "the answer to the math problem"`
33
34
  });
34
35
 
35
36
  const ManagerAgent = new AxAgent({
37
+ ai: openAI,
36
38
  name: "ManagerAgent",
37
39
  description: "Completes a user specified task.",
38
40
  signature: `question:string "a question to be answered" -> answer:string "the answer to the question"`,
@@ -50,7 +52,7 @@ const managerAgentResponse = await ManagerAgent.forward(
50
52
  }
51
53
  );
52
54
 
53
- console.log(`\nManagerAgentResponse: ${JSON.stringify(managerAgentResponse, null, 2)}\n`);
55
+ console.log(`\nAnswer: ${JSON.stringify(managerAgentResponse.answer, null, 2)}\n`);
54
56
 
55
57
  console.log("❌ This is the wrong answer ☝️");
56
58
 
@@ -61,6 +63,6 @@ const MathAgentResponse = await MathAgent.forward(
61
63
  }
62
64
  );
63
65
 
64
- console.log(`\nMathAgentResponse: ${JSON.stringify(MathAgentResponse, null, 2)}\n`);
66
+ console.log(`\nAnswer: ${JSON.stringify(MathAgentResponse.solution, null, 2)}\n`);
65
67
  console.log(" ✅ Correct answer ☝️");
66
68
 
@@ -1,15 +1,14 @@
1
1
  import type { AxModelConfig, AxFunction, AxSignature } from '@ax-llm/ax';
2
2
  import { FunctionRegistryType } from '../functions/index.js';
3
- type ExtendedAxModelConfig = AxModelConfig & {
4
- model: string;
5
- };
6
- interface AgentConfig {
3
+ export interface AgentConfig {
7
4
  name: string;
8
5
  description: string;
9
- signature: AxSignature;
6
+ signature: string | AxSignature;
10
7
  provider: string;
11
8
  providerKeyName?: string;
12
- ai: ExtendedAxModelConfig;
9
+ ai: AxModelConfig & {
10
+ model: string;
11
+ };
13
12
  debug?: boolean;
14
13
  apiURL?: string;
15
14
  options?: Record<string, any>;
@@ -37,7 +36,7 @@ declare const getAgentConfigParams: (agentName: string, agentConfig: AgentConfig
37
36
  ai: any;
38
37
  name: string;
39
38
  description: string;
40
- signature: AxSignature;
39
+ signature: string | AxSignature;
41
40
  functions: (AxFunction | (new (state: Record<string, any>) => {
42
41
  toFunction: () => AxFunction;
43
42
  }) | undefined)[];
@@ -16,7 +16,7 @@ class StatefulAxAgent extends AxAgent {
16
16
  this.axai = ai;
17
17
  // Set examples if provided
18
18
  if (examples && examples.length > 0) {
19
- this.setExamples(examples);
19
+ super.setExamples(examples);
20
20
  }
21
21
  }
22
22
  // Override the forward method
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  import { AxCrew } from './agents/index.js';
2
2
  import { AxCrewFunctions, FunctionRegistryType } from './functions/index.js';
3
- export { AxCrew, AxCrewFunctions, FunctionRegistryType };
3
+ import type { UsageCost } from './agents/agentUseCosts.js';
4
+ import type { AgentConfig, AgentConfigInput } from './agents/agentConfig.js';
5
+ import type { StateInstance } from './state/index.js';
6
+ export { AxCrew, AxCrewFunctions, FunctionRegistryType, type UsageCost, type AgentConfig, type AgentConfigInput, type StateInstance };
@@ -1,12 +1,10 @@
1
- interface StateInstance {
2
- set: (key: string, value: any) => void;
3
- get: (key: string) => any;
4
- getAll: () => {
5
- [key: string]: any;
6
- };
7
- getId: () => string;
8
- reset: () => void;
1
+ export interface StateInstance {
2
+ reset(): void;
3
+ set(key: string, value: any): void;
4
+ get(key: string): any;
5
+ getAll(): Record<string, any>;
6
+ [key: string]: any;
9
7
  }
10
- declare const createState: (id: string) => StateInstance;
11
- declare const getState: (id: string) => StateInstance | undefined;
12
- export { createState, getState, StateInstance };
8
+ declare function createState(id: string): StateInstance;
9
+ declare function getState(id: string): StateInstance | undefined;
10
+ export { createState, getState };
@@ -1,32 +1,27 @@
1
1
  const stateInstances = {};
2
- const createState = (id) => {
3
- if (!id) {
4
- throw new Error('An ID is required to create a new state instance.');
5
- }
2
+ function createState(id) {
6
3
  if (stateInstances[id]) {
7
4
  return stateInstances[id];
8
5
  }
9
- let data = {};
10
- stateInstances[id] = {
11
- set: (key, value) => {
12
- data[key] = value;
13
- },
14
- get: (key) => {
15
- return data[key];
6
+ let state = {};
7
+ const instance = {
8
+ reset() {
9
+ state = {};
16
10
  },
17
- getAll: () => {
18
- return data;
11
+ set(key, value) {
12
+ state[key] = value;
19
13
  },
20
- getId: () => {
21
- return id;
14
+ get(key) {
15
+ return state[key];
22
16
  },
23
- reset: () => {
24
- data = {};
17
+ getAll() {
18
+ return { ...state };
25
19
  }
26
20
  };
21
+ stateInstances[id] = instance;
22
+ return instance;
23
+ }
24
+ function getState(id) {
27
25
  return stateInstances[id];
28
- };
29
- const getState = (id) => {
30
- return stateInstances[id];
31
- };
26
+ }
32
27
  export { createState, getState };
package/index.d.ts CHANGED
@@ -1,7 +1,92 @@
1
+ import { AxAI, AxAgentic, AxFunction, AxSignature, AxProgramForwardOptions, AxModelConfig, AxAgent } from "@ax-llm/ax";
2
+
3
+ export interface UsageCost {
4
+ promptCost: number;
5
+ completionCost: number;
6
+ totalCost: number;
7
+ tokenMetrics: {
8
+ promptTokens: number;
9
+ completionTokens: number;
10
+ totalTokens: number;
11
+ };
12
+ }
13
+
14
+ export interface StateInstance {
15
+ reset(): void;
16
+ set(key: string, value: any): void;
17
+ get(key: string): any;
18
+ getAll(): Record<string, any>;
19
+ [key: string]: any;
20
+ }
21
+
22
+ export type FunctionRegistryType = {
23
+ [key: string]: AxFunction | { new(state: Record<string, any>): { toFunction: () => AxFunction } };
24
+ };
25
+
26
+ export interface AgentConfig {
27
+ name: string;
28
+ description: string;
29
+ signature: AxSignature;
30
+ provider: string;
31
+ providerKeyName?: string;
32
+ ai: AxModelConfig & { model: string };
33
+ debug?: boolean;
34
+ apiURL?: string;
35
+ options?: Record<string, any>;
36
+ functions?: string[];
37
+ agents?: string[];
38
+ examples?: Array<Record<string, any>>;
39
+ }
40
+
41
+ export type AgentConfigInput = string | { crew: AgentConfig[] };
42
+
43
+ export class StatefulAxAgent extends AxAgent<Record<string, any>, Record<string, any>> {
44
+ state: StateInstance;
45
+ axai: AxAI;
46
+
47
+ constructor(
48
+ ai: AxAI,
49
+ options: Readonly<{
50
+ name: string;
51
+ description: string;
52
+ signature: string | AxSignature;
53
+ agents?: AxAgentic[] | undefined;
54
+ functions?: (AxFunction | (() => AxFunction))[] | undefined;
55
+ examples?: Array<Record<string, any>> | undefined;
56
+ }>,
57
+ state: StateInstance
58
+ );
59
+
60
+ forward(
61
+ input: Record<string, any>,
62
+ options?: Readonly<AxProgramForwardOptions>
63
+ ): Promise<Record<string, any>>;
64
+
65
+ getUsageCost(): UsageCost | null;
66
+
67
+ setExamples(examples: Array<Record<string, any>>): void;
68
+ }
69
+
1
70
  export class AxCrew {
2
- constructor(configPath: string);
3
- addAgent(agent: any): void;
4
- createAgent(agent: any): void;
5
- addAgentsToCrew(agents: any[]): void;
71
+ private agentConfig: AgentConfigInput;
72
+ functionsRegistry: FunctionRegistryType;
73
+ crewId: string;
74
+ agents: Map<string, StatefulAxAgent> | null;
75
+ state: StateInstance;
76
+
77
+ constructor(
78
+ agentConfig: AgentConfigInput,
79
+ functionsRegistry?: FunctionRegistryType,
80
+ crewId?: string
81
+ );
82
+
83
+ createAgent(agentName: string): StatefulAxAgent;
84
+ addAgent(agentName: string): void;
85
+ addAgentsToCrew(agentNames: string[]): Map<string, StatefulAxAgent> | null;
6
86
  destroy(): void;
7
87
  }
88
+
89
+ export const AxCrewFunctions: {
90
+ CurrentDateTime: { new(state: Record<string, any>): { toFunction: () => AxFunction } };
91
+ DaysBetweenDates: { new(state: Record<string, any>): { toFunction: () => AxFunction } };
92
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@amitdeshmukh/ax-crew",
4
- "version": "3.3.2",
4
+ "version": "3.3.4",
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",
@@ -14,15 +14,13 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "dotenv": "^16.4.5",
17
- "js-yaml": "^4.1.0",
18
17
  "upgrade": "^1.1.0",
19
18
  "uuid": "^10.0.0"
20
19
  },
21
20
  "peerDependencies": {
22
- "@ax-llm/ax": "^10.0.9"
21
+ "@ax-llm/ax": "10.0.9"
23
22
  },
24
23
  "devDependencies": {
25
- "@types/js-yaml": "^4.0.9",
26
24
  "@types/node": "^20.14.9",
27
25
  "@types/uuid": "^10.0.0",
28
26
  "typescript": "^5.5.3"
@@ -20,17 +20,15 @@ const AIConstructors: Record<string, any> = {
20
20
  'together': AxAITogether
21
21
  };
22
22
 
23
- type ExtendedAxModelConfig = AxModelConfig & {
24
- model: string;
25
- };
26
23
 
27
- interface AgentConfig {
24
+
25
+ export interface AgentConfig {
28
26
  name: string;
29
27
  description: string;
30
- signature: AxSignature;
28
+ signature: string | AxSignature;
31
29
  provider: string;
32
30
  providerKeyName?: string;
33
- ai: ExtendedAxModelConfig;
31
+ ai: AxModelConfig & { model: string };
34
32
  debug?: boolean;
35
33
  apiURL?: string;
36
34
  options?: Record<string, any>;
@@ -17,7 +17,7 @@ interface AgentConfigParams {
17
17
  ai: AxAI;
18
18
  name: string;
19
19
  description: string;
20
- signature: AxSignature;
20
+ signature: string | AxSignature;
21
21
  functions: (
22
22
  | AxFunction
23
23
  | (new (state: Record<string, any>) => { toFunction: () => AxFunction })
@@ -57,7 +57,7 @@ class StatefulAxAgent extends AxAgent<any, any> {
57
57
 
58
58
  // Set examples if provided
59
59
  if (examples && examples.length > 0) {
60
- this.setExamples(examples);
60
+ super.setExamples(examples);
61
61
  }
62
62
  }
63
63
 
package/src/index.ts CHANGED
@@ -1,8 +1,16 @@
1
1
  import { AxCrew } from './agents/index.js';
2
2
  import { AxCrewFunctions, FunctionRegistryType } from './functions/index.js';
3
+ import type { UsageCost } from './agents/agentUseCosts.js';
4
+ import type { AgentConfig, AgentConfigInput } from './agents/agentConfig.js';
5
+ import type { StateInstance } from './state/index.js';
3
6
 
4
7
  export {
5
8
  AxCrew,
6
9
  AxCrewFunctions,
7
- FunctionRegistryType
10
+ FunctionRegistryType,
11
+ // Type exports
12
+ type UsageCost,
13
+ type AgentConfig,
14
+ type AgentConfigInput,
15
+ type StateInstance
8
16
  };
@@ -1,46 +1,41 @@
1
- interface StateInstance {
2
- set: (key: string, value: any) => void;
3
- get: (key: string) => any;
4
- getAll: () => { [key: string]: any };
5
- getId: () => string;
6
- reset: () => void;
1
+ export interface StateInstance {
2
+ reset(): void;
3
+ set(key: string, value: any): void;
4
+ get(key: string): any;
5
+ getAll(): Record<string, any>;
6
+ [key: string]: any;
7
7
  }
8
8
 
9
9
  const stateInstances: { [id: string]: StateInstance } = {};
10
10
 
11
- const createState = (id: string): StateInstance => {
12
- if (!id) {
13
- throw new Error('An ID is required to create a new state instance.');
14
- }
11
+ function createState(id: string): StateInstance {
15
12
  if (stateInstances[id]) {
16
13
  return stateInstances[id];
17
14
  }
18
15
 
19
- let data: { [key: string]: any } = {};
20
-
21
- stateInstances[id] = {
22
- set: (key, value) => {
23
- data[key] = value;
24
- },
25
- get: (key) => {
26
- return data[key];
16
+ let state: Record<string, any> = {};
17
+
18
+ const instance: StateInstance = {
19
+ reset() {
20
+ state = {};
27
21
  },
28
- getAll: () => {
29
- return data;
22
+ set(key: string, value: any) {
23
+ state[key] = value;
30
24
  },
31
- getId: () => {
32
- return id;
25
+ get(key: string) {
26
+ return state[key];
33
27
  },
34
- reset: () => {
35
- data = {};
28
+ getAll() {
29
+ return { ...state };
36
30
  }
37
31
  };
38
32
 
39
- return stateInstances[id];
40
- };
33
+ stateInstances[id] = instance;
34
+ return instance;
35
+ }
41
36
 
42
- const getState = (id: string): StateInstance | undefined => {
37
+ function getState(id: string): StateInstance | undefined {
43
38
  return stateInstances[id];
44
39
  }
45
40
 
46
- export { createState, getState, StateInstance };
41
+ export { createState, getState };
package/test1.js CHANGED
@@ -3,15 +3,29 @@ import { AxCrew, AxCrewFunctions } from "./dist/index.js";
3
3
  // Define the configuration object directly
4
4
  const config = {
5
5
  crew: [
6
+ // {
7
+ // name: "Planner",
8
+ // description: "Creates a plan to complete a task",
9
+ // signature:
10
+ // 'task:string "a task to be completed" -> plan:string "a plan to execute the task in 5 steps or less"',
11
+ // provider: "google-gemini",
12
+ // providerKeyName: "GEMINI_API_KEY",
13
+ // ai: {
14
+ // model: "gemini-1.5-flash",
15
+ // temperature: 0,
16
+ // },
17
+ // options: {
18
+ // debug: false,
19
+ // },
20
+ // },
6
21
  {
7
- name: "Planner",
8
- description: "Creates a plan to complete a task",
9
- signature:
10
- 'task:string "a task to be completed" -> plan:string "a plan to execute the task in 5 steps or less"',
11
- provider: "google-gemini",
12
- providerKeyName: "GEMINI_API_KEY",
22
+ name: "Summarizer",
23
+ description: "Summarizes long form text into a short summary",
24
+ signature: "inputText:string -> summary:string",
25
+ provider: "openai",
26
+ providerKeyName: "OPENAI_API_KEY",
13
27
  ai: {
14
- model: "gemini-1.5-flash",
28
+ model: "gpt-4o-mini",
15
29
  temperature: 0,
16
30
  },
17
31
  options: {
@@ -19,28 +33,9 @@ const config = {
19
33
  },
20
34
  },
21
35
  {
22
- name: "Calculator",
36
+ name: "MathAgent",
23
37
  description: "Solves math problems",
24
- signature:
25
- 'mathProblem:string "a math problem to be solved using Python code" -> solution:string "the solution to the math problem"',
26
- provider: "google-gemini",
27
- providerKeyName: "GEMINI_API_KEY",
28
- ai: {
29
- model: "gemini-1.5-pro",
30
- temperature: 0,
31
- },
32
- options: {
33
- debug: true,
34
- codeExecution: true,
35
- },
36
- functions: ["CurrentDateTime", "DaysBetweenDates"],
37
- },
38
- {
39
- name: "WebSearch",
40
- description:
41
- "Searches the web for the latest information using Google search",
42
- signature:
43
- 'webSearchQuery:string "a query for Google search" -> webSearchResponse:string "the result of the search"',
38
+ signature: `mathProblem:string "a sentence describing a math problem to be solved using Python code" -> solution:string "the answer to the math problem"`,
44
39
  provider: "google-gemini",
45
40
  providerKeyName: "GEMINI_API_KEY",
46
41
  ai: {
@@ -48,19 +43,35 @@ const config = {
48
43
  temperature: 0,
49
44
  },
50
45
  options: {
51
- debug: true,
52
- googleSearchRetrieval: {
53
- dynamic_retrieval_config: {
54
- mode: "MODE_UNSPECIFIED",
55
- },
56
- },
46
+ debug: false,
47
+ stream: false,
48
+ codeExecution: true
57
49
  },
58
50
  },
51
+ // {
52
+ // name: "WebSearch",
53
+ // description:
54
+ // "Searches the web for the latest information using Google search",
55
+ // signature:
56
+ // 'webSearchQuery:string "a query for Google search" -> webSearchResponse:string "the result of the search"',
57
+ // provider: "google-gemini",
58
+ // providerKeyName: "GEMINI_API_KEY",
59
+ // ai: {
60
+ // model: "gemini-1.5-pro",
61
+ // temperature: 0,
62
+ // },
63
+ // options: {
64
+ // debug: false,
65
+ // stream: false,
66
+ // googleSearchRetrieval: {
67
+ // mode: "MODE_UNSPECIFIED",
68
+ // },
69
+ // },
70
+ // },
59
71
  {
60
- name: "Manager",
61
- description: "Answers questions from the user",
62
- signature:
63
- 'question:string "a question from a user", plan:string "a suggested plan to answer the question" -> answer:string "the answer"',
72
+ name: "ManagerAgent",
73
+ description: "Completes a user specified task.",
74
+ signature: `task:string "a task to be completed" -> result:string "the result of the task"`,
64
75
  provider: "openai",
65
76
  providerKeyName: "OPENAI_API_KEY",
66
77
  ai: {
@@ -69,16 +80,13 @@ const config = {
69
80
  },
70
81
  options: {
71
82
  debug: true,
83
+ stream: false,
72
84
  },
73
- functions: ["CurrentDateTime", "DaysBetweenDates"],
85
+ agents: ["MathAgent"],
74
86
  },
75
87
  ],
76
88
  };
77
89
 
78
- // Create crew instance with the direct configuration
79
- const crew = new AxCrew(config, AxCrewFunctions);
80
- crew.addAgentsToCrew(["Planner", "Calculator", "WebSearch", "Manager"]);
81
-
82
90
  const calculateAndPrintAgentCost = (agent, agentName) => {
83
91
  const { models, modelUsage, modelInfo } = agent.axai;
84
92
 
@@ -89,16 +97,32 @@ const calculateAndPrintAgentCost = (agent, agentName) => {
89
97
  console.log(`\n${agentName} Usage:\nPrompt Token Cost: $${(promptTokens / 1000000 * modelDetails?.promptTokenCostPer1M).toFixed(6)}\nCompletion Token Cost: $${(completionTokens / 1000000 * modelDetails?.completionTokenCostPer1M).toFixed(6)}\nTotal Cost: $${totalCost.toFixed(6)}\nPrompt Tokens: ${promptTokens}\nCompletion Tokens: ${completionTokens}\nTotal Tokens: ${promptTokens + completionTokens}`);
90
98
  };
91
99
 
92
- const userQuery = "best sushi in mumbai";
93
- console.log(`\n\nQuestion: ${userQuery}`);
100
+ // Create crew instance with the direct configuration
101
+ const crew = new AxCrew(config, AxCrewFunctions);
102
+ crew.addAgentsToCrew(["MathAgent", "ManagerAgent"]);
103
+
104
+ // const userQuery = "who is considered as the father of the iphone and what is the 7th root of their year of birth";
105
+ const userQuery = "write an essay about the future of ai and then summarize it";
106
+ console.log(`\nTask: ${userQuery}`);
107
+
108
+ // const Planner = crew.agents.get("Planner");
109
+ // const plannerResponse = await Planner.forward({ task: userQuery });
110
+ // const plan = plannerResponse.plan;
111
+ // console.log(`\n\nPlan: ${plan}`);
112
+
113
+ const ManagerAgent = crew.agents.get("ManagerAgent");
114
+ const managerAgentResponse = await ManagerAgent.forward({
115
+ task: userQuery,
116
+ });
117
+ console.log(`\n\nManagerAgent Response: ${managerAgentResponse.result}`);
94
118
 
95
119
  // const Planner = crew.agents.get("Planner");
96
120
  // const plannerResponse = await Planner.forward({ task: userQuery });
97
121
  // console.log(`\n\nPlanner Response: ${plannerResponse.plan}`);
98
122
 
99
- const WebSearch = crew.agents.get("WebSearch");
100
- const webSearchResponse = await WebSearch.forward({ webSearchQuery: userQuery });
101
- console.log(`\n\nWeb Search Response: ${webSearchResponse.webSearchResponse}`);
123
+ // const WebSearch = crew.agents.get("WebSearch");
124
+ // const webSearchResponse = await WebSearch.forward({ webSearchQuery: userQuery });
125
+ // console.log(`\n\nWeb Search Response: ${webSearchResponse.webSearchResponse}`);
102
126
 
103
127
  // const calculatorResponse = await crew.agents.get("Calculator").forward({ mathProblem: userQuery });
104
128
  // calculateAndPrintAgentCost(crew.agents.get("Calculator"), "Calculator");
package/test1.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { AxCrew, AxCrewFunctions, FunctionRegistryType, StateInstance } from './dist/index.js';
2
+ import type { AxFunction } from '@ax-llm/ax';
3
+
4
+ // Type-safe configuration
5
+ const config = {
6
+ crew: [{
7
+ name: "Planner",
8
+ description: "Creates a plan to complete a task",
9
+ signature: "task:string \"a task to be completed\" -> plan:string \"a plan to execute the task\"",
10
+ provider: "google-gemini",
11
+ providerKeyName: "GEMINI_API_KEY",
12
+ ai: {
13
+ model: "gemini-1.5-pro",
14
+ temperature: 0
15
+ }
16
+ }]
17
+ };
18
+
19
+ // Create custom functions with type safety
20
+ class MyCustomFunction {
21
+ constructor(private state: Record<string, any>) {}
22
+
23
+ toFunction(): AxFunction {
24
+ return {
25
+ name: 'MyCustomFunction',
26
+ description: 'Does something useful',
27
+ parameters: {
28
+ type: 'object',
29
+ properties: {
30
+ input: { type: 'string', description: "input to the function" }
31
+ }
32
+ },
33
+ func: async ({ input }) => {
34
+ // Implementation
35
+ return input;
36
+ }
37
+ };
38
+ }
39
+ }
40
+
41
+ // Type-safe function registry
42
+ const myFunctions: FunctionRegistryType = {
43
+ MyCustomFunction
44
+ };
45
+
46
+ // Create crew with type checking
47
+ const crew = new AxCrew(config, myFunctions);
48
+
49
+ // Type-safe state management
50
+ crew.state.set('key', 'value');
51
+ const value: string = crew.state.get('key');
52
+
53
+ // Type-safe agent management
54
+ const agents = crew.addAgentsToCrew(['Planner']);
55
+ const planner = agents?.get('Planner');
56
+
57
+ if (planner) {
58
+ // Type-safe agent usage
59
+ const response = await planner.forward({ task: "Plan something" });
60
+ console.log(response.plan);
61
+ const cost = planner.getUsageCost();
62
+
63
+ if (cost) {
64
+ console.log(`Total cost: $${cost.totalCost}`);
65
+ console.log(`Total tokens: ${cost.tokenMetrics.totalTokens}`);
66
+ }
67
+ }