Skip to main content
You can connect an agent to any messaging platform by subclassing 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:
Looking for Slack? There’s a built-in Slack interface with full Block Kit, slash commands, and interactive component support.

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:
Raise these from your platform methods, and the base class handles them:
  • Runs all on_error hooks
  • Sends the configured error_message to the user
  • Logs the error

InterfaceRateLimitError

Includes an optional retry_after field for backoff:

Implementation Checklist

When building a custom interface:
  1. Subclass InterfaceConfig — Add platform-specific settings (tokens, URLs, modes). Use a frozen dataclass.
  2. Implement _start_receiver — Set up your connection (WebSocket, HTTP server, polling loop). Store any client objects on self.
  3. Implement _stop_receiver — Tear down connections. Must be idempotent (safe to call multiple times).
  4. Implement _convert_inbound — Parse the platform’s message format. Extract text, media, user info. Return None for messages to skip.
  5. Implement _send_response — Send text, images, files back to the platform. Handle message splitting if the platform has length limits.
  6. Call handle_platform_message — From your receiver (event handler, webhook route, poll loop), call await self.handle_platform_message(raw_message). This triggers the full pipeline.
The base class takes it from there — converting the message, running hooks, managing sessions, calling the agent, and invoking your _send_response.
Look at the Telegram or Slack implementations as references. Telegram demonstrates polling vs webhooks, media handling, and error mapping. Slack demonstrates Socket Mode, Block Kit interactions, slash commands, and modals.