Function: routeToAgents()
Makaio Framework / services-core / routeToAgents
Function: routeToAgents()
Section titled “Function: routeToAgents()”routeToAgents(
bus,session,agents,message,messageId,turn,deliveryMode,onTurnComplete,sessionContext?,turnContextEnricher?,isNewTurn?,recoveryContext?,recoveredAgentIds?,swappedAgentIds?,swappedAgentCwd?,freshMessageHistory?):Promise<void>
Defined in: ../../../packages/services/core/src/session/handlers/route-to-agents.ts:260
Route a message to target agents via agent.sendMessage.
Fans out to all agents in parallel. On routing failure, marks agent as errored and checks for turn completion.
For fork sessions on their first turn, assembles projected context from parent chain.
Parameters
Section titled “Parameters”Bus instance for communication
session
Section titled “session”Session metadata (for fork detection)
agents
Section titled “agents”object[]
Target agents to route to
message
Section titled “message”string | { blocks: { content: string; type: "text"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "image"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "attachment"; } | { content: string; metadata?: Record<string, unknown>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; } | ({ content: string; type: "text"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "image"; } | { source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "document"; } | { attachmentType: "file" | "directory"; displayName?: string; fileName: string; filePath: string; source: { data: string; mimeType: string; type: "base64"; } | { mimeType?: string; type: "url"; url: string; }; type: "attachment"; } | { content: string; metadata?: Record<string, unknown>; type: "reasoning"; } | { args: Record<string, unknown>; name: string; toolCallId: string; type: "tool_call"; } | { isError?: boolean; output: string; toolCallId: string; type: "tool_output"; })[]; role?: "user" | "assistant" | "system"; }
Message content to send
messageId
Section titled “messageId”string
Message identifier
Turn tracking object
deliveryMode
Section titled “deliveryMode”"enqueue" | "immediate" | undefined
How to deliver the message
onTurnComplete
Section titled “onTurnComplete”(turn, result) => Promise<void>
Callback when turn completes (all agents done)
sessionContext?
Section titled “sessionContext?”Session context with curated messageHistory and decision signals
extractedContext?
Section titled “extractedContext?”unknown = ...
Structured context from compression (if hasCompression=true).
hasCompression?
Section titled “hasCompression?”boolean = ...
Whether compression is active (extractedContext present). If true, Agent should use fresh mode with compressed context.
hasConnectorSwap?
Section titled “hasConnectorSwap?”boolean = ...
Whether a connector swap occurred before this message (e.g., cwd/model change). If true, native resume is infeasible and adapters should use fresh mode.
hasNewTransforms?
Section titled “hasNewTransforms?”boolean = ...
Whether transforms have been applied since last turn. If true, Agent should use fresh mode (history changed).
isFirstTurn?
Section titled “isFirstTurn?”boolean = ...
Whether this is the first turn in the session. If true, no native history exists yet.
messageHistory?
Section titled “messageHistory?”object[] = ...
Curated message history assembled via getFullConversation(). Only used if Agent decides to inject (fresh mode).
turnContext?
Section titled “turnContext?”Record<string, JsonValue> = ...
Turn-scoped context assembled by PreUserMessage hooks and the orchestrator. Keys are plugin-defined (e.g., ‘skillCatalog’, ‘skills’, ‘predictedTools’). Adapters consume this to prepend context blocks.
Constrained to JSON-safe types to ensure serialization succeeds.
ADAPTER CONTRACT: Every adapter MUST materialize turnContext into the LLM-facing message using serializeTurnContext().
turnContextEnricher?
Section titled “turnContextEnricher?”ITurnContextEnricher
Optional enricher for immediate message context
isNewTurn?
Section titled “isNewTurn?”boolean
Whether this is the first message in a new turn
recoveryContext?
Section titled “recoveryContext?”Context enriched with messageHistory for agents that were just recovered
extractedContext?
Section titled “extractedContext?”unknown = ...
Structured context from compression (if hasCompression=true).
hasCompression?
Section titled “hasCompression?”boolean = ...
Whether compression is active (extractedContext present). If true, Agent should use fresh mode with compressed context.
hasConnectorSwap?
Section titled “hasConnectorSwap?”boolean = ...
Whether a connector swap occurred before this message (e.g., cwd/model change). If true, native resume is infeasible and adapters should use fresh mode.
hasNewTransforms?
Section titled “hasNewTransforms?”boolean = ...
Whether transforms have been applied since last turn. If true, Agent should use fresh mode (history changed).
isFirstTurn?
Section titled “isFirstTurn?”boolean = ...
Whether this is the first turn in the session. If true, no native history exists yet.
messageHistory?
Section titled “messageHistory?”object[] = ...
Curated message history assembled via getFullConversation(). Only used if Agent decides to inject (fresh mode).
turnContext?
Section titled “turnContext?”Record<string, JsonValue> = ...
Turn-scoped context assembled by PreUserMessage hooks and the orchestrator. Keys are plugin-defined (e.g., ‘skillCatalog’, ‘skills’, ‘predictedTools’). Adapters consume this to prepend context blocks.
Constrained to JSON-safe types to ensure serialization succeeds.
ADAPTER CONTRACT: Every adapter MUST materialize turnContext into the LLM-facing message using serializeTurnContext().
recoveredAgentIds?
Section titled “recoveredAgentIds?”ReadonlySet<string>
Set of agent IDs that were recovered in this handler invocation
swappedAgentIds?
Section titled “swappedAgentIds?”ReadonlySet<string>
Set of agent IDs that swapped connector due to cwd mismatch
swappedAgentCwd?
Section titled “swappedAgentCwd?”ReadonlyMap<string, CwdSwapMeta>
Previous/new cwd metadata keyed by agent ID
freshMessageHistory?
Section titled “freshMessageHistory?”object[]
Curated history for agents forced into fresh mode
Returns
Section titled “Returns”Promise<void>