Skip to content

API Reference parrot.human.suspended_store

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

parrot.human.suspended_store

View source

Suspended-execution store for the stateless Web HITL suspend/resume path.

FEAT-204 / TASK-1380

When an agent tool raises :class:~parrot.core.exceptions.HumanInteractionInterrupt in SUSPEND mode, the HTTP handler must serialise the in-flight tool-loop state so a later hitl_response request can reload it and call agent.resume().

This module provides:

  • :class:SuspendedExecution — Pydantic v2 model holding the tool-loop state blob (messages, tool_call_id, agent_name, session_id, user_id).
  • :class:SuspendedExecutionStore — thin Redis-backed store that saves/loads blobs under hitl:suspended:{interaction_id} with a TTL aligned to the matching hitl:interaction:{id} key.

The delete method removes ONLY the suspended key — the interaction key is left intact so that the escalation sweeper (future feature) can still observe pending interactions via TTL expiry.

Class SuspendedExecution

Tool-loop state blob for a suspended HITL interaction.

Persisted to hitl:suspended:{interaction_id} in Redis with a TTL aligned to hitl:interaction:{id} (via :meth:HumanInteractionManager._compute_ttl). Rehydrated by the resume branch of AgentTalk.post so agent.resume() can inject the human's answer as the tool_result of the pending ask_human call.

Fields:

Field Type Default Description
interaction_id str UUID of the pending :class:~parrot.human.models.HumanInteraction.
session_id str Agent session identifier (forwarded to agent.resume).
user_id str Authenticated user who initiated the chat request.
agent_name str Name of the agent that was running when the interrupt fired.
tool_call_id str LLM tool-call ID of the pending ask_human invocation.
messages list[dict[str, Any]] Provider-shaped message history at the point of suspension. Stored as-is; agent.resume replays them without re-encoding.
created_at datetime UTC timestamp of when this record was created.

Class SuspendedExecutionStore

Redis-backed store for :class:SuspendedExecution blobs.

Key format: hitl:suspended:{interaction_id}

TTL is caller-provided (use :meth:~parrot.human.manager.HumanInteractionManager._compute_ttl so the suspended blob expires coherently with the interaction).

The delete method removes ONLY the suspended key — hitl:interaction:{id} is deliberately left intact (escalation seam; TTL-owned expiry).

Example::

store = SuspendedExecutionStore(redis_client)
await store.save(record, ttl=7260)
loaded = await store.load(record.interaction_id)
await store.delete(record.interaction_id)
Parameter Type Default Description
redis Any An redis.asyncio client (decode_responses=True recommended).

Method SuspendedExecutionStore.save

Persist a suspended-execution record to Redis with TTL.

save(record: SuspendedExecution, ttl: int) -> None

Parameter Type Default Description
record SuspendedExecution The :class:SuspendedExecution to persist.
ttl int Time-to-live in seconds (should match the interaction TTL). Values <= 0 are replaced with a 7260-second (2h+60s) fallback to prevent redis.exceptions.ResponseError from SETEX with a non-positive TTL.

Method SuspendedExecutionStore.load

Load a suspended-execution record from Redis.

load(interaction_id: str) -> Optional[SuspendedExecution]

Parameter Type Default Description
interaction_id str UUID of the pending interaction.

Returns: Optional[SuspendedExecution] — class:SuspendedExecution if found, None if expired or not yet saved.

Method SuspendedExecutionStore.delete

Remove the suspended-execution key from Redis.

This removes ONLY hitl:suspended:{interaction_id}. The hitl:interaction:{id} key is left intact so the escalation sweeper (future feature) can still observe pending interactions via TTL expiry.

delete(interaction_id: str) -> None

Parameter Type Default Description
interaction_id str UUID of the pending interaction.

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