Skip to content

crp.tel

Auto-generated reference for the crp.tel subpackage.

tel

crp.tel

Transparency Emission Layer (TEL) - stream CRP governance as AG-UI events (CRP-SPEC-056).

The crp.tel package maps CRP's internal governance evidence onto the AG-UI event vocabulary so any standard frontend can render a CRP agent, while adding namespaced governance events (crp.safety_scan, crp.quality, crp.provenance, ...) that carry the protocol's differentiators.

CRPEmitter

Adapter: CRP governance hooks -> AG-UI-compatible event stream.

Emitter

Ergonomic facade agents call. Knows nothing about transport.

SessionBus

Isolated event bus for one session.

Buffers the most recent buffer_size events so Last-Event-ID replay is possible, and fans out live events to both synchronous and asynchronous subscribers.

emit(ev)

Assign a sequence number, buffer, and fan out ev.

replay_after(seq)

Return all buffered events with seq greater than seq.

subscribe()

Block and yield live events until :meth:close is called.

The returned iterator registers its queue immediately, so a producer thread started right after this call will not race the registration.

asubscribe()

Return an async iterator yielding live events until the bus is closed.

close()

Close the bus and unblock all subscribers.

Event dataclass

A single typed event on the transparency stream.

Each event carries a monotonic seq (ordering + replay cursor), a stable id, a wall-clock ts, and a payload whose schema is determined by type.

to_dict()

Render as a JSON-serialisable dictionary.

to_sse()

Render to the Server-Sent Events wire format.

The id: field enables Last-Event-ID replay; the event: field lets EventSource route by type.

EventType

Bases: str, Enum

AG-UI event vocabulary with CRP governance extensions carried in CUSTOM.

map_agent_event(event)

Convert an internal :class:AgentEvent into AG-UI events.

Returns a list because one internal transition may surface as multiple display events (e.g. tool selection + reasoning).

custom(name, value)

Namespaced governance event (e.g. crp.safety_scan).

build_report(buffer, tier='casual')

Build a human-readable transparency report from an event buffer.

The same event stream drives all tiers; tier is a rendering filter, not a different backend. casual returns narrative + governance badges; power adds tools and sources; developer adds the raw event log; auditor adds the full provenance chain.

stream_events_sync(bus, last_event_id=None, *, heartbeat_interval=None)

Yield events from bus, replaying missed events when last_event_id is given.

This synchronous generator is useful for tests, CLIs, and adapters that run in a worker thread. It stops when the bus is closed.

to_sse(ev)

Render an :class:Event to the SSE wire format.

tel.adapter

crp.tel.adapter

Map CRP runtime hooks to AG-UI + governance events (CRP-SPEC-056 §8.3.1).

CRPEmitter

Adapter: CRP governance hooks -> AG-UI-compatible event stream.

map_agent_event(event)

Convert an internal :class:AgentEvent into AG-UI events.

Returns a list because one internal transition may surface as multiple display events (e.g. tool selection + reasoning).

tel.emitter

crp.tel.emitter

Per-session event bus: sequence, replay buffer, and fan-out (CRP-SPEC-056 §8.3.5).

SessionBus

Isolated event bus for one session.

Buffers the most recent buffer_size events so Last-Event-ID replay is possible, and fans out live events to both synchronous and asynchronous subscribers.

emit(ev)

Assign a sequence number, buffer, and fan out ev.

replay_after(seq)

Return all buffered events with seq greater than seq.

subscribe()

Block and yield live events until :meth:close is called.

The returned iterator registers its queue immediately, so a producer thread started right after this call will not race the registration.

asubscribe()

Return an async iterator yielding live events until the bus is closed.

close()

Close the bus and unblock all subscribers.

Emitter

Ergonomic facade agents call. Knows nothing about transport.

get_bus(session_id, buffer_size=2000)

Return the existing bus for session_id or create one.

tel.events

crp.tel.events

AG-UI-compatible event model + CRP governance extensions (CRP-SPEC-056 §8.3.1).

EventType

Bases: str, Enum

AG-UI event vocabulary with CRP governance extensions carried in CUSTOM.

Event dataclass

A single typed event on the transparency stream.

Each event carries a monotonic seq (ordering + replay cursor), a stable id, a wall-clock ts, and a payload whose schema is determined by type.

to_dict()

Render as a JSON-serialisable dictionary.

to_sse()

Render to the Server-Sent Events wire format.

The id: field enables Last-Event-ID replay; the event: field lets EventSource route by type.

custom(name, value)

Namespaced governance event (e.g. crp.safety_scan).

tel.faithful

crp.tel.faithful

Faithful-narration contract - check a claim against the event trace (CRP-SPEC-056 §8.3.2).

entailment_check(claim, evidence)

Return True if every content word in claim is supported by the trace.

This is a deterministic, dependency-free approximation of the D3 faithful- narration contract. A claim is supported when all of its content words appear in the flattened evidence. Unsupported claims must be withheld from the user stream.

filter_faithful(claims, evidence)

Return only claims supported by the evidence.

tel.report

crp.tel.report

Localized transparency reports from an event buffer (CRP-SPEC-056 §8.3).

build_report(buffer, tier='casual')

Build a human-readable transparency report from an event buffer.

The same event stream drives all tiers; tier is a rendering filter, not a different backend. casual returns narrative + governance badges; power adds tools and sources; developer adds the raw event log; auditor adds the full provenance chain.

tel.sse

crp.tel.sse

Server-Sent Events wire utilities and stream helpers (CRP-SPEC-056 §8.3).

to_sse(ev)

Render an :class:Event to the SSE wire format.

parse_sse(raw)

Parse a raw SSE payload into event dictionaries.

This is a test helper and a reference parser; production clients typically use the browser's EventSource.

stream_events_sync(bus, last_event_id=None, *, heartbeat_interval=None)

Yield events from bus, replaying missed events when last_event_id is given.

This synchronous generator is useful for tests, CLIs, and adapters that run in a worker thread. It stops when the bus is closed.

stream_events(bus, last_event_id=None, *, heartbeat_interval=None) async

Async variant of :func:stream_events_sync.