palyrad), the TypeScript/React web console, the Kotlin/Swift mobile scaffolds, and the various CLI tools. These contracts are defined primarily through Protocol Buffers (Protobuf) for RPC communication and JSON Schemas for persistent data and webhook envelopes.
Overview of Contract Governance
Palyra uses a “schema-first” approach where all external and internal service interfaces are defined in theschemas/ directory. These definitions serve as the single source of truth for:
- gRPC Services: Defining RPC methods for gateway, browser automation, and node management.
- JSON Envelopes: Defining the structure of webhooks, A2UI (Agent-to-User Interface) patches, and configuration exports.
- Cross-Language Stubs: Automated generation of Rust, Kotlin, and Swift code to ensure type safety across the monorepo.
PROTOCOL_MAJOR_VERSION to manage breaking changes across the ecosystem schemas/generated/rust/protocol_stubs.rs#5-5.
Service and Schema Landscape
The following diagram maps the relationship between the schema definitions and the code entities that implement or consume them. Schema to Entity Mapping Sources: schemas/proto/palyra/v1/gateway.proto#7-29, schemas/proto/palyra/v1/browser.proto#7-42, schemas/generated/rust/protocol_stubs.rs#1-7, schemas/generated/kotlin/ProtocolStubs.kt#1-4, schemas/generated/swift/ProtocolStubs.swift#1-3Protobuf Service Definitions
Palyra uses Protobuf to define its core gRPC services. These definitions are organized by versioned packages (e.g.,palyra.gateway.v1).
- Gateway Service: The primary interface for session management, agent orchestration, and message routing schemas/proto/palyra/v1/gateway.proto#7-29.
- Browser Service: Controls headless Chromium instances for browser automation schemas/proto/palyra/v1/browser.proto#7-42.
- Common Types: Shared primitives like
CanonicalIdandRunStreamEventused across all services schemas/proto/palyra/v1/gateway.proto#5-5.
JSON Schemas and Envelope Formats
For asynchronous communication and data persistence where Protobuf is not suitable (e.g., Webhooks or A2UI state patches), Palyra utilizes JSON Schemas. These schemas enforce strict versioning via av field and use additionalProperties: false to prevent schema drift.
- Webhooks: Standardized envelopes for inbound events from platforms like Discord or Slack.
- A2UI: The protocol for patching the Agent-to-User Interface state in the web console.
- Config: Export and import formats for daemon settings.
Generated Stubs and Protocol Governance
To maintain synchronization across languages, Palyra employs a code generation pipeline. Stubs are not just generated but are also validated through compilation checks in CI. Protocol Build & Validation Pipeline Sources: scripts/protocol/generate-stubs.ps1#82-87, scripts/protocol/validate-rust-stubs.ps1#25-26, scripts/protocol/validate-kotlin-stubs.ps1#25-26, scripts/protocol/validate-swift-stubs.ps1#22-23 Key governance mechanisms include:- Validation Scripts: Scripts like
validate-proto.ps1useprotocto ensure schema correctness scripts/protocol/validate-proto.ps1#58-63. - CI Enforcement: The
check-generated-stubs.ps1script ensures that developers have committed the latest generated code by checking for git diffs after running the generator scripts/protocol/check-generated-stubs.ps1#15-20.