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.

Metadata

Release files for purra-compaction 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for purra-compaction 1.0.5
File Size Uploaded Provenance Actions
purra_compaction-1.0.5.tar.gz 5.8 kB With provenance Details for purra_compaction-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for purra-compaction 1.0.5
File Interpreter ABI Platform Actions
purra_compaction-1.0.5-py3-none-any.whl Python 3 none any Details for purra_compaction-1.0.5-py3-none-any.whl

Total release size: 11.1 kB

Release files / purra_compaction-1.0.5.tar.gz

Download URL purra_compaction-1.0.5.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
33b8b3a4b0757ed0682f77770b79ffb75dd4002bbd3658aca5bb618f21e4957d
BLAKE2b-256 checksum
How to use checksums
cfe2a9efdb91a4dc2882c5eb09462e6c52044037f0660b640ddadae27e5a21c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Release files / purra_compaction-1.0.5-py3-none-any.whl

Download URL purra_compaction-1.0.5-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb0577fb9f1cfb934764d46c734c3387c24516f79b71a77f29484d2c837a770c
BLAKE2b-256 checksum
How to use checksums
6b4571e7fad20c9169356ade58fca3f63da5713b6c2037ec35bc648e2f24e2e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

Security for purra-compaction 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for purra_compaction-1.0.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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