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.4
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.4.tar.gz | 16.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autourgos_token_memory-2.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.2 kB
Release files / autourgos_token_memory-2.0.4.tar.gz
| Download URL | autourgos_token_memory-2.0.4.tar.gz |
|---|---|
| Size | 16.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d70fd8e7b6254cdb7dc8bf46a38dd39a703f298889d5c4d46d6047e17beed322
|
|
BLAKE2b-256 checksum How to use checksums |
8632676cf97167b18ad1a2f60b9eaf9f2a8d8ea8b794fb7d6f1487976ae401e4
|
| 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.4-py3-none-any.whl
| Download URL | autourgos_token_memory-2.0.4-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17adb8bdf327bad460d7c1adcb9b355ddbb1fe0171cf891f5c2d70ece12b9c7a
|
|
BLAKE2b-256 checksum How to use checksums |
25ff80ff5c82ad294ed44d721cb47681a9e89180c7d57634e674e24a63bbbac4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|