Protocols define extension points for custom authentication, pairing stores, and session binding implementations.Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Quick Start
Protocol Specifications
AuthProtocol
Authentication implementations for gateway requests.| Method | Signature | Returns |
|---|---|---|
check | check(request: Any) -> Dict[str, Any] | { success: bool, user_id: Optional[str], role: Optional[str], metadata: Dict[str, Any] } |
PairingProtocol
Channel pairing and authorization management.| Method | Signature | Returns |
|---|---|---|
generate_code | generate_code(channel_type: str = "unknown", channel_id: Optional[str] = None) -> str | The generated pairing code |
approve | approve(channel_type: str, code: str, user_id: str = "", user_name: str = "") -> bool | True if approval succeeded |
is_paired | is_paired(channel_id: str, channel_type: str) -> bool | Whether the channel is authorised |
list_paired | list_paired() -> List["PairedChannel"] | All paired channels |
revoke | revoke(channel_id: str, channel_type: str) -> bool | True if revocation succeeded |
list_pending | list_pending(channel_type: Optional[str] = None) -> List[Dict[str, any]] | Pending requests with channel, code, user info, age |
SessionBindingProtocol
Session to principal mapping for state tracking.| Method | Signature | Returns |
|---|---|---|
bind | bind(session_id: str, principal: Dict[str, Any]) -> None | — |
lookup | lookup(session_id: str) -> Optional[Dict[str, Any]] | Principal info if found |
These are
@runtime_checkable typing.Protocol classes — any object whose method shapes match (duck typing) satisfies them. No inheritance required.Custom Implementation Example
How It Works
Protocol implementations allow you to plug custom backends into the PraisonAI gateway without modifying core code.| Protocol | Purpose | Extension Point |
|---|---|---|
AuthProtocol | Request authentication | Custom auth backends (LDAP, OAuth, etc.) |
PairingProtocol | Channel pairing storage | Custom storage (Redis, DB, etc.) |
SessionBindingProtocol | Session management | Custom session stores |
Configuration Options
Protocol implementations are dependency-injected into the gateway:Common Patterns
- Redis Backend
- Database Backend
- File Backend
Best Practices
Implement all protocol methods
Implement all protocol methods
Protocol compliance requires implementing all methods, even if some return empty results for your use case.
Handle database errors gracefully
Handle database errors gracefully
Wrap database operations in try-catch blocks and return safe defaults.
Use connection pooling for performance
Use connection pooling for performance
For database backends, use connection pools to avoid connection overhead.
Validate inputs to prevent injection
Validate inputs to prevent injection
Always validate and sanitize inputs, especially for database queries.
Related
Bot Pairing
Complete pairing system documentation
Unknown User Pairing
Owner-DM inline-button approval flow

