Protocol Architecture
Palyra uses Protocol Buffers (proto3) as the source of truth for all structured communication between the daemon (palyrad), CLI (palyra), browser daemon (palyra-browserd), and mobile/desktop clients. The protocol is versioned via a major version constant PROTOCOL_MAJOR_VERSION schemas/generated/rust/protocol_stubs.rs#5-5.
Core Service Definitions
The system is partitioned into functional gRPC services defined inschemas/proto/palyra/v1/.
| Service | File | Primary Responsibility |
|---|---|---|
GatewayService | schemas/proto/palyra/v1/gateway.proto#7-29 | Run orchestration, session management, and agent routing. |
ApprovalsService | schemas/proto/palyra/v1/gateway.proto#31-35 | Management of tool and action approval records. |
VaultService | schemas/proto/palyra/v1/gateway.proto#37-42 | Secret storage and retrieval operations. |
CanvasService | schemas/proto/palyra/v1/gateway.proto#44-51 | State synchronization for A2UI (Agent-to-UI) components. |
BrowserService | schemas/proto/palyra/v1/browser.proto#7-42 | Headless Chromium automation and session control. |
AuthServiceClient | schemas/generated/rust/protocol_stubs.rs#52-58 | Identity and credential profile management. |
Data Flow and Envelope Structure
Most streaming interactions occur via theRunStream, which uses a request/event pattern schemas/proto/palyra/v1/gateway.proto#9-10.
Entity Relationship Diagram: Protocol Space
This diagram maps the logical protocol entities to their generated code representations. Sources: schemas/proto/palyra/v1/gateway.proto#7-106, schemas/proto/palyra/v1/browser.proto#132-159, schemas/proto/palyra/v1/gateway.proto#255-267Multi-Language Stubs
To ensure type safety across the Rust daemon, Swift (iOS/macOS), and Kotlin (Android) applications, a generation pipeline produces stubs from the.proto files.
Generated Stub Locations
- Rust: schemas/generated/rust/protocol_stubs.rs
- Kotlin: schemas/generated/kotlin/ProtocolStubs.kt
- Swift: schemas/generated/swift/ProtocolStubs.swift
scripts/protocol/generate-stubs.ps1. It parses the proto files for package, message, service, and rpc declarations to build language-specific constructs scripts/protocol/generate-stubs.ps1#103-143.
Mapping Logic
The generator applies specific naming conventions for each target:- Rust: Packages become modules (e.g.,
palyra.auth.v1->palyra_auth_v1) scripts/protocol/generate-stubs.ps1#154-157. - Swift: Packages become Enums used as namespaces schemas/generated/swift/ProtocolStubs.swift#3-3, and RPCs use lowerCamelCase scripts/protocol/generate-stubs.ps1#201-201.
- Kotlin: Packages become Objects, and messages become
data classentities schemas/generated/kotlin/ProtocolStubs.kt#4-5.
Protocol Validation Pipeline
The repository enforces protocol integrity through a multi-stage validation pipeline executed during CI.1. Schema Validation
Thevalidate-proto.ps1 script uses protoc to ensure that all .proto files are syntactically correct and that imports (like common.proto) resolve correctly scripts/protocol/validate-proto.ps1#57-66.
2. Stub Coherence Check
Thecheck-generated-stubs.ps1 script regenerates the stubs and performs a git diff. If the generated code in schemas/generated/ does not match the source schemas, the build fails scripts/protocol/check-generated-stubs.ps1#9-21.
3. Compilation Validation
Each language’s stubs are compiled to ensure they are valid source code:- Rust: Validated using
rustc --crate-type libscripts/protocol/validate-rust-stubs.ps1#26-26. - Swift: Validated using
swiftc -emit-modulescripts/protocol/validate-swift-stubs.sh#20-20. - Kotlin: Validated using
kotlincto produce a JAR scripts/protocol/validate-kotlin-stubs.ps1#26-27.
Pipeline Sequence Diagram
Sources: scripts/protocol/validate-proto.ps1#57-66, scripts/protocol/generate-stubs.ps1#22-44, scripts/protocol/validate-rust-stubs.ps1#26-29Key Message Definitions
Approval and Security
The protocol defines strict enums for decisions and subjects to maintain a consistent security posture across UIs.- ApprovalSubjectType: Defines what is being approved (e.g.,
TOOL,SECRET_ACCESS,DEVICE_PAIRING) schemas/proto/palyra/v1/gateway.proto#53-61. - ApprovalDecision: The outcome of a request (
ALLOW,DENY,TIMEOUT,ERROR) schemas/proto/palyra/v1/gateway.proto#63-69.
Browser Automation
TheBrowserService utilizes a SessionBudget to enforce resource constraints on headless instances, preventing memory exhaustion or runaway processes.
- SessionBudget: Includes
max_navigation_timeout_ms,max_screenshot_bytes, andmax_actions_per_sessionschemas/proto/palyra/v1/browser.proto#57-74.
Sources:
- schemas/proto/palyra/v1/gateway.proto#1-267
- schemas/proto/palyra/v1/browser.proto#1-159
- schemas/generated/rust/protocol_stubs.rs#1-58
- schemas/generated/kotlin/ProtocolStubs.kt#1-126
- schemas/generated/swift/ProtocolStubs.swift#1-251
- scripts/protocol/generate-stubs.ps1#1-201
- scripts/protocol/validate-proto.ps1#1-72
- scripts/protocol/validate-rust-stubs.ps1#1-35
- scripts/protocol/validate-swift-stubs.sh#1-22