Skip to content

API Reference parrot.human.channels.cli

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

parrot.human.channels.cli

View source

CLI Human Channel for AI-Parrot HITL.

Interactive terminal channel that renders questions using Rich and captures responses via stdin. Supports two modes:

  1. INTERACTIVE (default): Prompt appears directly in the terminal where the agent runs. Ideal for development and active monitoring.

  2. DAEMON: Questions are published to a Redis queue. A separate CLI companion process (cli_companion.py) reads and responds. Used when the agent runs as a background service.

The CLI channel is "local" by definition — the human who responds is whoever has access to the terminal. The recipient ID is typically "local" or a user identifier for the daemon queue.

Class CLIDaemonHumanChannel

CLI channel for when the agent runs as a daemon/background service.

Interactions are published to a Redis queue. A separate CLI companion process reads them and lets the human respond interactively.

The companion (cli_companion.py) subscribes to the queue, renders questions using the interactive CLIHumanChannel, and pushes responses back through Redis.

Parameter Type Default Description
redis Any Redis client instance (asyncio-compatible).
queue_prefix str 'hitl:cli_queue' Redis key prefix for the interaction queues.

Method CLIDaemonHumanChannel.register_response_handler

Register the manager's response callback.

register_response_handler(callback: Callable[[HumanResponse], Awaitable[None]]) -> None

Parameter Type Default Description
callback Callable[[HumanResponse], Awaitable[None]]

Method CLIDaemonHumanChannel.send_interaction

Publish interaction to Redis queue for the CLI companion.

send_interaction(interaction: HumanInteraction, recipient: str) -> bool

Parameter Type Default Description
interaction HumanInteraction
recipient str

Returns: bool

Method CLIDaemonHumanChannel.send_notification

Send notification via Redis queue.

send_notification(recipient: str, message: str) -> None

Parameter Type Default Description
recipient str
message str

Method CLIDaemonHumanChannel.cancel_interaction

Publish cancellation event.

Returns True when the publish succeeded, False if Redis raised.

cancel_interaction(interaction_id: str, recipient: str) -> bool

Parameter Type Default Description
interaction_id str
recipient str

Returns: bool

Method CLIDaemonHumanChannel.start_response_listener

Listen for responses from the CLI companion.

Runs as a background asyncio task in the agent worker process. Picks up responses pushed to the Redis queue by the companion.

start_response_listener(recipient: str) -> None

Parameter Type Default Description
recipient str

Class CLIHumanChannel

Interactive CLI channel for Human-in-the-Loop.

Renders interaction prompts in the terminal using Rich and captures human responses via stdin. Uses asyncio.run_in_executor to avoid blocking the event loop during input().

This is a production-grade channel — not just for testing. If you're running agents from your terminal and want to answer questions directly, this is the channel to use.

Parameter Type Default Description
console Optional[Any] None Rich Console instance (created if not provided).
prompt_prefix str '🧑 Human' Prefix shown before user input prompts.
show_context bool True Whether to display interaction context.
input_timeout Optional[int] None Optional local timeout for input in seconds. None means no local timeout (global interaction timeout still applies via the manager).

Method CLIHumanChannel.register_response_handler

Register the manager's response callback.

register_response_handler(callback: Callable[[HumanResponse], Awaitable[None]]) -> None

Parameter Type Default Description
callback Callable[[HumanResponse], Awaitable[None]]

Method CLIHumanChannel.send_interaction

Display the interaction in the terminal and capture the response.

Uses run_in_executor for all input() calls to keep the asyncio event loop free.

send_interaction(interaction: HumanInteraction, recipient: str) -> bool

Parameter Type Default Description
interaction HumanInteraction
recipient str

Returns: bool

Method CLIHumanChannel.send_notification

Display a notification in the terminal.

send_notification(recipient: str, message: str) -> None

Parameter Type Default Description
recipient str
message str

Method CLIHumanChannel.cancel_interaction

Cancel a pending interaction.

Returns True if a pending interaction existed and was removed, False if nothing was tracked for interaction_id.

cancel_interaction(interaction_id: str, recipient: str) -> bool

Parameter Type Default Description
interaction_id str
recipient str

Returns: bool

Attribute HAS_RICH

Alias HumanChannel

Re-exported from parrot.human.channels.base.HumanChannel.

Alias HumanInteraction

Re-exported from parrot.human.models.HumanInteraction.

Alias HumanResponse

Re-exported from parrot.human.models.HumanResponse.

Alias InteractionType

Re-exported from parrot.human.models.InteractionType.

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