AxCrew

AxCrew Class

API reference for the AxCrew class

The AxCrew class is the main entry point for creating and managing a crew of AI agents.

Constructor

constructor(
  configInput: CrewConfigInput, 
  functions?: FunctionRegistryType,
  state?: StateInstance,
  options?: AxCrewOptions
)

Creates a new AxCrew instance.

Parameters:

  • configInput - A configuration object with a crew array
  • functions - Optional. A registry of functions that agents can use
  • state - Optional. A custom state instance
  • options - Optional. Additional options including telemetry configuration

Examples:

// Using a configuration object
const crew = new AxCrew({
  crew: [
    {
      name: "Planner",
      description: "Creates a plan",
      signature: "task:string -> plan:string",
      provider: "openai",
      providerKeyName: "OPENAI_API_KEY",
      ai: { model: "gpt-4", temperature: 0 }
    }
  ]
});
 
// With functions
import { AxCrewFunctions } from '@amitdeshmukh/ax-crew';
const crew = new AxCrew(config, AxCrewFunctions);
 
// With telemetry
const crew = new AxCrew(config, AxCrewFunctions, undefined, {
  telemetry: { tracer, meter }
});

Properties

state

state: StateInstance

A shared state instance accessible by all agents in the crew.

crew.state.set('key', 'value');
const value = crew.state.get('key');
const allState = crew.state.getAll();

agents

agents: Map<string, StatefulAxAgent>

A map of all initialized agents in the crew, keyed by agent name.

const planner = crew.agents.get('Planner');
 
if (crew.agents.has('Calculator')) {
  // Use Calculator agent
}

Methods

addAgent

async addAgent(agentName: string): Promise<StatefulAxAgent | undefined>

Adds a single agent to the crew by name.

This method requires you to handle dependencies manually. You must add any agents that this agent depends on before calling this method.

const calculator = await crew.addAgent('Calculator');

addAgentsToCrew

async addAgentsToCrew(agentNames: string[]): Promise<Map<string, StatefulAxAgent> | undefined>

Adds multiple agents to the crew, automatically handling dependencies.

const agents = await crew.addAgentsToCrew(['Manager', 'Planner']);

addAllAgents

async addAllAgents(): Promise<Map<string, StatefulAxAgent> | undefined>

Adds all agents defined in the configuration, automatically handling dependencies.

const agents = await crew.addAllAgents();

getAggregatedCosts

getAggregatedCosts(): AggregatedCosts

Gets the aggregated costs for all agents in the crew.

const costs = crew.getAggregatedCosts();
console.log(`Total cost: $${costs.totalCost}`);
console.log(`Total tokens: ${costs.aggregatedMetrics.totalTokens}`);

getCrewMetrics

getCrewMetrics(): MetricsSnapshot

Gets the metrics snapshot for the entire crew.

const metrics = crew.getCrewMetrics();
console.log(metrics);

resetCosts

resetCosts(): void

Resets the cost tracking for all agents in the crew.

crew.resetCosts();

applyTaskFeedback

async applyTaskFeedback(options: {
  taskId: string;
  feedback: string;
  strategy: 'all' | 'primary' | 'leaf';
}): Promise<void>

Applies feedback to agents for ACE learning.

await crew.applyTaskFeedback({
  taskId: result._taskId,
  feedback: "Be more concise in responses",
  strategy: "all"
});

Static Methods

registerMCPServer

static registerMCPServer(name: string, server: MCPServer): void

Registers a custom MCP server for use with agents.

AxCrew.registerMCPServer('custom-api', customServer);

On this page