Processes
The Process module is the central orchestration and runtime environment for the A2 framework components. It manages the instantiation, execution, and monitoring of agents, workflows, and other components during application runtime.
Usage
import { Process } from '@a2/core';
// Create a new process with configurationconst process = new Process({ agents: { assistant: { name: 'Assistant', instructions: 'You are a helpful assistant.', role: 'assistant', }, },});
// Initialize and run the processawait process.initialize();await process.run();
API Reference
Creating a Process
import { Process } from '@a2/core';
const process = new Process(config);
The Process constructor accepts an optional configuration object with the following properties:
agents
: Record of agent configurationsworkflow
: Workflow configurationlogger
: Custom logger instancerepository
: Custom repository instanceapiMiddleware
: API middleware configurationsmemory
: Memory instancecollab
: Collaboration instances
Process Methods
initialize()
Initializes the process and all components.
await process.initialize();
run(triggerData?)
Starts the Process, initiating the current workflow.
await process.run(triggerData);
Agents
// Get all agentsconst agents = process.getAgents();
// Get specific agentconst agent = process.getAgent('agentId');
// Register a new agentconst agent = process.registerAgent('newAgent', agentConfig);
// Unregister an agentprocess.unregisterAgent('agentId');
Workflows
// Get current workflowconst workflow = process.getWorkflow();
// Set or replace workflowconst workflow = process.setWorkflow(workflowConfig, 'workflowId');
// Clear workflowprocess.clearWorkflow();
// Start workflowconst instance = await process.startWorkflow(triggerData);
Other Utilities
// Get loggerconst logger = process.getLogger();
// Get/set memoryconst memory = process.getMemory();process.setMemory(memory);
// Get repositoryconst repository = process.getRepository();
// Get API middlewareconst middleware = process.getApiMiddleware();
// Get collabsconst collabs = process.getCollabs();const specificCollab = process.getCollabs('collabId');
Events
The Process class extends EventEmitter and emits the following events:
agent:created
: When a new agent is createdagent:deleted
: When an agent is deletedworkflow:created
: When a workflow is createdworkflow:deleted
: When a workflow is deletedworkflow:started
: When a workflow is startedworkflow:completed
: When a workflow completes successfullyworkflow:failed
: When a workflow failsmemory:initialized
: When memory is initializedpersistence:initialized
: When persistence is initialized