Skip to content

bodhi-realtime-agent / AgentRouter

Class: AgentRouter

Defined in: agent/agent-router.ts:48

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?): AgentRouter

Defined in: agent/agent-router.ts:53

Parameters

sessionManager

SessionManager

eventBus

IEventBus

hooks

HooksManager

conversationContext

ConversationContext

transport

LLMTransport

clientTransport

ClientTransport

model

LanguageModelV1

getInstructionSuffix?

() => string

extraTools?

ToolDefinition[] = []

subagentCallbacks?

SubagentEventCallbacks

Returns

AgentRouter

Accessors

activeAgent

Get Signature

get activeAgent(): MainAgent

Defined in: agent/agent-router.ts:80

Returns

MainAgent


activeSubagentCount

Get Signature

get activeSubagentCount(): number

Defined in: agent/agent-router.ts:276

Returns

number

Methods

cancelSubagent()

cancelSubagent(toolCallId): void

Defined in: agent/agent-router.ts:267

Abort a running background subagent by its originating tool call ID.

Parameters

toolCallId

string

Returns

void


findSessionByRequestId()

findSessionByRequestId(requestId): SubagentSession | null

Defined in: agent/agent-router.ts:194

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: agent/agent-router.ts:189

Look up the SubagentSession for an active interactive subagent, or null.

Parameters

toolCallId

string

Returns

SubagentSession | null


handoff()

handoff(toolCall, subagentConfig): Promise<SubagentResult>

Defined in: agent/agent-router.ts:204

Spawn a background subagent to handle a tool call asynchronously.

Parameters

toolCall

ToolCall

subagentConfig

SubagentConfig

Returns

Promise<SubagentResult>


registerAgents()

registerAgents(agents): void

Defined in: agent/agent-router.ts:66

Parameters

agents

MainAgent[]

Returns

void


setInitialAgent()

setInitialAgent(agentName): void

Defined in: agent/agent-router.ts:72

Parameters

agentName

string

Returns

void


transfer()

transfer(toAgentName): Promise<void>

Defined in: agent/agent-router.ts:92

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>

Built with VitePress