Token-bounded short-term memory for Autourgos agents — TokenBufferedMemory.
Project description
autourgos-token-memory
Token-bounded short-term memory for Autourgos agents.
Keeps messages in RAM and evicts the oldest ones when the total token count exceeds a budget. Automatically uses tiktoken for accurate counts if installed, with a fast character-based heuristic as fallback.
Install
pip install autourgos-token-memory
# For accurate tiktoken counts (recommended for OpenAI models)
pip install 'autourgos-token-memory[tiktoken]'
Quick Start
from autourgos_token_memory import TokenBufferedMemory
from autourgos_react_agent import ReactAgent
memory = TokenBufferedMemory(max_tokens=4000)
agent = ReactAgent(llm=my_llm, memory=memory)
agent.invoke("Long conversation task...")
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
max_tokens |
int | 2000 |
Token budget. Oldest messages evicted when exceeded. |
token_estimator |
callable | None |
Custom (text: str) -> int. Defaults to tiktoken / heuristic. |
Custom token estimator
from autourgos_token_memory import TokenBufferedMemory
def my_estimator(text: str) -> int:
return len(text.split()) # word count
memory = TokenBufferedMemory(max_tokens=500, token_estimator=my_estimator)
Token counting
- tiktoken installed: uses
cl100k_baseencoding (accurate for GPT-3.5/4/4o). - tiktoken not installed: Unicode-aware heuristic — ~0.25 tokens per ASCII char, ~1.5 per CJK character.
Check current usage:
print(memory.total_tokens) # → int
Links
- PyPI: https://pypi.org/project/autourgos-token-memory/
- GitHub: https://github.com/devxjitin/autourgos-token-memory
- Issues: https://github.com/devxjitin/autourgos-token-memory/issues
License
MIT — see 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 autourgos_token_memory-1.0.0.tar.gz.
File metadata
- Download URL: autourgos_token_memory-1.0.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1788c7c1dd5d6a6b3f95f4bd6b7c89c7747481da283668d39a96bc4e19ede618
|
|
| MD5 |
3534892ce11adae7c2ea050df9699f5d
|
|
| BLAKE2b-256 |
725a18437b0e4c47a20f94d0fe1b9cc9439f09051f5af9adab1a31adb22ed426
|
File details
Details for the file autourgos_token_memory-1.0.0-py3-none-any.whl.
File metadata
- Download URL: autourgos_token_memory-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
501200722d20915eb14300528157b992d27b3738bbb1d9fef77178ee360e4871
|
|
| MD5 |
b34bd51cd5570b75df360ccd853c5092
|
|
| BLAKE2b-256 |
5ff2f75633256c67ebb6c3097ece3e6145191686e1ba94062f2ecb20bbbe0a8e
|