Skip to main content
This page details the JSON-based contracts and schemas that govern communication between the Palyra daemon (palyrad), the Web Console, the Desktop Application, and the CLI. These contracts ensure type safety and structural consistency across disparate surfaces (Rust, TypeScript, and TUI).

Runtime Vocabulary and Shared Enums

Palyra uses a shared runtime vocabulary defined in the palyra-common crate. These enums are the source of truth for wire names used in JSON payloads, database records, and API responses.

Key Lifecycle Contracts

EnumPurposeCanonical Wire Values
RunLifecyclePhaseStates of an agent runqueued, running, waiting_for_approval, paused, completed, failed, aborted, expired
RunLifecycleHookPhasePlugin execution pointsbefore_run, before_tool, after_tool, before_delivery, after_run
AuxiliaryTaskKindTypes of side-taskssummary, recall_search, classification, extraction, objective_judge, vision
AuxiliaryTaskStateStatus of background workpending, running, succeeded, failed, cancelled
The runtime_contract_enum! macro in crates/palyra-common/src/runtime_contracts.rs#19-84 enforces case-insensitive parsing and provides backward-compatible aliases for legacy labels. Sources: crates/palyra-common/src/runtime_contracts.rs#87-101, crates/palyra-common/src/runtime_contracts.rs#117-126

A2UI: Agent-to-UI Updates

The A2UI (Agent-to-UI) system allows agents to push structured UI updates to the console. These updates are embedded within the RunStreamEvent envelopes and rendered by the Web Console.

Data Flow: Agent to Renderer

Sources: crates/palyra-daemon/src/application/run_stream/tape.rs#1-10, apps/web/src/styles.css#144-152

Cross-Surface Handoff Tokens

Cross-surface handoff allows a user to move from one Palyra interface (e.g., CLI/TUI) to another (e.g., Web Console) while maintaining context (session ID, run ID, or specific intent).

Handoff Schema (CrossSurfaceHandoff)

The handoff is typically encoded as URL query parameters or a JSON token.
FieldTypeDescription
sectionHandoffSectionTarget dashboard domain (e.g., approvals, chat, memory).
sessionIdstringThe active ULID for the chat session.
runIdstringThe specific run ULID to inspect.
intentHandoffIntentSpecific action: approve, resume-session, reopen-canvas, etc.
sourceTelemetrySurfaceOriginating surface: web, desktop, tui, mobile.
Implementation Details: Sources: apps/web/src/console/contracts.ts#22-31, schemas/json/cross_surface_handoff.schema.json

UX Telemetry Events

UX Telemetry events are structured JSON logs that track operator behavior and “friction” without using third-party analytics. These are stored in the SystemEventRecord table.

Telemetry Entity Mapping

The function toSystemEventPayload in apps/web/src/console/contracts.ts#221-244 transforms the high-level UI event into the flat SystemEventRecord structure required by the daemon’s record_console_event handler. Sources: apps/web/src/console/contracts.ts#33-64, apps/web/src/console/contracts.ts#221-244, crates/palyra-daemon/src/transport/http/handlers/console/acp.rs#117-128

Auxiliary Task Contracts

Auxiliary tasks (summarization, vision, etc.) use strict execution contracts that define their input/output shapes and resource budgets. These are defined in auxiliary_executor.rs.

Task Type Definitions

Task TypeInput ContractOutput ContractDefault Budget
Summaryplain_text_contextbounded_plain_text_summary1,200 tokens
RecallSearchquery_plus_optional_contextranked_recall_evidence_json1,600 tokens
Classificationplain_text_payloadsingle_label_json600 tokens
ObjectiveJudgeobjective_judge_input_jsonobjective_judge_strict_json900 tokens
These contracts are immutable at runtime and ensure that model providers are selected based on the model_preference (e.g., LowCost vs LowLatency). Sources: crates/palyra-daemon/src/auxiliary_executor.rs#92-155, crates/palyra-daemon/src/auxiliary_executor.rs#47-54

ACP: Agent Control Protocol Envelopes

The Agent Control Protocol (ACP) bridge allows the Web Console to dispatch commands using the same envelope format as realtime clients.

Command Envelope Structure

  • AcpCommandEnvelope: Contains the request_id, the command (e.g., SessionNew, RunCreate), and an idempotency_key.
  • AcpCommandResultEnvelope: Returns the ok status, the result JSON, or a StableErrorEnvelope.
The bridge is implemented in console_acp_command_handler, which unwraps the HTTP body and routes it to dispatch_acp_command. Sources: crates/palyra-daemon/src/transport/http/handlers/console/acp.rs#54-59, crates/palyra-daemon/src/transport/http/handlers/console/acp.rs#65-74, crates/palyra-daemon/src/transport/http/handlers/console/acp.rs#142-180