Skip to content

API Reference parrot.tools.compression.tee

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.compression.tee

View source

Compression tee — the working-memory escape hatch (spec Sec 3 Module 3, G3).

No unrecoverable loss: anything lossy-compressed must be recoverable by the agent without re-running the tool. :class:CompressionTee persists the full pre-compression payload into the session's WorkingMemoryToolkit and :func:attach_tee_pointer appends a _tee pointer block to the compressed result so the LLM can call wm_get_result to recover it.

Consumer relationship only: this module never modifies WorkingMemoryToolkit's public API, and never constructs one — the caller (ToolManager) locates an already-registered instance.

Provenance and honest failure (FEAT-538)

The tee writes after the manager's dispatch has finished — the compression stage runs past the observed execution boundary, so the per-invocation context has already been reset by the time :meth:CompressionTee.store runs. With task memory enabled the producing attempt is therefore read from the explicitly retained producer (:meth:TurnTaskSession.retained_producer), or supplied by the caller; when neither exists the answer is None and the legacy write runs unchanged rather than a producer being invented.

The failure rule is unchanged and now stricter about what it claims: a tee that could not persist still returns None (the caller must fall back to the uncompressed payload), attaches no artifact receipt, and marks the producing attempt's tracking as degraded. A failed tee is never evidence, and never durable.

Class CompressionTee

Working-memory escape hatch for lossy/failed tool results.

Note on turn_id: ToolManager has no conversational-turn concept today (verified — no turn_id attribute or parameter anywhere in manager.py). This class therefore uses a stable per-instance identifier (generated once, at construction) as the turn_id component of the tee key — stable because one CompressionTee is constructed per ToolManager (one per user session after clone()), which is the closest available proxy for "this session's turn". Retention correspondingly tracks the last N tee ENTRIES rather than N conversational turns, since no turn boundary signal exists to key eviction on. Documented deviation — see TASK-1953 Completion Note.

Parameter Type Default Description
working_memory Optional['WorkingMemoryToolkit'] None An already-registered WorkingMemoryToolkit instance, or None if the session has none (tee disabled, see :attr:available).
max_retained int 200 Maximum number of tee entries kept before the oldest is evicted via drop_stored().

Attributes:

Attribute Type Description
available bool True when a WorkingMemoryToolkit is registered.

Method CompressionTee.bind_working_memory

(Re)bind the WorkingMemoryToolkit instance backing this tee.

ToolManager resolves this lazily, since tools/toolkits are typically registered AFTER the manager (and its CompressionTee) is constructed — a WorkingMemoryToolkit registered mid-session makes the tee available from that point on.

bind_working_memory(working_memory: Optional['WorkingMemoryToolkit']) -> None

Parameter Type Default Description
working_memory Optional['WorkingMemoryToolkit'] The current WorkingMemoryToolkit instance, or None if none is registered.

Method CompressionTee.store

Persist the full payload to working memory.

Never raises: a failing tee must never break a tool call. On failure (including "unavailable"), logs a warning (when applicable) and returns None — callers must then fall back to returning the original, uncompressed payload (losing data because the escape hatch failed is exactly what G3 forbids).

With task memory enabled the write is versioned and attributed to the producing attempt, and the resulting artifact_id@version is attached to that attempt's receipt. A failure attaches nothing and marks the attempt's tracking degraded instead: a tee that did not persist is not evidence that it did.

store(tool_name: str, payload: Any, reason: str, *, producer_call_id: Optional[str] = None) -> Optional[str]

Parameter Type Default Description
tool_name str Name of the tool whose result is being teed.
payload Any The FULL, pre-compression payload to persist.
reason str Why this payload is being teed (e.g. "lossy", "error") — stored in the entry's metadata and echoed in the _tee pointer block.
producer_call_id Optional[str] None The attempt this payload came from. Defaults to the retained producer, which is how the correlation survives the manager's post-dispatch context reset.

Returns: Optional[str] — The tee key on success, None if unavailable or the store failed.

Method CompressionTee.cleanup

Drop every retained tee entry — call on session cleanup.

cleanup() -> None

Alias WorkingMemoryToolkit

Re-exported from parrot.tools.working_memory.WorkingMemoryToolkit.

Function attach_tee_pointer

Append the _tee recovery pointer block to payload (spec Sec 2).

attach_tee_pointer(payload: Any, key: str, reason: str) -> Any

Parameter Type Default Description
payload Any The compressed payload to annotate.
key str The tee key returned by :meth:CompressionTee.store.
reason str Why the payload was teed ("lossy" or "error").

Returns: Any — payload with a _tee block appended. Dict payloads gain the key directly; non-dict payloads are wrapped as {"result": payload, "_tee": {...}} so the pointer is always reachable without silently discarding a non-dict result.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally