Archived
This project has been archived by its maintainers, and is no longer receiving any updates.
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
my_llm below is any chat-model instance, e.g. OpenAIChatModel from autourgos-openaichat (pip install autourgos-openaichat). See that package's README for setup.
from autourgos_token_memory import TokenBufferedMemory
from autourgos_react_agent import ReactAgent
from autourgos_openaichat import OpenAIChatModel
my_llm = OpenAIChatModel(model="gpt-4o-mini") # needs OPENAI_API_KEY set
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
Metadata
Release files for autourgos-token-memory 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| autourgos_token_memory-2.0.1.tar.gz | 6.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autourgos_token_memory-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.5 kB
Release files / autourgos_token_memory-2.0.1.tar.gz
| Download URL | autourgos_token_memory-2.0.1.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e81f209ddca40a02fac821938f4269d64e2a35c2f63edd389bbeeb043c0a7db7
|
|
BLAKE2b-256 checksum How to use checksums |
a020c90738c50a606acab54d634fc4e44973ddc88da85b3e64ac757a10243cae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / autourgos_token_memory-2.0.1-py3-none-any.whl
| Download URL | autourgos_token_memory-2.0.1-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
005bcac3adedd30849305ef37850044a12d88346fc58c9880b8ec9266ad1f361
|
|
BLAKE2b-256 checksum How to use checksums |
f08b49cd8bde966eb613fea67837b17dd19147b42ebc54ed6881245280de0c65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|