@amitdeshmukh/ax-crew 3.11.3 → 4.1.1
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 +34 -0
- package/README.md +83 -82
- package/dist/agents/agentConfig.d.ts +7 -6
- package/dist/agents/agentConfig.js +40 -32
- package/dist/agents/index.d.ts +14 -10
- package/dist/agents/index.js +155 -40
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/metrics/index.d.ts +2 -0
- package/dist/metrics/index.js +2 -0
- package/dist/metrics/registry.d.ts +9 -0
- package/dist/metrics/registry.js +138 -0
- package/dist/metrics/types.d.ts +40 -0
- package/dist/metrics/types.js +1 -0
- package/dist/types.d.ts +16 -6
- package/examples/basic-researcher-writer.ts +18 -13
- package/examples/mcp-agent.ts +14 -9
- package/examples/solve-math-problem.ts +7 -5
- package/examples/streaming.ts +7 -6
- package/package.json +5 -3
- package/src/agents/agentConfig.ts +45 -38
- package/src/agents/index.ts +171 -59
- package/src/index.ts +2 -0
- package/src/metrics/index.ts +4 -0
- package/src/metrics/registry.ts +167 -0
- package/src/metrics/types.ts +48 -0
- package/src/types.ts +33 -7
- package/tests/AxCrew.test.ts +22 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
## [4.1.0] - 2025-08-25
|
|
3
|
+
|
|
4
|
+
### Added
|
|
5
|
+
- Agent persona support via `definition` with validation (>= 100 chars).
|
|
6
|
+
- `prompt` alias for persona; `definition` takes precedence when both provided.
|
|
7
|
+
|
|
8
|
+
### Changed
|
|
9
|
+
- README updated to document `definition`/`prompt` usage with example.
|
|
10
|
+
- Example `examples/mcp-agent.ts` demonstrates `prompt` in agent config.
|
|
11
|
+
|
|
12
|
+
## [4.0.1] - 2025-08-24
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- Dependency: `big.js` for precise accumulation of estimated costs.
|
|
16
|
+
- Dev Dependency: `@types/big.js` for TypeScript support.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- Switched crew cost reporting to metrics-based API. Use `agent.getMetrics()` and `crew.getCrewMetrics()` instead of legacy cost getters.
|
|
20
|
+
- Estimated cost (`estimatedCostUSD`) is now accumulated with Big.js and reported rounded to 5 decimal places.
|
|
21
|
+
- Tests updated to use metrics assertions; added dummy `ANTHROPIC_API_KEY` in test setup to avoid env failures.
|
|
22
|
+
- Test agent signatures updated to new DSL (`query:string -> queryResponse:string`).
|
|
23
|
+
- Aligned with new `@ax-llm/ax` `ai()` and `agent()` factory methods: enforce canonical provider slugs, pass cost tracker via `options.trackers`, and validate `apiURL` when provided.
|
|
24
|
+
- Updated package versions for `@ax-llm/ax` and `@ax-llm/ax-tools`.
|
|
25
|
+
|
|
26
|
+
### Deprecated
|
|
27
|
+
- Legacy cost APIs (`getLastUsageCost`, `getAccumulatedCosts`, `getAggregatedCosts`) are deprecated in favor of metrics.
|
|
28
|
+
|
|
29
|
+
### Removed
|
|
30
|
+
- Tests no longer use `getAggregatedCosts`; replaced with metrics assertions.
|
|
31
|
+
|
|
32
|
+
### Updated
|
|
33
|
+
- README now documents metrics usage and 5-decimal cost rounding, de-emphasizing legacy cost APIs.
|
|
34
|
+
- README Features now includes "Metrics and Cost Tracking"; examples updated to use metrics (`getMetrics`, `getCrewMetrics`).
|
|
35
|
+
|
|
2
36
|
|
|
3
37
|
This Changelog format is based on [Keep a Changelog]
|
|
4
38
|
(https://keepachangelog.com/en/1.0.0/), and this project
|
package/README.md
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
### AxCrew — build a crew of AI agents with shared state (powered by AxLLM)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
AxCrew lets you define a team of AI agents in config and run them together with shared state, tools, streaming, MCP, and built‑in metrics/cost tracking. Bring your own functions or use the provided registry.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **Streaming
|
|
12
|
-
- **
|
|
7
|
+
### Why AxCrew
|
|
8
|
+
- **Config-first crews**: Declare agents once; instantiate on demand.
|
|
9
|
+
- **Shared state**: Simple key/value state all agents can read/write.
|
|
10
|
+
- **Sub‑agents and tools**: Compose agents and functions cleanly.
|
|
11
|
+
- **Streaming**: Real‑time token streaming for responsive UX.
|
|
12
|
+
- **MCP**: Connect agents to MCP servers (STDIO, HTTP SSE, Streamable HTTP).
|
|
13
|
+
- **Metrics & costs**: Per‑agent and crew snapshots, with estimated USD.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### Installation
|
|
15
|
+
### Install
|
|
17
16
|
Install this package:
|
|
18
17
|
```bash
|
|
19
18
|
npm install @amitdeshmukh/ax-crew
|
|
@@ -21,11 +20,22 @@ npm install @amitdeshmukh/ax-crew
|
|
|
21
20
|
AxLLM is a peer dependency, so you will need to install it separately.
|
|
22
21
|
|
|
23
22
|
```bash
|
|
24
|
-
npm install @ax-llm/ax
|
|
23
|
+
npm install @ax-llm/ax @ax-llm/ax-tools
|
|
25
24
|
```
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
Requirements: Node.js >= 21.
|
|
27
|
+
|
|
28
|
+
### Environment
|
|
29
|
+
Set provider keys in your environment. Example `.env`:
|
|
30
|
+
```bash
|
|
31
|
+
GEMINI_API_KEY=...
|
|
32
|
+
ANTHROPIC_API_KEY=...
|
|
33
|
+
OPENAI_API_KEY=...
|
|
34
|
+
```
|
|
35
|
+
In each agent config, set `providerKeyName` to the env var name.
|
|
36
|
+
|
|
37
|
+
### Quickstart
|
|
38
|
+
This package includes TypeScript declarations and provides type safety.
|
|
29
39
|
|
|
30
40
|
```typescript
|
|
31
41
|
import { AxCrew, AxCrewFunctions, FunctionRegistryType, StateInstance } from '@amitdeshmukh/ax-crew';
|
|
@@ -81,23 +91,20 @@ crew.state.set('key', 'value');
|
|
|
81
91
|
const value: string = crew.state.get('key');
|
|
82
92
|
|
|
83
93
|
// Add agents to the crew
|
|
84
|
-
|
|
85
|
-
const planner = agents?.get('Planner');
|
|
94
|
+
await crew.addAgentsToCrew(['Planner']);
|
|
95
|
+
const planner = crew.agents?.get('Planner');
|
|
86
96
|
|
|
87
97
|
if (planner) {
|
|
88
|
-
// Agent usage with function overloads
|
|
89
|
-
// Direct usage - AI config from agent construction is used
|
|
90
98
|
const response = await planner.forward({ task: "Plan something" });
|
|
91
99
|
|
|
92
100
|
// Sub-agent usage - when used by another agent (AI is ignored and agent's own config is used)
|
|
93
101
|
const subAgentResponse = await planner.forward(ai, { task: "Plan something" });
|
|
94
102
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
103
|
+
// Metrics (per-agent and per-crew)
|
|
104
|
+
const agentMetrics = (planner as any).getMetrics?.();
|
|
105
|
+
const crewMetrics = crew.getCrewMetrics();
|
|
106
|
+
console.log('Agent metrics:', agentMetrics);
|
|
107
|
+
console.log('Crew metrics:', crewMetrics);
|
|
101
108
|
}
|
|
102
109
|
```
|
|
103
110
|
|
|
@@ -109,8 +116,14 @@ Key TypeScript features:
|
|
|
109
116
|
- Comprehensive type safety for agent operations and responses
|
|
110
117
|
- Usage cost tracking with proper types
|
|
111
118
|
|
|
112
|
-
###
|
|
113
|
-
|
|
119
|
+
### Concepts at a glance
|
|
120
|
+
- **Agent**: An LLM program with a `signature`, `provider`, `ai` model config, optional `examples`, and optional `mcpServers`.
|
|
121
|
+
- **Sub‑agents**: List other agent names in `agents` to compose behaviors.
|
|
122
|
+
- **Functions (tools)**: Register callable functions via a registry and reference by name in agent `functions`.
|
|
123
|
+
- **State**: `crew.state.set/get/getAll()` shared across all agents.
|
|
124
|
+
- **Persona**: Use `definition` (preferred) or `prompt` to set the system program. If both are present, `definition` wins.
|
|
125
|
+
- **Streaming**: Use `streamingForward()` for token streams.
|
|
126
|
+
- **Metrics**: Per‑agent `getMetrics()` + crew‑level `getCrewMetrics()` snapshots.
|
|
114
127
|
|
|
115
128
|
## Usage
|
|
116
129
|
|
|
@@ -174,6 +187,25 @@ Both methods support the same configuration structure and options. Choose the on
|
|
|
174
187
|
- Modify configurations at runtime
|
|
175
188
|
- Keep everything in one file for simpler projects
|
|
176
189
|
|
|
190
|
+
### Agent Persona: definition and prompt
|
|
191
|
+
|
|
192
|
+
- **definition**: Detailed persona/program description used as the system prompt. Recommended for precise control. Must be at least 100 characters.
|
|
193
|
+
- **prompt**: An alias for `definition`. If both are provided, **definition** takes precedence.
|
|
194
|
+
|
|
195
|
+
Add either field to any agent config. The chosen value becomes the Ax agent's underlying program description (system prompt).
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{
|
|
199
|
+
"name": "Planner",
|
|
200
|
+
"description": "Creates a plan to complete a task",
|
|
201
|
+
"prompt": "You are a meticulous planning assistant. Produce concise, executable step-by-step plans with clear justifications, constraints, and assumptions. Prefer brevity, avoid fluff, and ask for missing critical details before proceeding when necessary.",
|
|
202
|
+
"signature": "task:string -> plan:string",
|
|
203
|
+
"provider": "google-gemini",
|
|
204
|
+
"providerKeyName": "GEMINI_API_KEY",
|
|
205
|
+
"ai": { "model": "gemini-1.5-flash", "temperature": 0 }
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
177
209
|
### Agent Examples
|
|
178
210
|
You can provide examples to guide the behavior of your agents using the `examples` field in the agent configuration. Examples help the agent understand the expected input/output format and improve its responses.
|
|
179
211
|
|
|
@@ -514,7 +546,7 @@ For MCP servers that support streamable HTTP communication:
|
|
|
514
546
|
"mcpEndpoint": "http://localhost:3002/stream",
|
|
515
547
|
"options": {
|
|
516
548
|
"authorization": "Bearer ey.JhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..-1234567890.1234567890",
|
|
517
|
-
"headers": {
|
|
549
|
+
"headers": {
|
|
518
550
|
"X-Custom-Header": "custom-value"
|
|
519
551
|
}
|
|
520
552
|
}
|
|
@@ -667,76 +699,45 @@ For new streamable HTTP servers, use:
|
|
|
667
699
|
|
|
668
700
|
### Tracking Usage Costs
|
|
669
701
|
|
|
670
|
-
The package provides
|
|
702
|
+
The package provides metrics for monitoring API usage across individual agents and the entire crew. Estimated costs are accumulated precisely and rounded to 5 decimal places for reporting.
|
|
671
703
|
|
|
672
704
|
```javascript
|
|
673
705
|
// After running an agent's forward method
|
|
674
|
-
|
|
706
|
+
await Planner.forward({ task: userQuery });
|
|
675
707
|
|
|
676
|
-
//
|
|
677
|
-
const
|
|
678
|
-
console.log(
|
|
679
|
-
/*
|
|
708
|
+
// Per-agent metrics
|
|
709
|
+
const agentMetrics = (Planner as any).getMetrics?.();
|
|
710
|
+
console.log(agentMetrics);
|
|
711
|
+
/* Example:
|
|
680
712
|
{
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
totalTokens: 413
|
|
688
|
-
}
|
|
713
|
+
provider: "anthropic",
|
|
714
|
+
model: "claude-3-haiku-20240307",
|
|
715
|
+
requests: { totalRequests, totalErrors, errorRate, totalStreamingRequests, durationMsSum, durationCount },
|
|
716
|
+
tokens: { promptTokens, completionTokens, totalTokens },
|
|
717
|
+
estimatedCostUSD: 0.00091, // rounded to 5 decimals
|
|
718
|
+
functions: { totalFunctionCalls, totalFunctionLatencyMs }
|
|
689
719
|
}
|
|
690
720
|
*/
|
|
691
721
|
|
|
692
|
-
//
|
|
693
|
-
const
|
|
694
|
-
console.log(
|
|
695
|
-
/*
|
|
722
|
+
// Crew metrics
|
|
723
|
+
const crewMetrics = crew.getCrewMetrics();
|
|
724
|
+
console.log(crewMetrics);
|
|
725
|
+
/* Example:
|
|
696
726
|
{
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
promptTokens: 291,
|
|
702
|
-
completionTokens: 122,
|
|
703
|
-
totalTokens: 413
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
*/
|
|
707
|
-
|
|
708
|
-
// Get aggregated costs for all agents in the crew
|
|
709
|
-
const crewCosts = crew.getAggregatedCosts();
|
|
710
|
-
console.log(crewCosts);
|
|
711
|
-
/* Output example:
|
|
712
|
-
{
|
|
713
|
-
totalCost: "0.0025482500000",
|
|
714
|
-
byAgent: {
|
|
715
|
-
"Planner": { ... },
|
|
716
|
-
"Calculator": { ... },
|
|
717
|
-
"Manager": { ... }
|
|
718
|
-
},
|
|
719
|
-
aggregatedMetrics: {
|
|
720
|
-
promptTokens: 850,
|
|
721
|
-
completionTokens: 324,
|
|
722
|
-
totalTokens: 1174,
|
|
723
|
-
promptCost: "0.0010625000000",
|
|
724
|
-
completionCost: "0.0014857500000"
|
|
725
|
-
}
|
|
727
|
+
requests: { ... },
|
|
728
|
+
tokens: { promptTokens, completionTokens, totalTokens },
|
|
729
|
+
estimatedCostUSD: 0.00255, // rounded to 5 decimals
|
|
730
|
+
functions: { ... }
|
|
726
731
|
}
|
|
727
732
|
*/
|
|
728
733
|
|
|
729
|
-
// Reset
|
|
734
|
+
// Reset tracked metrics
|
|
730
735
|
crew.resetCosts();
|
|
731
736
|
```
|
|
732
737
|
|
|
733
|
-
|
|
734
|
-
-
|
|
735
|
-
-
|
|
736
|
-
- Aggregated crew-wide metrics
|
|
737
|
-
- Token usage statistics
|
|
738
|
-
- Support for different pricing tiers per model
|
|
739
|
-
- Persistent cost tracking across multiple agent runs
|
|
738
|
+
Notes:
|
|
739
|
+
- Legacy cost APIs (`getLastUsageCost`, `getAccumulatedCosts`, `getAggregatedCosts`) are superseded by metrics methods.
|
|
740
|
+
- Estimated cost values are numbers rounded to 5 decimal places.
|
|
740
741
|
|
|
741
742
|
## Changelog
|
|
742
743
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { AxDefaultCostTracker } from '@ax-llm/ax';
|
|
1
2
|
import type { AxFunction } from '@ax-llm/ax';
|
|
2
|
-
import type { AgentConfig, CrewConfigInput, FunctionRegistryType, MCPTransportConfig, MCPStdioTransportConfig, MCPHTTPSSETransportConfig,
|
|
3
|
-
declare const AIConstructors: Record<string, any>;
|
|
4
|
-
export type Provider = keyof typeof AIConstructors;
|
|
3
|
+
import type { AgentConfig, CrewConfigInput, FunctionRegistryType, MCPTransportConfig, MCPStdioTransportConfig, MCPHTTPSSETransportConfig, MCPStreamableHTTPTransportConfig } from '../types.js';
|
|
5
4
|
export declare function isStdioTransport(config: MCPTransportConfig): config is MCPStdioTransportConfig;
|
|
6
5
|
export declare function isHTTPSSETransport(config: MCPTransportConfig): config is MCPHTTPSSETransportConfig;
|
|
7
|
-
export declare function isStreambleHTTPTransport(config: MCPTransportConfig): config is
|
|
6
|
+
export declare function isStreambleHTTPTransport(config: MCPTransportConfig): config is MCPStreamableHTTPTransportConfig;
|
|
8
7
|
/**
|
|
9
8
|
* Parses and returns the AxCrew config from either a JSON config file or a direct JSON object.
|
|
10
9
|
* @param {CrewConfigInput} input - Either a path to the agent config json file or a JSON object with crew configuration.
|
|
@@ -27,12 +26,14 @@ declare const parseCrewConfig: (input: CrewConfigInput) => {
|
|
|
27
26
|
* the API key is not found, or the provider key name is not specified in the configuration.
|
|
28
27
|
*/
|
|
29
28
|
declare const parseAgentConfig: (agentName: string, crewConfig: CrewConfigInput, functions: FunctionRegistryType, state: Record<string, any>) => Promise<{
|
|
30
|
-
ai:
|
|
29
|
+
ai: import("@ax-llm/ax").AxAI<string>;
|
|
31
30
|
name: string;
|
|
32
31
|
description: string;
|
|
33
|
-
|
|
32
|
+
definition: any;
|
|
33
|
+
signature: string | import("@ax-llm/ax").AxSignature<Record<string, any>, Record<string, any>>;
|
|
34
34
|
functions: AxFunction[];
|
|
35
35
|
subAgentNames: string[];
|
|
36
36
|
examples: Record<string, any>[];
|
|
37
|
+
tracker: AxDefaultCostTracker;
|
|
37
38
|
}>;
|
|
38
39
|
export { parseAgentConfig, parseCrewConfig };
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
// Import
|
|
3
|
-
import {
|
|
4
|
-
//
|
|
5
|
-
import { AxMCPClient, AxMCPHTTPSSETransport, AxMCPStreambleHTTPTransport } from '@ax-llm/ax';
|
|
2
|
+
// Import Ax factory and MCP transports (as exported by current package)
|
|
3
|
+
import { ai, AxMCPClient, AxMCPHTTPSSETransport, AxMCPStreambleHTTPTransport, AxDefaultCostTracker } from '@ax-llm/ax';
|
|
4
|
+
// STDIO transport from tools package
|
|
6
5
|
import { AxMCPStdioTransport } from '@ax-llm/ax-tools';
|
|
7
6
|
import { PROVIDER_API_KEYS } from '../config/index.js';
|
|
8
|
-
//
|
|
9
|
-
const
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'ollama'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
|
|
7
|
+
// Canonical provider slugs supported by ai() factory
|
|
8
|
+
const PROVIDER_CANONICAL = new Set([
|
|
9
|
+
'openai',
|
|
10
|
+
'anthropic',
|
|
11
|
+
'google-gemini',
|
|
12
|
+
'mistral',
|
|
13
|
+
'groq',
|
|
14
|
+
'cohere',
|
|
15
|
+
'together',
|
|
16
|
+
'deepseek',
|
|
17
|
+
'ollama',
|
|
18
|
+
'huggingface',
|
|
19
|
+
'openrouter',
|
|
20
|
+
'azure-openai',
|
|
21
|
+
'reka',
|
|
22
|
+
'x-grok'
|
|
23
|
+
]);
|
|
24
|
+
// Provider type lives in src/types.ts
|
|
24
25
|
// Type guard to check if config is stdio transport
|
|
25
26
|
export function isStdioTransport(config) {
|
|
26
27
|
return 'command' in config;
|
|
@@ -173,11 +174,12 @@ const parseAgentConfig = async (agentName, crewConfig, functions, state) => {
|
|
|
173
174
|
if (!agentConfigData) {
|
|
174
175
|
throw new Error(`AI agent with name ${agentName} is not configured`);
|
|
175
176
|
}
|
|
176
|
-
//
|
|
177
|
-
const
|
|
178
|
-
if (!
|
|
179
|
-
throw new Error(`AI provider ${agentConfigData.provider} is not supported.
|
|
177
|
+
// Enforce canonical provider slug
|
|
178
|
+
const lower = agentConfigData.provider.toLowerCase();
|
|
179
|
+
if (!PROVIDER_CANONICAL.has(lower)) {
|
|
180
|
+
throw new Error(`AI provider ${agentConfigData.provider} is not supported. Use one of: ${Array.from(PROVIDER_CANONICAL).join(', ')}`);
|
|
180
181
|
}
|
|
182
|
+
const provider = lower;
|
|
181
183
|
// If an API Key property is present, get the API key for the AI agent from the environment variables
|
|
182
184
|
let apiKey = '';
|
|
183
185
|
if (agentConfigData.providerKeyName) {
|
|
@@ -189,26 +191,30 @@ const parseAgentConfig = async (agentName, crewConfig, functions, state) => {
|
|
|
189
191
|
else {
|
|
190
192
|
throw new Error(`Provider key name is missing in the agent configuration`);
|
|
191
193
|
}
|
|
192
|
-
// Create
|
|
193
|
-
const
|
|
194
|
+
// Create a cost tracker instance and pass to ai()
|
|
195
|
+
const costTracker = new AxDefaultCostTracker((agentConfigData.options?.costTracking) || undefined);
|
|
196
|
+
// Create an instance of the AI agent via factory
|
|
197
|
+
const aiArgs = {
|
|
198
|
+
name: provider,
|
|
194
199
|
apiKey,
|
|
195
200
|
config: agentConfigData.ai,
|
|
196
201
|
options: {
|
|
197
202
|
debug: agentConfigData.debug || false,
|
|
198
|
-
...agentConfigData.options
|
|
203
|
+
...agentConfigData.options,
|
|
204
|
+
// Attach default cost tracker so usage/costs are recorded by provider layer
|
|
205
|
+
trackers: [costTracker]
|
|
199
206
|
}
|
|
200
|
-
}
|
|
201
|
-
// If an apiURL is provided in the agent config, set it in the AI agent
|
|
207
|
+
};
|
|
202
208
|
if (agentConfigData.apiURL) {
|
|
203
209
|
try {
|
|
204
|
-
// Validate apiURL format
|
|
205
210
|
new URL(agentConfigData.apiURL);
|
|
206
|
-
|
|
211
|
+
aiArgs.apiURL = agentConfigData.apiURL;
|
|
207
212
|
}
|
|
208
213
|
catch (error) {
|
|
209
214
|
throw new Error(`Invalid apiURL provided: ${agentConfigData.apiURL}`);
|
|
210
215
|
}
|
|
211
216
|
}
|
|
217
|
+
const aiInstance = ai(aiArgs);
|
|
212
218
|
// If an mcpServers config is provided in the agent config, convert to functions
|
|
213
219
|
const mcpFunctions = await initializeMCPServers(agentConfigData);
|
|
214
220
|
// Prepare functions for the AI agent
|
|
@@ -229,13 +235,15 @@ const parseAgentConfig = async (agentName, crewConfig, functions, state) => {
|
|
|
229
235
|
];
|
|
230
236
|
// Return AI instance and Agent parameters
|
|
231
237
|
return {
|
|
232
|
-
ai,
|
|
238
|
+
ai: aiInstance,
|
|
233
239
|
name: agentName,
|
|
234
240
|
description: agentConfigData.description,
|
|
241
|
+
definition: agentConfigData.definition ?? agentConfigData.prompt,
|
|
235
242
|
signature: agentConfigData.signature,
|
|
236
243
|
functions: agentFunctions,
|
|
237
244
|
subAgentNames: agentConfigData.agents || [],
|
|
238
245
|
examples: agentConfigData.examples || [],
|
|
246
|
+
tracker: costTracker,
|
|
239
247
|
};
|
|
240
248
|
}
|
|
241
249
|
catch (error) {
|
package/dist/agents/index.d.ts
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
import { AxAgent, AxAI } from "@ax-llm/ax";
|
|
2
2
|
import type { AxSignature, AxAgentic, AxFunction, AxProgramForwardOptions, AxProgramStreamingForwardOptions, AxGenStreamingOut } from "@ax-llm/ax";
|
|
3
3
|
import type { StateInstance, FunctionRegistryType, UsageCost, CrewConfigInput, MCPTransportConfig } from "../types.js";
|
|
4
|
-
import { StateFulAxAgentUsage } from "./agentUseCosts.js";
|
|
5
4
|
declare class StatefulAxAgent extends AxAgent<any, any> {
|
|
6
5
|
state: StateInstance;
|
|
7
6
|
axai: any;
|
|
8
7
|
private agentName;
|
|
8
|
+
private costTracker?;
|
|
9
|
+
private lastRecordedCostUSD;
|
|
10
|
+
private isAxAIService;
|
|
11
|
+
private isAxAIInstance;
|
|
9
12
|
constructor(ai: AxAI, options: Readonly<{
|
|
10
13
|
name: string;
|
|
11
14
|
description: string;
|
|
15
|
+
definition?: string;
|
|
12
16
|
signature: string | AxSignature;
|
|
13
17
|
agents?: AxAgentic<any, any>[] | undefined;
|
|
14
18
|
functions?: (AxFunction | (() => AxFunction))[] | undefined;
|
|
15
19
|
examples?: Array<Record<string, any>> | undefined;
|
|
16
20
|
mcpServers?: Record<string, MCPTransportConfig> | undefined;
|
|
17
21
|
}>, state: StateInstance);
|
|
18
|
-
forward(values: Record<string, any>, options?: Readonly<AxProgramForwardOptions
|
|
19
|
-
forward(ai: AxAI, values: Record<string, any>, options?: Readonly<AxProgramForwardOptions
|
|
20
|
-
streamingForward(values: Record<string, any>, options?: Readonly<AxProgramStreamingForwardOptions
|
|
21
|
-
streamingForward(ai: AxAI, values: Record<string, any>, options?: Readonly<AxProgramStreamingForwardOptions
|
|
22
|
+
forward(values: Record<string, any>, options?: Readonly<AxProgramForwardOptions<any>>): Promise<Record<string, any>>;
|
|
23
|
+
forward(ai: AxAI, values: Record<string, any>, options?: Readonly<AxProgramForwardOptions<any>>): Promise<Record<string, any>>;
|
|
24
|
+
streamingForward(values: Record<string, any>, options?: Readonly<AxProgramStreamingForwardOptions<any>>): AxGenStreamingOut<any>;
|
|
25
|
+
streamingForward(ai: AxAI, values: Record<string, any>, options?: Readonly<AxProgramStreamingForwardOptions<any>>): AxGenStreamingOut<any>;
|
|
22
26
|
getLastUsageCost(): UsageCost | null;
|
|
23
27
|
getAccumulatedCosts(): UsageCost | null;
|
|
28
|
+
getMetrics(): import("../metrics/types.js").MetricsSnapshot;
|
|
29
|
+
resetMetrics(): void;
|
|
24
30
|
}
|
|
25
31
|
/**
|
|
26
32
|
* Represents a crew of agents with shared state functionality.
|
|
@@ -63,14 +69,12 @@ declare class AxCrew {
|
|
|
63
69
|
* Cleans up the crew by dereferencing agents and resetting the state.
|
|
64
70
|
*/
|
|
65
71
|
destroy(): void;
|
|
66
|
-
/**
|
|
67
|
-
* Gets aggregated costs for all agents in the crew
|
|
68
|
-
* @returns Aggregated cost information for all agents
|
|
69
|
-
*/
|
|
70
|
-
getAggregatedCosts(): ReturnType<typeof StateFulAxAgentUsage.getAggregatedCosts>;
|
|
71
72
|
/**
|
|
72
73
|
* Resets all cost tracking for the crew
|
|
73
74
|
*/
|
|
74
75
|
resetCosts(): void;
|
|
76
|
+
getCrewMetrics(): import("../metrics/types.js").MetricsSnapshot;
|
|
77
|
+
resetCrewMetrics(): void;
|
|
75
78
|
}
|
|
76
79
|
export { AxCrew };
|
|
80
|
+
export type { StatefulAxAgent };
|