Skip to main content

purra-compaction · Python

English | 简体中文

Compress older conversation turns with a model call when PurrA's context budget requires it. Instructions and recent complete turns, including tool results, remain in the input.

Install

From the repository root, with Python 3.11+:

python -m pip install . ./integrations/compaction/python

Configure

from purra.context_orchestration import ContextCompressionCoordinator
from purra_compaction import SemanticCompaction

def compactor(model_tasks):
    return ContextCompressionCoordinator(SemanticCompaction(
        model_tasks,
        max_summary_tokens=1024,
        max_input_tokens=16000,
        keep_recent_messages=8,
    ))

Attach the factory to your existing Agent preset. Core supplies the Run-bound model task runner:

from dataclasses import replace
from purra.api import AgentComponentBinding

preset = replace(
    preset,
    conversation_compactor_factory=compactor,
    component_bindings={
        **preset.component_bindings,
        "conversationCompactor": AgentComponentBinding("semantic-compaction", "1"),
    },
)

Pass this preset to AgentCore. Keep the component binding stable during recovery; change its revision when the compression configuration changes.

Option Default Purpose
max_summary_tokens 1024 Output limit for the summary call
max_input_tokens 16000 Maximum estimated input tokens for the summarizer
keep_recent_messages 8 Recent-message retention target, adjusted to complete turns

Behavior

Each compression uses one managed model call and consumes the Run's budget. The summary retains goals, constraints, decisions, completed work, open questions, and evidence references. Private reasoning and provider continuation data are excluded from the summarizer input.

The summary is untrusted historical context. Invalid or oversized summaries fail without replacing the input. Set the input limit within the summarizer model's available context window. The application retains the original conversation.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

purra_compaction-0.5.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

purra_compaction-0.5.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file purra_compaction-0.5.1.tar.gz.

File metadata

  • Download URL: purra_compaction-0.5.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for purra_compaction-0.5.1.tar.gz
Algorithm Hash digest
SHA256 d5b0c95e88f81a14a8b1b220231fa41950f1681c31f7bb854ebd3aeef08c320d
MD5 e06bc8af38ca1bd3eb05902e165830ab
BLAKE2b-256 bd4fbed7e53cbcf0616e8268c6c85b44c6c134f09473da10608fc5e44bd87384

See more details on using hashes here.

Provenance

The following attestation bundles were made for purra_compaction-0.5.1.tar.gz:

Publisher: release.yml on Lybrands/purra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file purra_compaction-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for purra_compaction-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb553125ef67d2b4d499ff6c264a72de1bf78aca15e3a1ef222db22cad19ee54
MD5 5b6ab36bc340a2ac6f47f3157eb86c08
BLAKE2b-256 513c0b1dc25b12591aff2f0c7d2fe818aeebdc1b03b04a10a00713213a99a768

See more details on using hashes here.

Provenance

The following attestation bundles were made for purra_compaction-0.5.1-py3-none-any.whl:

Publisher: release.yml on Lybrands/purra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 files

0.5.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page