Skip to main content
This page provides a high-level overview of Palyra’s communication protocols, schema definitions, and the automated pipeline that ensures cross-language consistency. Palyra uses a polyglot architecture (Rust, TypeScript, Kotlin, Swift), making strict protocol contracts essential for system stability.

Protocol Overview

The Palyra ecosystem relies on two primary schema formats to govern data exchange:
  1. Protobuf (gRPC/Internal): Used for high-performance service-to-service communication (e.g., between palyrad and palyra-browserd) and for defining core entity models.
  2. JSON Envelopes (Web/External): Used for the Web Console API, A2UI (Agent-to-UI) updates, and external webhooks.

Multi-Language Consistency

To prevent drift between the Rust backend and various client implementations, Palyra utilizes a “Schema-First” approach. Source-of-truth .proto files are used to generate stubs for all supported languages.
LanguageGenerated Stub PathValidation Tool
Rustschemas/generated/rust/protocol_stubs.rsrustc
Kotlinschemas/generated/kotlin/ProtocolStubs.ktkotlinc
Swiftschemas/generated/swift/ProtocolStubs.swiftswiftc

Code-to-Entity Mapping: Protocol Generation

The following diagram illustrates how the build system transforms Protobuf definitions into language-specific entities used throughout the codebase. Sources: scripts/protocol/generate-stubs.ps1#82-91, schemas/generated/rust/protocol_stubs.rs#1-7, schemas/generated/kotlin/ProtocolStubs.kt#1-4, schemas/generated/swift/ProtocolStubs.swift#1-3

Protobuf Service Definitions

The core services of Palyra are defined in the schemas/proto directory. These definitions include both the RPC methods and the message structures (requests/responses) they exchange. For a detailed breakdown of every RPC and message type, see Protobuf Service Definitions.

JSON Envelope Schemas & A2UI Protocol

Beyond gRPC, Palyra uses JSON-based protocols for UI interaction and external integrations. These are characterized by “Envelopes” that wrap various payload types with consistent metadata.
  • A2UI (Agent-to-UI): A specialized protocol for streaming UI state updates from the agent to the Web Console. It supports incremental patches to minimize bandwidth.
  • Webhook Envelopes: Standardized formats for receiving events from Discord, Slack, or Telegram, including replay protection signatures.
  • Config Export/Import: JSON representations of the palyra.toml configuration used for migrations and backups.
For details on JSON structures and the renderer security model, see JSON Envelope Schemas & A2UI Protocol.

Validation Pipeline

Palyra enforces protocol integrity through a multi-stage validation pipeline triggered during CI. This ensures that any change to a .proto file is valid and that all generated stubs compile correctly in their respective languages.

Code-to-Entity Mapping: Validation Workflow

This diagram maps the validation logic to the scripts and tools responsible for enforcing the contract.

Key Validation Steps:

  1. Protoc Validation: Uses protoc to verify that .proto files are syntactically correct and imports are resolvable scripts/protocol/validate-proto.ps1#57-66.
  2. Stub Drift Detection: Checks if the generated files in the repository match what the current generator script produces. If they differ, the CI fails scripts/protocol/check-generated-stubs.ps1#14-21.
  3. Language-Specific Compilation:
Sources: scripts/protocol/validate-proto.ps1#1-72, scripts/protocol/check-generated-stubs.ps1#1-24, scripts/protocol/validate-rust-stubs.ps1#1-35, scripts/protocol/validate-kotlin-stubs.ps1#1-35, scripts/protocol/validate-swift-stubs.sh#1-22

Child Pages