Skip to content

API Reference parrot.human.models

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

parrot.human.models

View source

Core data models for the Human-in-the-Loop system.

Class BusinessHours

Defines a business-hours window for an escalation tier.

When EscalationTier.business_hours is set, the manager will only dispatch that tier if the current time (in the given timezone) falls within the window. Tiers whose window is currently closed are skipped.

Example::

bh = BusinessHours(tz="Europe/Madrid", days="mon-fri", hours="09:00-18:00")
bh.contains(datetime.now(pytz.timezone("Europe/Madrid")))

Fields:

Field Type Default Description
tz str IANA timezone name, e.g. "Europe/Madrid".
days str Day range or list, e.g. "mon-fri" or "mon,wed,fri".
hours str 24-hour window, e.g. "09:00-18:00".

Method BusinessHours.contains

Return True if now falls within this business-hours window.

contains(now: datetime) -> bool

Parameter Type Default Description
now datetime A timezone-aware datetime (or naive UTC will be treated as UTC).

Returns: bool — True if the day-of-week and time-of-day match the window.

Class ChoiceOption

A selectable option presented to the human.

Fields:

Field Type Default Description
key str
label str
description Optional[str] None
metadata Dict[str, Any]

Class ConsensusMode

How to consolidate responses when multiple humans are involved.

Class EscalationActionType

Actions performed when escalating to a tier.

Class EscalationPolicy

A series of tiered levels for escalating human-in-the-loop requests.

Fields:

Field Type Default Description
policy_id str
name str
tiers List[EscalationTier]

Method EscalationPolicy.select_starting_tier

Return the first applicable tier for the given severity and time.

A tier is considered applicable when:

  1. Its min_severity is <= severity (or min_severity is None).
  2. Its business_hours window includes now (or business_hours is None).

Tiers are evaluated in ascending level order. The first applicable tier is returned. None is returned when no tier currently applies (caller should treat this as a chain-exhausted / terminal CANCEL).

This is a pure method — no I/O, no logging.

select_starting_tier(severity: 'Severity', now: datetime) -> Optional['EscalationTier']

Parameter Type Default Description
severity 'Severity' The declared criticality of the interaction.
now datetime A timezone-aware datetime representing the current instant.

Returns: Optional['EscalationTier'] — The first applicable :class:EscalationTier, or None.

Class EscalationTier

Definition of a single level in an escalation policy.

Fields:

Field Type Default Description
level int 1-based tier ordering
name str
channel_type Optional[str] None Channel to dispatch this tier through. When None the manager falls back to the channel of the originating interaction.
target_humans List[str]
timeout float 3600.0 Seconds
action_type EscalationActionType EscalationActionType.INTERACT
action_metadata Dict[str, Any]
min_severity Optional[Severity] None Minimum severity required to START at this tier. Tiers with min_severity > requested severity are skipped during starting-tier selection.
business_hours Optional[BusinessHours] None Optional business-hours window for this tier. When set, the tier is only entered if 'now' falls within the window.

Class HumanInteraction

Represents a request for human input.

Fields:

Field Type Default Description
interaction_id str
question str
context Optional[str] None
interaction_type InteractionType InteractionType.FREE_TEXT
options Optional[List[ChoiceOption]] None
form_schema Optional[Dict[str, Any]] None
default_response Any None
target_humans List[str]
consensus_mode ConsensusMode ConsensusMode.FIRST_RESPONSE
timeout float 7200.0
timeout_action TimeoutAction TimeoutAction.CANCEL
escalation_targets List[str]
policy_id Optional[str] None
policy Optional[EscalationPolicy] None
current_tier_level int 0
severity Severity Severity.NORMAL Declared criticality of this interaction. The manager uses this to select the starting tier when a policy is active.
source_agent Optional[str] None
source_flow Optional[str] None
source_node Optional[str] None
channel Optional[str] None Name of the channel through which this interaction was first dispatched. Set by the manager in request_human_input/_dispatch_to_channel; used by advance_chain to target the same channel when re-escalating.
originator Optional[str] None Identifier of the end-user who triggered this interaction (e.g. their email or session id). Used for audit and as the CC recipient when a NOTIFY tier sets cc_originator.
notify_channel Optional[str] None How to reach the originator with status updates. May be the name of a registered HumanChannel (e.g. 'web', 'telegram', 'teams') to push an in-conversation notice, or an async-notify provider name (e.g. 'email', 'ses', 'sms', 'telegram') for an out-of-band notice.
notify_recipient Optional[str] None Address/id of the originator on notify_channel — a web session id, a Telegram chat id, an email address, a phone number, etc. Defaults to originator when omitted.
notify_provider_options Optional[Dict[str, Any]] None Runtime-only connection kwargs forwarded to the async-notify provider when notify_channel resolves to one (e.g. SMTP hostname/port, a Telegram bot_token). Intentionally excluded from serialization so credentials are never written to Redis. Populate from environment variables or a secrets manager at call time.
status InteractionStatus InteractionStatus.PENDING

Class HumanResponse

Response from a human to an interaction.

Fields:

Field Type Default Description
interaction_id str
respondent str
response_type InteractionType
value Any
timestamp datetime UTC timestamp when the response was captured
metadata Dict[str, Any]

Class InteractionResult

Consolidated result of an interaction after consensus evaluation.

Fields:

Field Type Default Description
interaction_id str
status InteractionStatus
responses List[HumanResponse]
consolidated_value Any None
timed_out bool False
escalated bool False
tier_level int 0
action_metadata Dict[str, Any]

Class InteractionStatus

Lifecycle status of a human interaction.

Class InteractionType

Type of interaction requested from the human.

Class Severity

Declared criticality of a human-interaction request.

Higher severity may cause the manager to skip lower-priority tiers and start at a more appropriate level per EscalationPolicy.select_starting_tier.

Class TimeoutAction

Action to take when an interaction times out.

Class WaitStrategy

Strategy that controls how HumanTool waits for the human response.

Attributes:

Attribute Type Description
BLOCK Default — registers an in-memory asyncio.Future and blocks the current coroutine until the human responds (or timeout). Suitable for live-channel deployments (Telegram, WebSocket long-poll).
SUSPEND Stateless web path — persists the interaction to Redis and raises HumanInteractionInterrupt immediately, allowing the HTTP handler to serialise tool-loop state and return a paused envelope. No in-process timer is relied upon.
HOT_THEN_SUSPEND Reserved for future live-channel + REST hybrid use. Currently treated the same as BLOCK.

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