latent.wire.providers.native.state¶
State tracking for the native AgentProtocol provider.
This module defines the mutable state that tracks the current position in the NormalizedEvent lifecycle while converting AgentEvent items. The state machine manages open text/reasoning/step blocks and usage metric accumulation.
Classes¶
NativeStreamState¶
NativeStreamState(text_id: str | None = None, text_started: bool = False, reasoning_id: str | None = None, reasoning_started: bool = False, current_step_active: bool = False, usage_metrics: dict[str, int] | None = None, id_generators: IDGenerators = (lambda: default_id_generators)(), start_timestamp: datetime | None = None, finish_timestamp: datetime | None = None, fidelity: bool = False, tool_input_available_emitted: set[str] = set())
Tracks state across AgentEvent items during a single message stream.
The native provider does not need a thinking parser (AgentProtocol already separates TextDelta from ReasoningDelta) or tool input buffering (ToolCall provides complete arguments). This makes the state significantly simpler than the Strands or LangChain state objects.
Attributes:
text_id: ID of the current active text block, or None if no block
is open.
text_started: Whether a TextStart event has been emitted for the
current text block.
reasoning_id: ID of the current active reasoning block, or None.
reasoning_started: Whether a ReasoningStart event has been emitted.
current_step_active: Whether a step is currently in progress.
usage_metrics: Always None for the native provider — token usage
rides its own lossless DataLatent part (Usage is never
accumulated here). The attribute exists only because the stream
orchestrator's finish-metadata step reads it for providers that DO
accumulate; native leaves it unset so the finish part carries timing
only.
id_generators: Generators for text and reasoning block IDs.
start_timestamp: Set by the stream orchestrator when streaming begins.
finish_timestamp: Set by the stream orchestrator when streaming ends.
fidelity: When True (the codec path — ai-sdk / ag-ui
WireProtocol.encode), ToolCall/ToolResult ride verbatim
DataLatent fidelity parts so decode(encode([e])) == [e] holds
field-for-field. When False (the browser-serving path via
NativeProviderAdapter), they map to native AI SDK tool parts with
{status, content} output normalization and orphan-input synthesis
for a stock AI SDK UI.