Skip to main content
Use autoplay_sdk.agent_state.v2 (SessionState) as the only supported agent-state model.

SessionState v2

Overview

autoplay_sdk.agent_state.v2 provides the supported three-state FSM and enforces a clear timeout-only exit rule from active states. Timeouts and cooldowns are session-level settings rather than per-trigger values.

States

Transition rules

_timeout_to_thinking() is a private method called exclusively by tick(). Never call it directly in your code β€” use tick() on every incoming event or background pulse instead.

Session-level timeout settings

Session-owned routing fields

These fields are persisted directly on SessionState and are the canonical delivery routing source: SessionState.on_conversation_linked(link) transition rules:
  • ConversationEventType.NEW: always set conversation_linked=True and overwrite conversation_id
  • ConversationEventType.REPLY_EXISTING: set link fields only when currently unlinked; keep existing conversation_id when already linked
  • invariant: during a live session, this path never flips conversation_linked back to False

State and flag matrix

Per-state sub-dataclasses

Each state carries a typed sub-object that tracks its own metrics. These are reset when the session enters that state. ThinkingState ProactiveState ReactiveState

Public exports

Import InvalidTransitionError from autoplay_sdk.agent_state.v2 with the rest of the v2 symbols.

Key methods

Persistence

Session scope is primary: persist/load by session_id, and treat conversation_id as derived session-owned routing state.

Example

See also