Skip to main content
Reference for the brain slot. For worked examples and guidance, see Bring Your Agent; this page is the contract.

The DialogAdapter protocol

Defined in unpod.adapters.base. Runtime-checkable - any object with these three methods passes isinstance(obj, DialogAdapter); no base class required.
class DialogAdapter(Protocol):
    async def turn(self, text: str, context: dict | None = None) -> str:
        """Return a complete response string. NOT called during live calls."""

    async def stream(self, text: str, context: dict | None = None) -> AsyncIterator[str]:
        """Yield response tokens. HOT PATH - session.run() calls this on
        every user turn and streams tokens directly to the voice bridge."""

    def assist(self, text: str) -> None:
        """Inject a system instruction before the next turn."""
session.run() calls only stream(). A single-chunk stream() fallback (await the full reply, yield once) produces choppy, high-latency audio with no error anywhere. See Streaming is the hot path.

Auto-wrapping

The ctx.session.dialog_machine setter accepts, in order:
  1. A superdialog DialogMachine or LLMAgent - wrapped in a SuperDialogAdapter automatically.
  2. Any object satisfying the DialogAdapter protocol - used as-is.
  3. Anything else - raises TypeError.

Bundled adapters

All importable from unpod.adapters: AnthropicAdapter, DialogAdapter, HTTPAdapter, LangChainAdapter, MCPAdapter, OpenAIAdapter, SuperDialogAdapter.

Constructor signatures

AdapterConstructorWraps
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

Adapterstream() behavior
OpenAIAdapterReal token streaming via chat.completions.create(stream=True)
AnthropicAdapterReal token streaming via messages.stream()
LangChainAdapterReal streaming via the chain’s .astream()
SuperDialogAdapterDelegates to dm.turn(text, stream=True)
HTTPAdapterSingle chunk - one POST round-trip, full reply yielded once
MCPAdapterFalls back to turn(), which is not implemented yet

assist() semantics

AdapterWhat assist(text) does
OpenAIAdapter / LangChainAdapterInjects the instruction into the conversation history
AnthropicAdapterInjects as a user/assistant message pair - the Anthropic API does not accept mid-conversation system messages
HTTPAdapterQueues the instruction; sent as system_instructions in the next request body
MCPAdapterQueues the instruction (pending full implementation)
SuperDialogAdapterDelegates to the DialogMachine’s assist()

SuperDialogAdapter extras

Beyond the protocol, SuperDialogAdapter exposes the wrapped machine’s controls:
adapter.set_llm("anthropic/claude-haiku-4-5")        # swap the runtime model
adapter.switch_flow(flow, preserve_memory=False)      # change the active flow
adapter.is_complete                                   # has the flow finished?
adapter.state                                         # current flow state (dict)
See SuperDialog for the machine itself.

Error surfaces

FailureWhat you see
Assigning a non-adapter to dialog_machineTypeError from the setter, immediately
HTTPAdapter endpoint returns non-2xxhttpx.HTTPStatusError (the adapter calls raise_for_status())
HTTPAdapter endpoint slower than timeout_shttpx.TimeoutException
MCPAdapter without the mcp packageImportError - install with unpod[mcp]
MCPAdapter with the packageNotImplementedError - full MCP orchestration is not implemented yet
LangChainAdapter with a chain expecting a different input shapeNo error - the chain receives {input_key: history} and may silently misbehave; set input_key to match your chain
Lazy stream() in a custom adapterNo error - choppy, delayed audio on calls