Skip to content

Function: routeToAgents()

Makaio Framework


Makaio Framework / services-core / 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.

IMakaioBus

Bus instance for communication

IMakaioSession

Session metadata (for fork detection)

object[]

Target agents to route to

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

string

Message identifier

Turn

Turn tracking object

"enqueue" | "immediate" | undefined

How to deliver the message

(turn, result) => Promise<void>

Callback when turn completes (all agents done)

Session context with curated messageHistory and decision signals

unknown = ...

Structured context from compression (if hasCompression=true).

boolean = ...

Whether compression is active (extractedContext present). If true, Agent should use fresh mode with compressed context.

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.

boolean = ...

Whether transforms have been applied since last turn. If true, Agent should use fresh mode (history changed).

boolean = ...

Whether this is the first turn in the session. If true, no native history exists yet.

object[] = ...

Curated message history assembled via getFullConversation(). Only used if Agent decides to inject (fresh mode).

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().

ITurnContextEnricher

Optional enricher for immediate message context

boolean

Whether this is the first message in a new turn

Context enriched with messageHistory for agents that were just recovered

unknown = ...

Structured context from compression (if hasCompression=true).

boolean = ...

Whether compression is active (extractedContext present). If true, Agent should use fresh mode with compressed context.

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.

boolean = ...

Whether transforms have been applied since last turn. If true, Agent should use fresh mode (history changed).

boolean = ...

Whether this is the first turn in the session. If true, no native history exists yet.

object[] = ...

Curated message history assembled via getFullConversation(). Only used if Agent decides to inject (fresh mode).

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().

ReadonlySet<string>

Set of agent IDs that were recovered in this handler invocation

ReadonlySet<string>

Set of agent IDs that swapped connector due to cwd mismatch

ReadonlyMap<string, CwdSwapMeta>

Previous/new cwd metadata keyed by agent ID

object[]

Curated history for agents forced into fresh mode

Promise<void>