BaseInterface and implementing four abstract methods. The base class handles sessions, hooks, concurrency, and error handling — you only write the platform-specific code.
What You Implement
Everything else — sessions, hooks, agent execution, error handling, concurrency — is handled by
BaseInterface.
Skeleton Example
Here is a minimal custom interface for a WebSocket-based chat platform:InterfaceMessage
The platform-agnostic inbound message your_convert_inbound method must produce:
Return
None from _convert_inbound to silently skip a message (e.g., bot’s own messages, unsupported message types).
InterfaceResponse
The platform-agnostic response produced by the agent:
Your
_send_response method receives this and translates it into platform API calls.
Error Types
Use the built-in error hierarchy for consistent error handling across interfaces:- Runs all
on_errorhooks - Sends the configured
error_messageto the user - Logs the error
InterfaceRateLimitError
Includes an optionalretry_after field for backoff:
Implementation Checklist
When building a custom interface:-
Subclass
InterfaceConfig— Add platform-specific settings (tokens, URLs, modes). Use a frozen dataclass. -
Implement
_start_receiver— Set up your connection (WebSocket, HTTP server, polling loop). Store any client objects onself. -
Implement
_stop_receiver— Tear down connections. Must be idempotent (safe to call multiple times). -
Implement
_convert_inbound— Parse the platform’s message format. Extract text, media, user info. ReturnNonefor messages to skip. -
Implement
_send_response— Send text, images, files back to the platform. Handle message splitting if the platform has length limits. -
Call
handle_platform_message— From your receiver (event handler, webhook route, poll loop), callawait self.handle_platform_message(raw_message). This triggers the full pipeline.
_send_response.