Skip to content

API Reference parrot.cli.session

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

parrot.cli.session

View source

Turn execution boundary for the parrot agent presenters (FEAT-573, spec §3 M5).

Only this module calls bot.ask / bot.ask_stream. Both the inline REPL and the Textual workspace consume the TurnEvent stream produced here.

Alias AfterToolCallEvent

Re-exported from parrot.core.events.lifecycle.AfterToolCallEvent.

Alias BackendCapabilities

Re-exported from parrot.cli.events.BackendCapabilities.

Alias BeforeToolCallEvent

Re-exported from parrot.core.events.lifecycle.BeforeToolCallEvent.

Alias ConversationTurn

Re-exported from parrot.cli.commands.ConversationTurn.

Alias OutputMode

Re-exported from parrot.models.outputs.OutputMode.

Alias TextDelta

Re-exported from parrot.cli.events.TextDelta.

Alias ToolCall

Re-exported from parrot.models.basic.ToolCall.

Alias ToolCallFailedEvent

Re-exported from parrot.core.events.lifecycle.ToolCallFailedEvent.

Alias ToolFailed

Re-exported from parrot.cli.events.ToolFailed.

Alias ToolFinished

Re-exported from parrot.cli.events.ToolFinished.

Alias ToolStarted

Re-exported from parrot.cli.events.ToolStarted.

Alias TurnCancelled

Re-exported from parrot.cli.events.TurnCancelled.

Alias TurnCompleted

Re-exported from parrot.cli.events.TurnCompleted.

Alias TurnEvent

Re-exported from parrot.cli.events.TurnEvent.

Alias TurnFailed

Re-exported from parrot.cli.events.TurnFailed.

Class TurnInProgressError

Raised by :meth:TurnRunner.run_turn while another turn is active (one turn per session).

Class TurnRunner

Run conversation turns against a bot-like backend and yield TurnEvents.

Identity kwargs are exactly those AgentREPL passes today (repl.py:212-218, :249-255): session_id, user_id, output_mode=OutputMode.TERMINAL, permission_context. user_id=None is omitted from the call.

Parameter Type Default Description
bot Any
config Any
capabilities Optional[BackendCapabilities] None

Attributes:

Attribute Type Description
history List[ConversationTurn]
capabilities BackendCapabilities
is_active bool

Method TurnRunner.run_turn

Yield TurnStarted, then TextDelta/Tool* events, then exactly one terminal event.

run_turn(query: str) -> AsyncIterator[TurnEvent]

Parameter Type Default Description
query str

Returns: AsyncIterator[TurnEvent]

Method TurnRunner.cancel

Cancel the active turn's task; True if one was active.

Relies on self._active_task -- the caller's own task, captured by run_turn() via asyncio.current_task() -- so this only cancels anything when the caller wraps turn-consumption in a dedicated task (as the inline REPL's _turn_with_cancel and the TUI's action_cancel_turn both do). A caller that drives run_turn() directly on its own task (no wrapper) has nothing for this to cancel.

cancel() -> bool

Returns: bool

Method TurnRunner.load_history

Resume: map bot.get_conversation_history(user_id, session_id) turns to CLI turns.

load_history(session_id: str) -> List[ConversationTurn]

Parameter Type Default Description
session_id str

Returns: List[ConversationTurn]

Method TurnRunner.reset_session

New session id (/clear semantics, commands.py:228-230); clears history.

reset_session() -> str

Returns: str

Method TurnRunner.add_post_turn_hook

Register a coroutine awaited after each COMPLETED turn.

The hook is awaited as hook(self, turn) — the TurnRunner itself stands in for CommandContext here, since this module has no presenter reference. A presenter implementing the richer CommandContext protocol (e.g. AgentREPL, TASK-3407) should wrap the hook to close over its own ctx before delegating registration to :meth:add_post_turn_hook.

add_post_turn_hook(hook: _RunnerPostTurnHook) -> None

Parameter Type Default Description
hook _RunnerPostTurnHook

Alias TurnStarted

Re-exported from parrot.cli.events.TurnStarted.

Alias get_global_registry

Re-exported from parrot.core.events.lifecycle.get_global_registry.

Alias in_turn_scope

Re-exported from parrot.core.events.lifecycle.turn_scope.in_turn_scope.

Alias save_session_pointer

Re-exported from parrot.cli.modes.save_session_pointer.

Alias summarize_message_text

Re-exported from parrot.cli.events.summarize_message_text.

Alias turn_scope

Re-exported from parrot.core.events.lifecycle.turn_scope.turn_scope.

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