swarmauri_agent_compacting
swarmauri_agent_compacting
Swarmauri text agent with manual and token-triggered conversation compaction.
Overview · Installation · Quick Start · Usage · API · Contributing · Governance · License
Overview
Summary
Run text conversations that keep recent turns and summarize older complete turns.
Why This Package
Reduce the model input consumed by long conversations while preserving recent context.
When to Use
Use this agent when a chat model needs to stay within a token budget across many turns.
Features
- Manual compaction through
compact()andacompact(). - Token-triggered compaction before
exec()andaexec()dispatch. - Optional dedicated summarizer and an input limit enforced after compaction.
Non-Goals
The caller supplies the model and a token counter for its input format.
Getting Started
Prerequisites
Use Python 3.10 through 3.14. Run the source installation commands from this package's directory.
Installation
uv
swarmauri_agent_compacting is not declared published. From the source checkout:
uv pip install .
pip
swarmauri_agent_compacting is not declared published. From the source checkout:
python -m pip install .
Poetry
swarmauri_agent_compacting is not declared published. From a separate Poetry project, replace the path with your checkout:
poetry add /path/to/swarmauri_agent_compacting
Quick Start
Example
Source: docs/readme/quick_start.py.
from swarmauri_agent_compacting import CompactingAgent
assert CompactingAgent.__name__ == "CompactingAgent"
Expected Result
The quick start loads the package's public agent class without starting a service or calling a model.
Usage
Common Workflows
Source: docs/readme/usage.py.
from swarmauri_agent_compacting import CompactingAgent
from swarmauri_conversation_compacting import CompactingConversation
def make_agent(model, count_tokens):
return CompactingAgent(
llm=model,
conversation=CompactingConversation(
trigger_tokens=24_000,
keep_recent_turns=4,
),
count_input_tokens=count_tokens,
max_input_tokens=28_000,
)
def run_turn(agent, prompt):
reply = agent.exec(prompt)
changed = agent.compact()
return reply, changed
async def run_turn_async(agent, prompt):
reply = await agent.aexec(prompt)
changed = await agent.acompact()
return reply, changed
Construct an agent with the model and conversation, then run turns and compact as needed. Both compaction methods return True when they apply a shorter summary.
Configuration
Set trigger_tokens on CompactingConversation for automatic compaction. Omit it for manual operation. Set max_input_tokens on the agent to enforce a limit.
Error Handling
When the budget is still exceeded, the pending message remains in the conversation. Retry with exec() or aexec() without appending it again.
Best Practices
Use one agent per conversation and submit turns sequentially. Provide the token counter again after restoring a serialized agent.
Package Boundary
What It Owns
Text-agent execution and orchestration of manual or automatic conversation compaction.
Public API and Import Surfaces
Import CompactingAgent from swarmauri_agent_compacting and CompactingConversation from swarmauri_conversation_compacting.
Entry Points
swarmauri.agents→CompactingAgent→swarmauri_agent_compacting:CompactingAgent
Injected Dependencies
Pass a Swarmauri text model that appends its reply to the conversation and a callable that counts the model's input tokens.
Protocol Consumers
Use exec() for synchronous text turns and aexec() in asynchronous callers. The batch interfaces process turns in order.
Extensions
Configure a dedicated summarization model and its generation options when the chat model is unsuitable for summaries.
Operations and Readiness
Operational Requirements
Provide model credentials and a token counter appropriate for the deployed provider.
Health and Observability
Observe compaction results and budget errors in the calling application.
Security and Resource Limits
Set max_input_tokens to enforce a per-request input limit after the compaction attempt.
Compatibility
The manifest limits supported Python versions to 3.10 through 3.12.
Verification
Tests
Run the package unit tests to exercise manual and threshold-triggered compaction in both synchronous and asynchronous execution.
Certification Status
The offline tests cover the scenarios listed above. No external certification is claimed.
Evidence
See the package tests for the compaction and budget behaviors.
FAQ
Why
Keep the source of token counts and summarization policy under application control.
How
Start with the source installation and import example, then use the constructor example under Usage.
When
Set a threshold for long-running conversations. Use manual compaction if the caller decides when to summarize.
Documentation and Related Packages
More Documentation
See the CompactingAgent source for constructor parameters and execution methods.
Related Packages
swarmauri_conversation_compacting owns the conversation and summary state.
Project Links
Contributing
How to Contribute
Follow the repository contribution guide and run the package tests when changing the public API.
Development Setup
From pkgs/, run uv run --directory standards/swarmauri_agent_compacting --package swarmauri_agent_compacting pytest.
Notes for Maintainers
Keep the plugin entry points, declared Python support, and maintained README examples aligned with package behavior.
Governance
Ownership and Decision Making
Swarmauri SDK maintainers review package changes in the repository.
Standards and Policies
See the repository README policy for the package documentation contract.
Lifecycle and Migration
This package is in planning. Review API and dependency changes before moving between source revisions.
License and Attribution
License
Licensed under Apache-2.0. See LICENSE.
Notices
See NOTICE for attribution.
Metadata
Release files for swarmauri_agent_compacting 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmauri_agent_compacting-0.1.0.tar.gz | 10.4 kB | Without provenance | Details for swarmauri_agent_compacting-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmauri_agent_compacting-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for swarmauri_agent_compacting-0.1.0-py3-none-any.whl |
Total release size: 22.2 kB
Release files / swarmauri_agent_compacting-0.1.0.tar.gz
| Download URL | swarmauri_agent_compacting-0.1.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
feb0f60050979b8c90d3307582198d650a79ffd043a403b6ed2d97e6ce395fb0
|
|
BLAKE2b-256 checksum How to use checksums |
2d6dd4b16cdb588fa1de0121a43a224a58aaa42d46e59f1a1ec98104f73ca250
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.11 {"installer":{"name":"uv","version":"0.13.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swarmauri_agent_compacting-0.1.0-py3-none-any.whl
| Download URL | swarmauri_agent_compacting-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5bd8bc869c2024bf73d60a43d4a739b515fd85e8a633f3de0d1df5a4a5d2fa14
|
|
BLAKE2b-256 checksum How to use checksums |
f60d7331f1c86de13f1c9ec53bb362a01b8f2d3c11361d83ddf3af346cb51262
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.11 {"installer":{"name":"uv","version":"0.13.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for swarmauri_agent_compacting 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.