Gets the current state.
Gets the transition history.
Gets the current error count.
Checks if a transition is valid from the current state.
Gets the next state for an event, if valid.
Gets all valid events from the current state.
Attempts a state transition.
The event triggering the transition
Optionalcontext: Record<string, unknown>Optional context data for the transition
Result with the new state or an AgentError
Forces a transition to the error state. Use for unrecoverable errors that should bypass normal transition rules.
Optionalcontext: Record<string, unknown>Optional context data about the error
Attempts recovery from the error state.
Optionalcontext: Record<string, unknown>Optional context data about the recovery
Result with the new state or an AgentError if recovery failed
Resets the error count. Call after successful task completion.
Resets the state machine to its initial state.
Whether to clear the transition history
Subscribes to state change events.
Callback to invoke on state changes
Unsubscribe function
Subscribes to transition error events.
Callback to invoke on transition errors
Unsubscribe function
Checks if the agent is in a state where it can accept new tasks.
Checks if the agent is currently working.
Checks if the agent is in an error state.
Agent State Machine.
Manages agent lifecycle states with validation, event callbacks, and error recovery mechanisms.