Function: routeToAgentsCore()
Makaio Framework / services-core / routeToAgentsCore
Function: routeToAgentsCore()
Section titled “Function: routeToAgentsCore()”routeToAgentsCore(
bus,session,agents,message,messageId,turn,deliveryMode,onTurnComplete,sessionContext?):Promise<void>
Defined in: ../../../packages/services/core/src/session/handlers/route-to-agents-core.ts:35
Route a message to target agents using a single shared session context.
Fans out to all agents in parallel. On routing failure, marks the agent
as errored and checks for turn completion. On HookAbortError, marks
the agent as completed with cancelled outcome.
Parameters
Section titled “Parameters”Bus instance for communication
session
Section titled “session”Session metadata (for session ID)
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 to the agent
onTurnComplete
Section titled “onTurnComplete”Callback invoked when the turn completes (all agents done)
sessionContext?
Section titled “sessionContext?”Optional shared session context forwarded to all agents
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().
Returns
Section titled “Returns”Promise<void>