Skip to main content
This section documents the interactive and programmatic interfaces provided by the Palyra CLI. It covers the Terminal User Interface (TUI) for human interaction, the Agent Control Protocol (ACP) bridge for tool-based integration, and the management commands for agents and sessions.

Terminal User Interface (TUI)

The Palyra TUI is a ratatui-based interactive environment that allows users to chat with agents, manage sessions, and approve tool executions directly from the terminal. It is implemented in crates/palyra-cli/src/tui/mod.rs crates/palyra-cli/src/tui/mod.rs#12-19.

TUI Architecture and State Management

The TUI is driven by the App struct, which maintains the session state, transcript history, and active gRPC streams crates/palyra-cli/src/tui/mod.rs#107-131.
ComponentRole
OperatorRuntimeManages gRPC communication with the palyrad gateway crates/palyra-cli/src/client/operator.rs#15-17.
ManagedRunStreamWraps the bidirectional gRPC stream, handling asynchronous events and control signals crates/palyra-cli/src/client/operator.rs#31-35.
TranscriptEntryRepresents a single turn in the conversation (User, Assistant, Tool, etc.) crates/palyra-cli/src/tui/mod.rs#93-98.
PickerStateManages selection UI for agents, sessions, or models crates/palyra-cli/src/tui/mod.rs#75-81.

Run Loop and Event Handling

The TUI uses a standard crossterm event loop crates/palyra-cli/src/tui/mod.rs#149-165. It polls for terminal input while simultaneously draining events from the active_stream crates/palyra-cli/src/tui/mod.rs#151-152.

Bridge: TUI Code Entity Space

The following diagram illustrates how TUI visual components map to the underlying Rust structs and the gRPC communication layer. TUI System Mapping Sources: crates/palyra-cli/src/tui/mod.rs#107-131, crates/palyra-cli/src/client/operator.rs#15-35, crates/palyra-cli/src/client/runtime.rs#9-12

Agent Control Protocol (ACP) Bridge

The ACP bridge implements a stdio-based protocol that allows external editors or tools to control Palyra agents. It translates ACP JSON-RPC messages into Palyra gRPC calls.

Bridge Implementation

The bridge is implemented in crates/palyra-cli/src/acp_bridge.rs. It maintains a BridgeState to track active sessions and runs crates/palyra-cli/src/acp_bridge.rs#38-42. Key features include:

ACP to gRPC Data Flow

Sources: crates/palyra-cli/src/acp_bridge.rs#100-131, crates/palyra-cli/src/client/operator.rs#137-148

Agent & Session Commands

The CLI provides extensive commands for managing the lifecycle of agents and their associated conversation sessions.

Agent Management

Agent commands are handled in crates/palyra-cli/src/commands/agents.rs and interact with the GatewayServiceClient crates/palyra-cli/src/commands/agents.rs#29-31.

Session Management

Session commands are implemented in crates/palyra-cli/src/commands/sessions.rs. These commands support both administrative operations and conversational history.

Interactive Mode

The agent interactive command provides a simplified line-based chat interface as an alternative to the full TUI. It supports slash commands such as /exit, /help, /session, and /reset crates/palyra-cli/src/commands/agent.rs#139-190. Command Entity Mapping Sources: crates/palyra-cli/src/commands/agent.rs#27-30, crates/palyra-cli/src/commands/agents.rs#3-12, crates/palyra-cli/src/commands/sessions.rs#3-11