Skip to content

latent.wire.fidelity

Shared data-latent fidelity reconstruction for wire codecs.

Both codecs carry otherwise-lossy AgentEvents verbatim — ai-sdk as data-latent-* parts, ag-ui as CUSTOM events — and reconstruct them on decode (ADR-003 D2). The reconstruction (class lookup in :mod:latent.events plus a nested-dataclass rebuild) is identical for both, so it lives here.

Functions

reconstruct_event

reconstruct_event(name: str, payload: dict) -> AgentEvent | None

Rebuild a canonical AgentEvent from a carried fidelity payload.

Looks name up in :mod:latent.events, then rebuilds each constructor field — recursing into nested dataclasses (e.g. a ToolCall's FunctionCall) so the reconstructed instance compares equal to the original. Unknown names or payloads that don't fit the dataclass return None (the caller drops them) rather than raising.