Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

autourgos-token-memory

Framework: Autourgos Python License: Apache 2.0 Author Contributor Contributor

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
  • tiktoken support (optional) — accurate cl100k_base counts for GPT-3.5/4/4o when installed
  • Unicode-aware heuristic fallback — ~0.25 tokens/ASCII char, ~1.5/CJK char when tiktoken isn't installed
  • Custom estimator — swap in your own (text: str) -> int counter

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_base encoding (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.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autourgos-token-memory 2.0.3
File Size Uploaded
autourgos_token_memory-2.0.3.tar.gz 16.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autourgos-token-memory 2.0.3
File Interpreter ABI Platform
autourgos_token_memory-2.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 30.3 kB

Release files / autourgos_token_memory-2.0.3.tar.gz

Download URL autourgos_token_memory-2.0.3.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
172f9a1510abc5e06cfa305cb6153491bcd122e39a24e9784de33cb0e5d5ab8c
BLAKE2b-256 checksum
How to use checksums
9b8d0b115b89ee66047f610669d41596a71ba1b9a7c6f2b5ce5005559c1253c7
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.3-py3-none-any.whl

Download URL autourgos_token_memory-2.0.3-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7e3c0cc2dbea21a9f05f7d5477989134304eb4139217ba350a8ca8ed8c6dcdf
BLAKE2b-256 checksum
How to use checksums
c7f230eaae43303b76e4b52ce392b1cb22ba75b7f6679489322cf2daf51b5b9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page