Orchestrates the execution of AI agents.

The orchestrator manages agent registration, execution, and coordination between multiple agents.

class StratixAgentOrchestrator implements AgentOrchestrator {
private agents = new Map<string, AIAgent<any, any>>();

registerAgent(agent: AIAgent<any, any>): void {
this.agents.set(agent.id.value, agent);
}

async executeAgent<TInput, TOutput>(
agentId: AgentId,
input: TInput,
context: AgentContext
): Promise<AgentResult<TOutput>> {
const agent = this.agents.get(agentId.value);
if (!agent) throw new Error('Agent not found');

agent.setContext(context);
return await agent.execute(input);
}
}
interface AgentOrchestrator {
    registerAgent(agent: AIAgent<unknown, unknown>): void;
    unregisterAgent(agentId: AgentId): void;
    executeAgent<TInput, TOutput>(
        agentId: AgentId,
        input: TInput,
        context: AgentContext,
    ): Promise<AgentResult<TOutput>>;
    executeSequential(
        agents: AIAgent<unknown, unknown>[],
        input: unknown,
        context: AgentContext,
    ): Promise<AgentResult<unknown>>;
    executeParallel(
        agents: AIAgent<unknown, unknown>[],
        input: unknown,
        context: AgentContext,
    ): Promise<AgentResult<unknown>[]>;
    delegateToAgent(
        fromAgent: AIAgent<unknown, unknown>,
        toAgent: AIAgent<unknown, unknown>,
        input: unknown,
    ): Promise<AgentResult<unknown>>;
}

Methods

  • Executes multiple agents sequentially

    Each agent receives the output of the previous agent as input.

    Parameters

    • agents: AIAgent<unknown, unknown>[]

      Array of agents to execute in sequence

    • input: unknown

      Initial input data

    • context: AgentContext

      Execution context

    Returns Promise<AgentResult<unknown>>

    The final agent result

  • Executes multiple agents in parallel

    All agents receive the same input and execute simultaneously.

    Parameters

    • agents: AIAgent<unknown, unknown>[]

      Array of agents to execute in parallel

    • input: unknown

      Input data (same for all agents)

    • context: AgentContext

      Execution context

    Returns Promise<AgentResult<unknown>[]>

    Array of agent results

  • Delegates execution from one agent to another

    Parameters

    • fromAgent: AIAgent<unknown, unknown>

      The delegating agent

    • toAgent: AIAgent<unknown, unknown>

      The agent to delegate to

    • input: unknown

      Input data for the target agent

    Returns Promise<AgentResult<unknown>>

    The result from the target agent