// Initialize all agents defined in the configawait crew.addAllAgents();// Get agent instancesconst planner = crew.agents?.get("Planner");const manager = crew.agents?.get("Manager");
This method:
Reads all agents from your configuration
Automatically determines the correct initialization order based on dependencies
// Add multiple agents - dependencies will be handled automaticallyawait crew.addAgentsToCrew(['Manager', 'Planner', 'Calculator']);// Or add them in multiple steps - order doesn't matterawait crew.addAgentsToCrew(['Calculator']); // Will be initialized firstawait crew.addAgentsToCrew(['Manager']); // Will initialize dependencies
// Add agents one by one - you must handle dependencies manuallyawait crew.addAgent('Calculator'); // Add base agent firstawait crew.addAgent('Planner'); // Then its dependentawait crew.addAgent('Manager'); // Then agents that depend on both
One of the most powerful features of crews is shared state. All agents in a crew have access to the same state:
// Set state at crew levelcrew.state.set('name', 'Crew1');crew.state.set('location', 'Earth');// Access from any agentconst planner = crew.agents.get("Planner");planner.state.get('name'); // 'Crew1'// Set state from an agentplanner.state.set('plan', 'Fly to Mars');// Access the updated state from another agentconst manager = crew.agents.get("Manager");manager.state.getAll(); // { name: 'Crew1', location: 'Earth', plan: 'Fly to Mars' }
Here's how you might use a crew to solve a problem:
import { AxCrew, AxCrewFunctions } from '@amitdeshmukh/ax-crew';// Create and initialize the crewconst crew = new AxCrew(config, AxCrewFunctions);await crew.addAgentsToCrew(['Planner', 'Calculator', 'Manager']);// Get agent instancesconst planner = crew.agents.get("Planner");const manager = crew.agents.get("Manager");// User queryconst userQuery = "What's the square root of the number of days until Christmas?";// Execute the task in stagesconst planResponse = await planner.forward({ task: userQuery });const managerResponse = await manager.forward({ question: userQuery, plan: planResponse.plan });console.log(`Plan: ${planResponse.plan}`);console.log(`Answer: ${managerResponse.answer}`);