The DialogAdapter protocol
Defined inunpod.adapters.base. Runtime-checkable - any object with these
three methods passes isinstance(obj, DialogAdapter); no base class required.
Auto-wrapping
Thectx.session.dialog_machine setter accepts, in order:
- A superdialog
DialogMachineorLLMAgent- wrapped in aSuperDialogAdapterautomatically. - Any object satisfying the
DialogAdapterprotocol - used as-is. - Anything else - raises
TypeError.
Bundled adapters
All importable fromunpod.adapters:
AnthropicAdapter, DialogAdapter, HTTPAdapter, LangChainAdapter,
MCPAdapter, OpenAIAdapter, SuperDialogAdapter.
Constructor signatures
| Adapter | Constructor | Wraps |
|---|---|---|
OpenAIAdapter | (client, model="gpt-4o-mini", system_prompt=None) | openai.AsyncOpenAI client |
AnthropicAdapter | (client, model="claude-haiku-4-5-20251001", system_prompt=None, max_tokens=1024) | anthropic.AsyncAnthropic client |
LangChainAdapter | (chain, input_key="messages") | LangChain Runnable with ainvoke/astream |
HTTPAdapter | (url, headers=None, timeout_s=10.0) | A remote HTTP endpoint, any language |
MCPAdapter | (server_url, tools=None, llm="anthropic/claude-haiku-4-5", headers=None) | An MCP server (preview - see below) |
SuperDialogAdapter | (dm) | superdialog DialogMachine or LLMAgent |
Streaming behavior
| Adapter | stream() behavior |
|---|---|
OpenAIAdapter | Real token streaming via chat.completions.create(stream=True) |
AnthropicAdapter | Real token streaming via messages.stream() |
LangChainAdapter | Real streaming via the chain’s .astream() |
SuperDialogAdapter | Delegates to dm.turn(text, stream=True) |
HTTPAdapter | Single chunk - one POST round-trip, full reply yielded once |
MCPAdapter | Falls back to turn(), which is not implemented yet |
assist() semantics
| Adapter | What assist(text) does |
|---|---|
OpenAIAdapter / LangChainAdapter | Injects the instruction into the conversation history |
AnthropicAdapter | Injects as a user/assistant message pair - the Anthropic API does not accept mid-conversation system messages |
HTTPAdapter | Queues the instruction; sent as system_instructions in the next request body |
MCPAdapter | Queues the instruction (pending full implementation) |
SuperDialogAdapter | Delegates to the DialogMachine’s assist() |
SuperDialogAdapter extras
Beyond the protocol,SuperDialogAdapter exposes the wrapped machine’s
controls:
Error surfaces
| Failure | What you see |
|---|---|
Assigning a non-adapter to dialog_machine | TypeError from the setter, immediately |
HTTPAdapter endpoint returns non-2xx | httpx.HTTPStatusError (the adapter calls raise_for_status()) |
HTTPAdapter endpoint slower than timeout_s | httpx.TimeoutException |
MCPAdapter without the mcp package | ImportError - install with unpod[mcp] |
MCPAdapter with the package | NotImplementedError - full MCP orchestration is not implemented yet |
LangChainAdapter with a chain expecting a different input shape | No error - the chain receives {input_key: history} and may silently misbehave; set input_key to match your chain |
Lazy stream() in a custom adapter | No error - choppy, delayed audio on calls |