Skip to content

API Reference parrot.integrations.core.state

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.core.state

View source

Class InMemoryStateStore

Simple in-memory key-value store with TTL support.

Used as a fallback when no persistent store (e.g., Redis) is available.

.. warning:: Memory leak risk — this store holds all keys in memory indefinitely unless they are explicitly deleted or their TTL is checked on access. Entries with an expire value are evicted lazily on get() and swept proactively (via :meth:_sweep_expired) whenever the store exceeds _SWEEP_THRESHOLD entries. For production workloads with high message volumes, replace this with a real Redis-backed store.

Method InMemoryStateStore.set

set(key: str, value: str, expire: int = 0) -> None

Parameter Type Default Description
key str
value str
expire int 0

Method InMemoryStateStore.get

get(key: str) -> Optional[str]

Parameter Type Default Description
key str

Returns: Optional[str]

Method InMemoryStateStore.delete

delete(key: str) -> None

Parameter Type Default Description
key str

Class IntegrationStateManager

Manages state for chat integrations (Telegram, MS Teams, Slack, Matrix).

Tracks when a user in a specific chat context is waiting for a handoff response (Human-in-the-Loop) rather than starting a new conversation turn.

Parameter Type Default Description
store Any None Persistent store implementation (e.g., RedisStore). Falls back to an in-memory store if not provided.

Method IntegrationStateManager.set_suspended_state

Mark a user/chat context as suspended, waiting for human input.

set_suspended_state(integration_id: str, chat_id: str, user_id: str, session_id: str, agent_name: str, execution_state: str = 'handoff_waiting') -> bool

Parameter Type Default Description
integration_id str Platform name (e.g., 'telegram', 'msteams')
chat_id str Chat/Channel ID
user_id str User ID
session_id str The execution session ID to resume later
agent_name str Name of the agent that was executing
execution_state str 'handoff_waiting' String describing the state

Returns: bool — True if successful

Method IntegrationStateManager.get_suspended_session

Check if there's a suspended session for this user/chat context.

get_suspended_session(integration_id: str, chat_id: str, user_id: str) -> Optional[Dict[str, Any]]

Parameter Type Default Description
integration_id str Identifier for the integration (e.g., 'telegram', 'slack')
chat_id str The chat or channel ID
user_id str The user ID within the integration

Returns: Optional[Dict[str, Any]] — The suspended state dictionary if one exists, None otherwise.

Method IntegrationStateManager.clear_suspended_state

Clear the suspended state for a user context. Call this after successfully resuming the agent.

clear_suspended_state(integration_id: str, chat_id: str, user_id: str) -> bool

Parameter Type Default Description
integration_id str Platform name
chat_id str Chat/Channel ID
user_id str User ID

Returns: bool — True if successful

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally