Skip to content

AgentStateController

Manages active agent resolution, handoff recording, and agent state. Shared by Runtime and VoiceEngine.

clearAgent(session, agentId): void;

Remove per-agent state from session.agentStates. No-op if absent.

Parameter Type

session

Session

agentId

string

void


getActiveAgent(session, fallbackAgentId): string;

Resolve the active agent ID, falling back to the provided default.

Parameter Type

session

Session

fallbackAgentId

string

string


getAgentState<T>(session, agentId): T | undefined;

Read per-agent state with optional type assertion. Returns undefined if absent or empty.

Type Parameter Default type

T

Record<string, unknown>

Parameter Type

session

Session

agentId

string

T | undefined


isCircularHandoff(
handoffStack,
agentId,
maxVisits?): boolean;

Check whether visiting the given agent would constitute a circular handoff. Returns true if the agent has been visited >= maxVisits times in the handoff stack.

Parameter Type

handoffStack

string[]

agentId

string

maxVisits?

number

boolean


recordHandoff(args): void;

Record a handoff in the session’s handoff history.

Parameter Type

args

{ fromAgentId: string; reason: string; session: Session; toAgentId: string; }

args.fromAgentId

string

args.reason

string

args.session

Session

args.toAgentId

string

void


setActiveAgent(session, agentId): void;

Set the active agent on the session.

Parameter Type

session

Session

agentId

string

void


setAgentState(
session,
agentId,
state): void;

Replace per-agent state fully (no merge). Use when the state is a single opaque blob.

Parameter Type

session

Session

agentId

string

state

Record<string, unknown>

void


updateAgentState(
session,
agentId,
state): void;

Update per-agent state stored in session.agentStates. Merges with existing state.

Parameter Type

session

Session

agentId

string

state

Record<string, unknown>

void