DefaultAgentStateController
Default agent state controller extracted from Runtime.
Handles:
- Active agent resolution with fallback
- Handoff recording in session.handoffHistory + session.metadata.handoffHistory
- Per-agent state updates in session.agentStates
- Circular handoff detection
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new DefaultAgentStateController(): DefaultAgentStateController;Returns
Section titled “Returns”DefaultAgentStateController
Methods
Section titled “Methods”clearAgent()
Section titled “clearAgent()”clearAgent(session, agentId): void;Remove per-agent state from session.agentStates. No-op if absent.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
|
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”AgentStateController.clearAgent
getActiveAgent()
Section titled “getActiveAgent()”getActiveAgent(session, fallbackAgentId): string;Resolve the active agent ID, falling back to the provided default.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
|
Returns
Section titled “Returns”string
Implementation of
Section titled “Implementation of”AgentStateController.getActiveAgent
getAgentState()
Section titled “getAgentState()”getAgentState<T>(session, agentId): T | undefined;Read per-agent state with optional type assertion. Returns undefined if absent or empty.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
|
Returns
Section titled “Returns”T | undefined
Implementation of
Section titled “Implementation of”AgentStateController.getAgentState
isCircularHandoff()
Section titled “isCircularHandoff()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”boolean
Implementation of
Section titled “Implementation of”AgentStateController.isCircularHandoff
recordHandoff()
Section titled “recordHandoff()”recordHandoff(args): void;Record a handoff in the session’s handoff history.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”AgentStateController.recordHandoff
setActiveAgent()
Section titled “setActiveAgent()”setActiveAgent(session, agentId): void;Set the active agent on the session.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
|
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”AgentStateController.setActiveAgent
setAgentState()
Section titled “setAgentState()”setAgentState( session, agentId, state): void;Replace per-agent state fully (no merge). Use when the state is a single opaque blob.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”AgentStateController.setAgentState
updateAgentState()
Section titled “updateAgentState()”updateAgentState( session, agentId, state): void;Update per-agent state stored in session.agentStates. Merges with existing state.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
|
|
|
|
Returns
Section titled “Returns”void