AcpBridge, which translates the JSON-RPC based ACP over stdio into the high-performance gRPC streams used by the Palyra daemon.
Architecture and Data Flow
The ACP Bridge acts as a protocol translator. It consumes standard input from a parent process (e.g., VS Code or Cursor), parses ACP JSON-RPC messages, and invokes corresponding methods on theGatewayRuntimeClient. Results and events from the gateway are then serialized back to standard output as ACP-compliant notifications or responses.
Protocol Mapping Diagram
The following diagram illustrates how “Natural Language Space” (ACP JSON-RPC) maps to “Code Entity Space” (gRPC/Rust structs). Sources: crates/palyra-cli/src/acp_bridge.rs#30-63, crates/palyra-cli/src/client/operator.rs#137-151, crates/palyra-cli/src/client/runtime.rs#203-215The AcpBridge Implementation
The core of the ACP integration is thePalyraAcpAgent struct. It maintains the mapping between ACP session IDs and Palyra’s internal ULID-based session identifiers.
Key Components
| Component | Code Entity | Responsibility |
|---|---|---|
| Agent State | BridgeState | Tracks active SessionBinding and active_runs crates/palyra-cli/src/acp_bridge.rs#38-42. |
| Protocol Handler | PalyraAcpAgent | Implements the acp::Client trait to handle incoming requests crates/palyra-cli/src/acp_bridge.rs#56-63. |
| Stream Manager | ManagedRunStream | Wraps the gRPC bidirectional stream for tool interaction crates/palyra-cli/src/client/operator.rs#31-35. |
| Permission Bridge | ClientBridgeRequest | Dispatches permission requests (e.g., tool execution approval) back to the ACP client crates/palyra-cli/src/acp_bridge.rs#44-53. |
Session Resolution Logic
When an external tool initiates a session, the bridge usesSessionMetaOverrides to determine if a specific sessionKey or sessionLabel is required. It then calls OperatorRuntime::resolve_session to establish the connection to the daemon.
Sources: crates/palyra-cli/src/acp_bridge.rs#163-170, crates/palyra-cli/src/acp_bridge.rs#100-116, crates/palyra-cli/src/client/operator.rs#112-118
Legacy Compatibility and Shims
To support older integration patterns and ensure a stable surface for third-party developers, the CLI provides specific shim commands.ACP Shim Commands
palyra acp: The primary entry point for modern ACP integrations crates/palyra-cli/src/commands/agent.rs#111.palyra agent acp-shim: A compatibility layer for legacy tool versions crates/palyra-cli/src/commands/agent.rs#110.
allow_sensitive_tools and identity verification via AgentConnection crates/palyra-cli/src/acp_bridge.rs#56-63.
Integration with External Tools
External tools typically integrate by spawning the Palyra CLI in ACP mode:palyra acp run --session-key <KEY>
Permission Handling
ACP allows for granular permission requests. When the Palyra gateway encounters a tool call requiring human-in-the-loop (HITL) approval, theAcpBridge sends a RequestPermission message to the IDE. The IDE can respond with:
allow-onceallow-alwaysreject-oncereject-always
common_v1::ToolApprovalResponse and sent back through the ManagedRunStream to the orchestrator.
Sources: crates/palyra-cli/src/acp_bridge.rs#25-28, crates/palyra-cli/src/acp_bridge.rs#118-131, crates/palyra-cli/src/client/operator.rs#50-68
Summary of Key Functions
| Function | Location | Description |
|---|---|---|
run_agent_interactive_async | crates/palyra-cli/src/commands/agent.rs#115 | Manages the interactive loop for standard input/output. |
execute_agent_stream | crates/palyra-cli/src/commands/agent.rs#73 | Low-level execution of a gRPC run stream. |
send_session_update | crates/palyra-cli/src/acp_bridge.rs#100 | Dispatches ACP notifications back to the tool. |
build_agent_run_input | crates/palyra-cli/src/commands/agent.rs#60 | Constructs the gRPC payload from CLI/ACP arguments. |