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.1.0
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.1.0.tar.gz | 16.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autourgos_token_memory-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.1 kB
Release files / autourgos_token_memory-2.1.0.tar.gz
| Download URL | autourgos_token_memory-2.1.0.tar.gz |
|---|---|
| Size | 16.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f01f5aea58ead978ad532759ddafbd79cb931aa68d7690d789eaffec490ea8e2
|
|
BLAKE2b-256 checksum How to use checksums |
5ed65520f46bac40c16c8e2221c463db932ac4996c860d91287c85f3c896c652
|
| 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.1.0-py3-none-any.whl
| Download URL | autourgos_token_memory-2.1.0-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b8865eda53c2dc3d7283b403ded1b102f1ceb620f9000f30b946f6461985364
|
|
BLAKE2b-256 checksum How to use checksums |
340d28d72537332f7bff29d802893a2bf1ba8ac78478b2722f07574f38b88c5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|