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.0.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.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: purra_compaction-0.5.0.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.0.tar.gz
Algorithm Hash digest
SHA256 be886c7a54d77d1d0182f1310089b2c258de18287861567bf50da6fc5c9dabbb
MD5 1d46c7d523197c285c2d0c56407daa35
BLAKE2b-256 340e0e6176767cba7e95bfc7ed5d9ea4d4558061dac314a87f23fea921b02e9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for purra_compaction-0.5.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for purra_compaction-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 079e4471f0e30af2fb3f9ebc306bbdfcc1927fd16acfca177c9814015259f4f6
MD5 928443190c1c92a5d40cd4a7cdf7e149
BLAKE2b-256 6cdb2bfcd06ebe0af601bbb91cc70af625302886d87c85e5fb1fbd1337868013

See more details on using hashes here.

Provenance

The following attestation bundles were made for purra_compaction-0.5.0-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

0.5.1

2 files

This release

0.5.0 This release

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