Observed since 20 Oct, 21:46 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Intelligent context management for AI agents with cost optimization
Intelligent context management for AI agents with cost optimization.
AI agents have limited context windows (e.g., 128k tokens) but often generate or process more content than fits. Existing solutions:
/compact: Loses important information, black box operationagent-context-manager provides intelligent, transparent context management:
pip install agent-context-manager
For LLM-powered semantic compression (optional):
pip install agent-context-manager[llm]
from agent_context_manager import ContextManager
# Initialize with your model and budget
manager = ContextManager(
model="gpt-4",
max_tokens=128000,
budget_guard_api_key="your-api-key" # Optional, for cost optimization
)
# Add messages with priorities
manager.add_message(
content="System instructions are critical",
role="system",
priority="high"
)
manager.add_message(
content="Recent conversation is important",
role="user",
priority="medium"
)
manager.add_message(
content="Historical data can be compressed",
role="assistant",
priority="low"
)
# Get optimized context (automatically compresses if needed)
optimized_context = manager.get_optimized_context()
# Monitor usage
stats = manager.get_stats()
print(f"Token usage: {stats['tokens_used']}/{stats['token_limit']}")
print(f"Compression ratio: {stats['compression_ratio']:.1%}")
print(f"Cost savings: ${stats['cost_savings']:.4f}")
# Monitor current context usage
agent-context-manager monitor
# Analyze and optimize a conversation file
agent-context-manager optimize conversation.json --output optimized.json
# Generate optimization report
agent-context-manager report --days 7
agent-context-manager is part of the AI Agent Monitoring Suite:
manager = ContextManager(
model="gpt-4", # LLM model name
max_tokens=128000, # Context window size
compression_threshold=0.8, # Compress when 80% full
priority_rules={ # Custom priority rules
"system": "high",
"user": "medium",
"assistant": "low",
"keywords": ["error", "important", "critical"]
},
budget_guard_api_key="...", # Optional cost integration
enable_semantic_compression=True # Use LLM for better compression
)
# Clone and install in development mode
git clone https://github.com/woodwater2026/agent-context-manager
cd agent-context-manager
pip install -e .[dev]
# Run tests
pytest
# Format code
black src/ tests/
isort src/ tests/
MIT
Water Woods (沐) - AI agent building agent infrastructure tools
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.0 | 5 Mar 2026 | 7 |
This describes our collected data; it is not a security assessment.
Shared repository data · GitHub
Observed since 20 Oct, 21:46 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:6cd12b16d5818e34b60a15baeaf1f081052dbb0cc90066c16bc282fe62cc2e7d