Skip to content

latent.wire.providers.adapter

Bound provider adapter protocol for agent streaming integrations.

This module defines the protocol for provider-specific adapters that are "bound" to an underlying agent instance. Bound adapters encapsulate the agent object internally and expose a uniform interface to the stream orchestrator, avoiding any assumptions about the agent's public API.

Responsibilities: - Provide provider-specific state (create_state) - Expose an async iterator over raw provider events (iterate_events) - Convert raw provider events to normalized events (convert_event)

Design: The core orchestrator remains provider-agnostic and relies on this adapter to handle framework-specific details such as how to iterate events and how to convert them to normalized events. The agent is not passed to the orchestrator; implementations capture it at construction time.

Classes

BoundProviderAdapter

BoundProviderAdapter()

Protocol for bound provider adapters that integrate agent frameworks.

Implementations encapsulate provider-specific details and the agent instance itself so the core stream orchestrator can remain agnostic of agent frameworks and their agent method names.

Methods: create_state(): Return provider-specific mutable state object iterate_events(messages): Async iterator of raw provider events convert_event(event, state): Map raw provider event to normalized events

Methods

BoundProviderAdapter.convert_event

convert_event(event: dict, state: Any) -> list[NormalizedEvent]

Convert a single raw provider event to a list of normalized events.

Normalized events are provider-agnostic core events consumed by encoders to produce AI SDK parts.

BoundProviderAdapter.create_state

create_state() -> Any

Create and return provider-specific state for one message stream.

BoundProviderAdapter.iterate_events

iterate_events(messages: list, config: dict | None = None) -> AsyncIterator[dict]

Return an async iterator yielding raw provider events as dictionaries.

Implementations should call the appropriate provider API on the bound agent (e.g., self.agent.stream(messages)) and return the async iterator object.

Args: messages: Full conversation history as a list of Message objects. config: Optional framework-specific config (e.g. callbacks).