Skip to content

API Reference parrot.tools.compression.stage

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

parrot.tools.compression.stage

View source

CompressionStage — the pure, independently testable core of the tool-result compression pipeline (spec Sec 3 Module 2).

Given a tool name, its unwrapped result payload, execution status, and metadata, decides whether to compress, with which codec, at which :class:~parrot.tools.compression.levels.FilterLevel, on which :class:~parrot.tools.compression.budget.Route — and returns the (possibly compressed) payload plus a compression-metadata dict.

Deliberately decoupled from ToolManager: this module does not import or touch parrot.tools.manager. Wiring this stage into ToolManager.execute_tool() is TASK-1952's job.

Alias BudgetRouter

Re-exported from parrot.tools.compression.budget.BudgetRouter.

Alias CompressionOutcome

Re-exported from parrot.tools.compression.protocol.CompressionOutcome.

Class CompressionStage

Decides whether/how to compress a tool result, and dispatches to a codec via the latency-budget router.

Never raises: every failure path (unknown codec, codec exception, budget passthrough) returns the ORIGINAL payload unchanged plus a compression_skipped reason in the metadata dict. A broken codec can never break a tool call.

Parameter Type Default Description
registry CompressorRegistry Loaded, immutable :class:CompressorRegistry.
router BudgetRouter :class:BudgetRouter deciding inline/executor/passthrough.
tee Optional[TeeLike] None Optional :class:~parrot.tools.compression.tee.CompressionTee (or legacy bare callable, see :data:TeeLike) invoked when a codec reports lossy=True, to persist the original payload to working memory. None → tee disabled: lossy levels (NORMAL/AGGRESSIVE) are capped to MINIMAL (G3 — never lossy without recovery); a bare callable is always treated as available (it cannot be introspected).
rust_available Optional[bool] None Override for Rust-extension detection (mainly for tests). Defaults to :func:~parrot.tools.compression.budget.is_rust_available.

Method CompressionStage.run

Run the compression pipeline for a single tool result.

run(tool_name: str, payload: Any, *, status: str, metadata: dict[str, Any], return_direct: bool, level_override: Optional[FilterLevel] = None) -> tuple[Any, dict[str, Any]]

Parameter Type Default Description
tool_name str Name of the tool that produced payload.
payload Any The UNWRAPPED tool result (never a ToolResult).
status str The tool call's status (e.g. "success", "error"). Anything other than "success" forces :attr:FilterLevel.NONE (G5).
metadata dict[str, Any] The result's existing metadata dict. Read-only here — this method never mutates it in place; the caller merges the returned metadata.
return_direct bool When True, the pipeline is skipped entirely (tee included) — the tool author's verbatim output must not be altered.
level_override Optional[FilterLevel] None Optional per-call override, highest precedence.

Returns: tuple[Any, dict[str, Any]] — A (payload, compression_metadata) tuple. payload is the original object, unchanged, on every skip/error path; it is the codec's compressed output on the happy path.

Alias CompressionTee

Re-exported from parrot.tools.compression.tee.CompressionTee.

Alias CompressorRegistry

Re-exported from parrot.tools.compression.registry.CompressorRegistry.

Alias FilterLevel

Re-exported from parrot.tools.compression.levels.FilterLevel.

Alias Route

Re-exported from parrot.tools.compression.budget.Route.

Attribute TeeCallback

Attribute TeeLike

Alias attach_tee_pointer

Re-exported from parrot.tools.compression.tee.attach_tee_pointer.

Alias cap

Re-exported from parrot.tools.compression.levels.cap.

Alias get_codec

Re-exported from parrot.tools.compression.protocol.get_codec.

Alias is_rust_available

Re-exported from parrot.tools.compression.budget.is_rust_available.

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