The State Sidecar for AI Agents
Project description
📖 Chronicle-Gist: The State Sidecar for AI Agents
Chronicle-Gist is a lightweight Python library designed to solve the "Context Window Bloat" in agentic workflows. It distills massive conversation histories into a permanent, structured State Ledger, allowing your agents to remember everything while paying for almost nothing.
🚀 The Problem: The Loyalty Tax
The more a user talks to your agent, the more expensive that user becomes. By turn 50, you are paying for 5,000+ tokens of redundant history just to get a simple answer.
Chronicle-Gist reduces this by 80%+ using a tiered memory approach.
✨ Features
- Tiered Memory: Combines a high-resolution buffer (L1) with a permanent narrative summary (L2).
- Fact Ledger: Automatically extracts and persists a JSON "Source of Truth" (e.g., user preferences, names).
- Arbitrage Logic: Uses cheap models (Llama 8B) to compress history for expensive models (GPT-4o/Llama 70B).
- Zero-Dementia: Ensures critical facts are never "summarized away" during compression.
📦 Installation
pip install chronicle-gist
🛠️ Quick Start
Chronicle-Gist is designed as a Sidecar. You call it before you call your LLM to prepare the perfect, lean prompt.
import os
import asyncio
from chronicle_gist import Chronicle
# 1. Initialize with your API Key (Groq, OpenAI, etc.)
# "Arbitrage": Use a cheap model (e.g., Llama 3 8B) for the compression work.
chronicle = Chronicle(
api_key=os.getenv("GROQ_API_KEY"),
model_name="groq/llama-3.1-8b-instant",
token_threshold=1000
)
async def main():
session_id = "user_123"
# 2. Your Agent's State
history = [
{"role": "user", "content": "My name is Alex and I'm allergic to peanuts."},
{"role": "assistant", "content": "Noted, Alex."},
# ... imagine 50 more messages ...
]
new_msg = {"role": "user", "content": "Can I eat this Pad Thai?"}
# 3. The Sidecar hydrates the state and returns a lean prompt
# It extracts facts (Allergy: Peanuts) and compresses the rest.
context = await chronicle.process_async(session_id, new_msg, history)
# 4. Call your LLM as usual with the optimized prompt
# (Example using generic print, but you'd pass `context['hydrated_messages']` to OpenAI/Anthropic)
print("--- Optimized Prompt ---")
print(context['hydrated_messages'][0]['content'])
# Output:
# [MEMORY RECALL]
# Summary: User Alex has discussed food preferences...
# [FACT LEDGER]
# { "name": "Alex", "allergies": ["Peanuts"] }
print(f"\nTokens Saved: {context['meta']['tokens_saved']}")
if __name__ == "__main__":
asyncio.run(main())
📊 The "Arbitrage" Dashboard
When you use Chronicle-Gist, you get real-time transparency into your agent's cognitive efficiency.
| Metric | Naive Approach | Chronicle-Gist |
|---|---|---|
| Prompt Size | 5,200 tokens | 410 tokens |
| Latency | 1.8s | 0.4s |
| Cost | $0.0050 | $0.0004 |
🏗️ Architecture
Chronicle-Gist follows the Sawtooth Memory Pattern. Every time your history hits the limit, it's compressed into the permanent state, resetting the context window while preserving the "Essence."
🤝 Contributing
We love contributors! Whether it's fixing a bug or adding a new "State Provider" (like Redis or Cassandra), feel free to open a PR.
🛡️ License
MIT License.
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 chronicle_gist-0.2.2.tar.gz.
File metadata
- Download URL: chronicle_gist-0.2.2.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7b9e1cb77e01db47bf9e970a6b5827ba297fad24ce20948c9cb98c961b4ab1b
|
|
| MD5 |
5e51af05e7b7af791f642611b3f8f8cc
|
|
| BLAKE2b-256 |
f8c72c73dc3d91337d54da6729b9bc479d3a1b60e6bd46d54c3761e24be41669
|
File details
Details for the file chronicle_gist-0.2.2-py3-none-any.whl.
File metadata
- Download URL: chronicle_gist-0.2.2-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a379badf91adf5ac54c24580faf4f06bb2ff77604cf24bb45607379bad0a9666
|
|
| MD5 |
26a6f599f9d012302f464ebf2ebb9a99
|
|
| BLAKE2b-256 |
c347b7b3d6f3758193cda43eda5ad9e4ca1a6394fb82a969e26e0af1870b7cf2
|