Skip to main content
This page documents the structured data exchange formats used within Palyra, focusing on the A2UI (Agent-to-UI) protocol, the Workspace Patch system, and the JSON schemas governing tool inputs and configuration. These protocols enable high-fidelity, incremental updates between the Rust-based daemon and the React-based web console.

A2UI: Agent-to-UI Protocol

The A2UI protocol allows agents to render complex, interactive interfaces within the Chat Console (Canvas). Unlike static Markdown, A2UI supports dynamic components like forms, tables, and charts that can be updated incrementally via JSON patches.

Data Flow & Rendering

The A2UI lifecycle begins with an A2uiDocument being emitted by the daemon. The frontend uses A2uiRenderer to transform this document into React components.
  1. Initial State: A full A2uiDocument is sent to the client.
  2. Patching: Subsequent updates are sent as PatchDocument objects containing PatchOperation arrays (e.g., replace, add, remove).
  3. Normalization: The frontend runs normalizeA2uiDocument to ensure the incoming JSON matches the expected TypeScript interfaces.
  4. Rendering: The A2uiRenderer iterates through document.components and delegates to specific sub-renderers.

A2UI Architecture

The following diagram illustrates the relationship between the A2UI TypeScript entities and the rendering logic. A2UI Entity to Code Mapping Sources: apps/web/src/a2ui/renderer.tsx#33-59, apps/web/src/a2ui/renderer.tsx#66-97, apps/web/src/a2ui/tests/renderer.snapshot.test.tsx#44-46

Supported Components

Component TypeRoleKey Props
textBasic text displayvalue, tone (e.g., info, error)
markdownRich text renderingvalue (sanitized)
tableTabular datacolumns, rows
formHuman-in-the-loop inputfields, submitLabel, title
chartData visualizationseries (bar charts)
Sources: apps/web/src/a2ui/renderer.tsx#67-94, apps/web/src/a2ui/renderer.tsx#99-123

Workspace Patch Protocol

The Workspace Patch system provides a secure, fail-closed mechanism for agents to modify files within a user’s local workspace. It is defined in the palyra-common crate and includes strict limits and redaction policies.

Implementation Details

The core logic resides in apply_workspace_patch. It follows a Plan -> Validate -> Execute flow:
  1. Parsing: The patch string is parsed into a series of PatchOperation (Add, Update, Delete).
  2. Validation: Paths are checked against workspace_roots to prevent directory traversal.
  3. Limits: WorkspacePatchLimits enforces maximum bytes and file counts.
  4. Execution: Changes are applied atomically. If a failure occurs, a best-effort rollback is performed.
Workspace Patch Data Flow Sources: crates/palyra-common/src/workspace_patch.rs#207-213, crates/palyra-common/src/workspace_patch.rs#23-39, crates/palyra-common/src/workspace_patch.rs#184-193

Key Structures

Tool Input Schemas

Tools in Palyra consume JSON payloads that must strictly adhere to predefined schemas. This is enforced during the decide_tool_call phase in the daemon.

Process Runner Input

The palyra.process.run tool uses the ProcessRunnerToolInput struct. It enforces deny_unknown_fields to prevent unexpected parameters from reaching the shell.
FieldTypeDescription
commandStringThe executable to run.
argsVec<String>List of arguments.
cwdOption<String>Working directory relative to workspace root.
requested_egress_hostsVec<String>Network hosts the process needs to access.
Sources: crates/palyra-common/src/process_runner_input.rs#7-17, crates/palyra-common/src/process_runner_input.rs#26-31

Validation & Fuzzing

To ensure the robustness of JSON parsing across the monorepo, several fuzzing targets are maintained in the fuzz/ directory. These targets subject the parsers to arbitrary byte streams to detect crashes or hangs. Sources: fuzz/Cargo.toml#19-79