bodhi-realtime-agent / AgentRouter
Class: AgentRouter
Defined in: src/agent/agent-router.ts:68
Manages agent lifecycle: transfers between MainAgents and handoffs to background subagents.
Transfer flow (agent → agent): onExit → agent.exit event → TRANSFERRING → buffer audio → disconnect → reconnect with new agent config → replay context + buffered audio → ACTIVE → onEnter → agent.enter event → agent.transfer event
Handoff flow (background tool → subagent): Create AbortController → build context snapshot → agent.handoff event → runSubagent() async → return SubagentResult
Constructors
Constructor
new AgentRouter(
sessionManager,eventBus,hooks,conversationContext,transport,clientTransport,model,getInstructionSuffix?,extraTools?,subagentCallbacks?,externalAudioCallbacks?,getMemoryFacts?,getKnowledgeBaseContext?):AgentRouter
Defined in: src/agent/agent-router.ts:78
Parameters
sessionManager
eventBus
hooks
conversationContext
transport
clientTransport
model
LanguageModelV1
getInstructionSuffix?
() => string
extraTools?
ToolDefinition[] = []
subagentCallbacks?
externalAudioCallbacks?
ExternalAudioCallbacks
getMemoryFacts?
() => MemoryFact[]
Cached user memory facts for subagent system prompts (VoiceSession wires from MemoryCacheManager).
getKnowledgeBaseContext?
() => string | undefined
Prompt-injected KB text for the active main agent (VoiceSession wires from processed KB).
Returns
AgentRouter
Properties
drainBufferedInbound?
optionaldrainBufferedInbound?: () =>Buffer<ArrayBufferLike>[]
Defined in: src/agent/agent-router.ts:76
H2 gate-aware transfer drain (set by VoiceSession): filters capture-tagged inbound frames and transform-sends admitted ones.
Returns
Buffer<ArrayBufferLike>[]
responseModality?
optionalresponseModality?:"text"|"audio"
Defined in: src/agent/agent-router.ts:73
Response modality to include in transfer SessionUpdate (set by VoiceSession for TTS).
Accessors
activeAgent
Get Signature
get activeAgent():
MainAgent
Defined in: src/agent/agent-router.ts:110
Returns
activeSubagentCount
Get Signature
get activeSubagentCount():
number
Defined in: src/agent/agent-router.ts:370
Returns
number
Methods
cancelSubagent()
cancelSubagent(
toolCallId):void
Defined in: src/agent/agent-router.ts:361
Abort a running background subagent by its originating tool call ID.
Parameters
toolCallId
string
Returns
void
findSessionByRequestId()
findSessionByRequestId(
requestId):SubagentSession|null
Defined in: src/agent/agent-router.ts:249
Find the SubagentSession that has a pending UI request with the given requestId.
Parameters
requestId
string
Returns
SubagentSession | null
getSubagentSession()
getSubagentSession(
toolCallId):SubagentSession|null
Defined in: src/agent/agent-router.ts:244
Look up the SubagentSession for an active interactive subagent, or null.
Parameters
toolCallId
string
Returns
SubagentSession | null
handoff()
handoff(
toolCall,subagentConfig,externalSignal?):Promise<SubagentResult>
Defined in: src/agent/agent-router.ts:264
Spawn a background subagent to handle a tool call asynchronously.
Parameters
toolCall
subagentConfig
externalSignal?
AbortSignal
Returns
Promise<SubagentResult>
Deprecated
Use SubagentSupervisorActor via RuntimeOrchestrator instead. Retained for backward compatibility during the actor runtime transition.
registerAgents()
registerAgents(
agents):void
Defined in: src/agent/agent-router.ts:96
Parameters
agents
Returns
void
setInitialAgent()
setInitialAgent(
agentName):void
Defined in: src/agent/agent-router.ts:102
Parameters
agentName
string
Returns
void
transfer()
transfer(
toAgentName):Promise<void>
Defined in: src/agent/agent-router.ts:125
Transfer the active LLM session to a different agent. Uses transport.transferSession() — the transport decides whether to apply in-place (OpenAI session.update) or reconnect-based (Gemini).
Parameters
toAgentName
string
Returns
Promise<void>
Deprecated
Use MainAgentActor via RuntimeOrchestrator instead. Retained for backward compatibility during the actor runtime transition.