latent.wire.providers.native.convert¶
Convert AgentEvent items to NormalizedEvent items.
This module implements the state-machine conversion logic that bridges the agent-studio AgentProtocol event hierarchy to the stream adapter's NormalizedEvent hierarchy. Each handler manages opening/closing of text, reasoning, and step blocks as required by the AI SDK UI protocol.
Design notes¶
- AgentProtocol already separates TextDelta from ReasoningDelta, so no thinking-tag parser is needed (unlike the Strands provider).
- ToolCall provides complete arguments, so we skip ToolInputDelta entirely and emit ToolInputStart + ToolInputAvailable in a single batch.
- Events with no lossless native AI SDK part (Usage, LLM/retriever spans,
journey/phase markers, verification results, guardrail/context violations)
each emit a single :class:
DataLatentfidelity event so the codec stays bijective (ADR-003 D2 / ADR-009 D5). They are reconstructed verbatim on decode. ToolCallandToolResultare dual-mode (state.fidelity): on the codec path they ride verbatimDataLatentparts (raw arguments string + type forToolCall;{tool_call_id, output, error}forToolResult) so they round-trip field-for-field; on the browser-serving path they map to native AI SDK tool parts with output normalization and orphan-input synthesis.
Functions¶
convert_native_event¶
Convert a single wrapped AgentEvent or sentinel to NormalizedEvent items.
The event dict uses one of two shapes:
{"__event__": <AgentEvent>}-- a real agent event to convert.{"__finalize__": True}-- a sentinel signalling that the agent iterator is exhausted and open blocks should be closed.
Args: event: Wrapped event dictionary. state: Mutable state tracking open blocks and accumulated metrics.
Returns:
A list of zero or more NormalizedEvent items.