Context recovery for AI agents — analyze fatigue, compress context, improve token efficiency
Project description
agent-cop
Context recovery for AI agents. Analyze fatigue, compress context, improve token efficiency.
from agent_cop import analyze, recover
# Detect context bloat
report = analyze(messages)
# → { fatigue_score: 73, issues: [...], ... }
# Recover with algorithmic compression (free, no API key needed)
result = await recover(messages, budget_ratio=0.4)
# → { messages: [...], stats: { compression_ratio: "62.3%", ... } }
# Recover with LLM-based deep summarization (requires openai key)
result = await recover(messages, deep=True, openai_api_key="sk-...")
Quick install
pip install agent-cop
For deep LLM summarization:
pip install "agent-cop[deep]"
API
analyze(messages)
Detect context fatigue and bloat in a message history.
recover(messages, budget_ratio=0.5, deep=False, openai_api_key=None)
Compress a message history to fit within a budget. Algorithmic by default (free). Pass deep=True with an OpenAI key for semantic LLM-based summarization.
LangChain integration
from agent_cop.langchain import CopCallback
from langchain.agents import AgentExecutor
callback = SpaCallback(threshold=0.8)
agent = AgentExecutor(..., callbacks=[callback])
# Auto-recovers context at 80% token usage
REST API
curl -X POST https://api.agent-spa.dev/v1/recover \
-H "x-api-key: $KEY" \
-H "Content-Type: application/json" \
-d '{"messages": [...], "budget_ratio": 0.4, "deep": true}'
Generate a free API key at https://agent-cop.dev.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_context_recovery-0.1.0.tar.gz.
File metadata
- Download URL: agent_context_recovery-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c6a6a9fe3675b2d1a801cf3a158383bf0027a2444cb15f9767585a063aa43c6
|
|
| MD5 |
d11a6572c7e522fd42ad21896d21bc71
|
|
| BLAKE2b-256 |
903377c4ec850d1f0cfd4e1bd93b0cf761fcad59e1a7a9aeccb54197252ad5a4
|
File details
Details for the file agent_context_recovery-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agent_context_recovery-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a231ed0d1ac4b6794376b962d793816b22a08cdaeb061f5584d98695b54b7491
|
|
| MD5 |
10df236b5ec5ee935228a32819c8ce8b
|
|
| BLAKE2b-256 |
8900448f10e798f2995cbcd90bb209edcdbef31cd0096f07a2fc04268eb805a4
|