latent.wire.providers.native.adapter¶
Native AgentProtocol provider adapter.
This adapter wraps any agent implementing the agent-studio AgentProtocol
and exposes it via the BoundProviderAdapter interface consumed by the
stream orchestrator.
The adapter:
- Creates NativeStreamState for each message stream.
- Iterates AgentEvent items via agent.stream(messages), wrapping each
in {"__event__": event} and appending a {"__finalize__": True}
sentinel when the iterator is exhausted.
- Delegates conversion to convert_native_event.
Requires the wire extra: uv add "latent[wire]".
Classes¶
NativeProviderAdapter¶
Provider adapter for agent-studio AgentProtocol agents.
This adapter bridges the simple AgentEvent hierarchy to the richer NormalizedEvent hierarchy required by the AI SDK UI stream protocol.
Example::
from latent.protocol import AgentProtocol, Message, TextDelta
from latent.wire import stream_ui_message
from latent.wire.providers.native import NativeProviderAdapter
class MyAgent:
async def stream(self, messages, *, config=None):
yield TextDelta(text="Hello, world!")
agent = MyAgent()
provider = NativeProviderAdapter(agent)
messages = [Message(role="user", content="Hi")]
async for chunk in stream_ui_message(messages, provider=provider):
yield chunk
Args:
agent: Any object implementing the AgentProtocol protocol.
Methods¶
NativeProviderAdapter.convert_event¶
Convert a wrapped agent event to normalized events.
NativeProviderAdapter.create_state¶
Create provider state for one message stream.
NativeProviderAdapter.iterate_events¶
Iterate agent events wrapped in the dict envelope.
The full conversation history is passed directly to
agent.stream(messages). Each yielded AgentEvent is wrapped as
{"__event__": event}. After the iterator is exhausted, a
{"__finalize__": True} sentinel is yielded to signal the converter
to close any open blocks.
Args: messages: Full conversation history as Message objects. config: Optional configuration dict passed through to the agent.
Yields: Dictionary-wrapped agent events and a finalize sentinel.