Skip to main content
This page details the Palyra communication layer, which relies on Protocol Buffers (Protobuf) for schema definition and gRPC (via the tonic library in Rust) for high-performance, type-safe remote procedure calls. The system uses a centralized schema repository to generate language-specific stubs for Rust, Swift, and Kotlin, ensuring cross-platform consistency across the daemon, mobile apps, and desktop clients.

Protocol Schema Architecture

The protocol is organized into several functional domains defined in .proto files within the schemas/proto/palyra/v1/ directory.

Core Service Definitions

ServiceFilePrimary Responsibility
GatewayServicegateway.protoMain entry point for runs, session management, and agent orchestration.
BrowserServicebrowser.protoInterface for the palyra-browserd automation engine.
AuthServiceClientauth.protoManagement of AuthProfile and provider credentials.
VaultServicegateway.protoSecure storage for secrets and sensitive bytes.
CanvasServicegateway.protoManagement of the Agent-to-User Interface (A2UI) state.

Common Types and Messaging

The common.proto file defines the fundamental building blocks used across all services, such as CanonicalId (ULID-based identifiers) and MessageEnvelope for secure message passing schemas/proto/palyra/v1/common.proto#6-11, schemas/proto/palyra/v1/common.proto#98-108. Sources: schemas/proto/palyra/v1/gateway.proto#7-29, schemas/proto/palyra/v1/browser.proto#7-42, schemas/proto/palyra/v1/common.proto#1-142

Data Flow: RunStream and Event Lifecycle

The most critical interface in Palyra is the bidirectional RunStream within the GatewayService. It facilitates real-time interaction between the user (or client) and the agent.

RunStream Interaction Model

  1. Request: The client sends a RunStreamRequest containing a MessageEnvelope schemas/proto/palyra/v1/common.proto#259-276.
  2. Execution: The daemon processes the input, potentially triggering tool calls or model generations.
  3. Events: The daemon streams back RunStreamEvent messages, which are a oneof union of ModelToken, ToolProposal, ToolResult, and others schemas/proto/palyra/v1/common.proto#300-307.

Mapping Protocol to Entities

The following diagram bridges the Protobuf definitions to the logical entities they represent in the system. “Natural Language Space to Code Entity Space: Messaging” Sources: schemas/proto/palyra/v1/common.proto#98-108, schemas/proto/palyra/v1/common.proto#144-151, schemas/proto/palyra/v1/common.proto#251-257, schemas/proto/palyra/v1/gateway.proto#9-10

Browser Automation Interface

The BrowserService exposes a high-level API for controlling headless Chromium instances. It includes standard automation actions (Click, Type, Navigate) and Palyra-specific session management.

Key Browser Operations

“Natural Language Space to Code Entity Space: Browser Control” Sources: schemas/proto/palyra/v1/browser.proto#57-74, schemas/proto/palyra/v1/browser.proto#19-24, schemas/proto/palyra/v1/browser.proto#132-159

Generated Stubs and Multi-Language Support

Palyra uses a code generation pipeline to transform .proto definitions into native language structures. This ensures that changes to the protocol are immediately reflected across all components of the monorepo.

Language Targets

Validation Pipeline

The repository includes scripts to validate that the generated stubs are in sync with the .proto files and that they compile correctly in their respective target languages.
ScriptPurpose
validate-proto.ps1Uses protoc to check schema syntax and imports scripts/protocol/validate-proto.ps1#43-66.
check-generated-stubs.ps1Ensures that the files in schemas/generated/ match the current .proto definitions scripts/protocol/check-generated-stubs.ps1#14-21.
validate-rust-stubs.ps1Attempts to compile the Rust stubs using rustc scripts/protocol/validate-rust-stubs.ps1#24-29.
Sources: schemas/generated/rust/protocol_stubs.rs#1-60, schemas/generated/swift/ProtocolStubs.swift#1-79, schemas/generated/kotlin/ProtocolStubs.kt#1-35, scripts/protocol/validate-proto.ps1#9-41

Security and Integrity

The protocol incorporates security features directly into the message definitions: Sources: schemas/proto/palyra/v1/common.proto#14-21, schemas/proto/palyra/v1/common.proto#110-142, schemas/proto/palyra/v1/common.proto#82-96