Provider Adapter Architecture
Palyra uses a trait-based adapter system to support multiple LLM providers. The core runtime traits areModelProvider (for chat and audio) and EmbeddingsProvider crates/palyra-daemon/src/model_provider.rs#5-12.
Supported Adapters
- OpenAI Adapter: Implements the standard OpenAI chat completions and embeddings protocol crates/palyra-daemon/src/model_provider.rs#42-43.
- Anthropic Adapter: Supports Claude models via the Messages API and includes specific handling for MiniMax via bearer authentication crates/palyra-daemon/src/model_provider.rs#8-9.
- Google Gemini: Integrated via the OpenAI-compatible surface crates/palyra-daemon/src/openai_surface.rs#61-62.
- MiniMax: Supports both Anthropic-compatible and native OAuth flows crates/palyra-daemon/src/openai_surface.rs#48-53.
- Deterministic Provider: A mock provider used for offline testing and fixtures crates/palyra-daemon/src/model_provider.rs#7-8.
Streaming and Normalization
Upstream provider events are normalized into a uniform stream ofProviderEvent::ModelToken events crates/palyra-daemon/src/model_provider.rs#14-18. This ensures the Orchestrator can consume a consistent event format regardless of whether the underlying transport is Server-Sent Events (SSE) or a standard HTTP response body.
Tool Repair
The subsystem includes aToolRepairStreamNormalizer that monitors assistant output for malformed tool calls crates/palyra-daemon/src/model_provider.rs#71-77. It can identify and potentially repair truncated or syntactically incorrect JSON in tool arguments before they reach the execution layer.
Provider Data Flow
The following diagram illustrates the flow from a high-level request to the specific code entities handling the adapter logic. Model Request Normalization Flow Sources: crates/palyra-daemon/src/model_provider.rs#10-18, crates/palyra-daemon/src/model_provider.rs#39-43, crates/palyra-daemon/src/model_provider.rs#71-77Configuration Pipeline
Palyra employs a multi-layered configuration loading strategy defined incrates/palyra-daemon/src/config/load.rs.
Precedence Layers
- Secure Defaults: Hardcoded values in
DaemonConfigand related structs crates/palyra-daemon/src/config/schema.rs#1-13. - TOML Configuration: Values loaded from
palyra.tomlcrates/palyra-daemon/src/config/load.rs#1-9. - Environment Variables:
PALYRA_*prefixed variables that override both defaults and file settings crates/palyra-daemon/src/config/load.rs#4-5.
Secret Management and SecretRefs
Sensitive values like API keys are never stored directly in the primary configuration if aSecretRef is provided. The system supports:
- Inline Secrets: Stored in the TOML (redacted during exports) crates/palyra-common/src/daemon_config_schema.rs#22-38.
- Vault References:
VaultRefpoints to encrypted storage managed bypalyra-vaultcrates/palyra-daemon/src/model_provider.rs#19-19. - Environment Refs: Sourcing secrets from specific environment variables at runtime crates/palyra-daemon/src/config/load.rs#52-52.
CLI and Model Management
Thepalyra models command group provides tools for inspecting and mutating the provider registry.
Key Commands
Sources: crates/palyra-cli/src/commands/models.rs#41-68, crates/palyra-cli/src/commands/models.rs#121-128, crates/palyra-daemon/src/transport/http/handlers/console/models.rs#116-137
Connection Probing and Discovery
Thepalyra-daemon exposes internal handlers for the CLI and Web Console to verify credentials. These probes resolve credentials from the Vault or AuthProfileRegistry and perform a live request to the provider’s /models or /v1/models endpoint crates/palyra-daemon/src/transport/http/handlers/console/models.rs#3-9.
Configuration Redaction
To prevent accidental leakage, theSECRET_CONFIG_PATHS constant defines all sensitive paths (e.g., model_provider.openai_api_key) that must be redacted whenever configuration is exported or displayed in the console crates/palyra-common/src/daemon_config_schema.rs#22-38.
Sources: crates/palyra-common/src/daemon_config_schema.rs#22-38, crates/palyra-daemon/src/transport/http/handlers/console/models.rs#145-156