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.
from autourgos_token_memory import TokenBufferedMemory
from autourgos_agent import Agent
from autourgos_openaichat import OpenAIChatModel
my_llm = OpenAIChatModel(model="gpt-4o-mini") # needs OPENAI_API_KEY set
memory = TokenBufferedMemory(max_tokens=4000)
agent = Agent(llm=my_llm, memory=memory)
Features
- Token-budget eviction, not message-count — a better proxy for what actually blows an LLM's context
tiktokensupport (optional) — accuratecl100k_basecounts for GPT-3.5/4/4o when installed- Unicode-aware heuristic fallback — ~0.25 tokens/ASCII char, ~1.5/CJK char when
tiktokenisn't installed - Custom estimator — swap in your own
(text: str) -> intcounter
Table of Contents
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_agent import Agent
from autourgos_openaichat import OpenAIChatModel
my_llm = OpenAIChatModel(model="gpt-4o-mini") # needs OPENAI_API_KEY set
memory = TokenBufferedMemory(max_tokens=4000)
agent = Agent(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
License
Apache License 2.0, Copyright (c) 2026 Jitin Kumar Sengar
Metadata
Release files for autourgos-token-memory 2.0.2
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.2.tar.gz | 16.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autourgos_token_memory-2.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.2 kB
Release files / autourgos_token_memory-2.0.2.tar.gz
| Download URL | autourgos_token_memory-2.0.2.tar.gz |
|---|---|
| Size | 16.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2db6322af204e1b890adbab506e07fd62626bb0616f9a223249b9b1879023214
|
|
BLAKE2b-256 checksum How to use checksums |
68da18b32cbf8ac166ee422b15c9422f26b2df264fdebb4aa980aa1da02f3824
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / autourgos_token_memory-2.0.2-py3-none-any.whl
| Download URL | autourgos_token_memory-2.0.2-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dffdf720c5c53fc35e6e9c76bfbc04fda6ca1a433769f018359bf79effbde0b0
|
|
BLAKE2b-256 checksum How to use checksums |
eae32aa0793033c8ab8a19c1d77e85357576be01f747cf5253b2364634965d83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|