Skip to main content

nodus-session

Full session lifecycle for multi-channel AI systems. Manages conversation entries, transcripts, pruning, and compaction. Zero required dependencies — pure Python stdlib. Optionally integrates with nodus-state for typed session keys.

Install

pip install nodus-session

# With nodus-state integration (typed SessionKey)
pip install "nodus-session[nodus-state]"

Usage

Session entries

from nodus_session import SessionEntry, SessionKey, InMemorySessionStore

store = InMemorySessionStore()

key = SessionKey(agent_id="assistant", channel="web", peer="user-1")
entry = SessionEntry.create(key, provenance={"channel_id": "web"})
entry.append_message({"role": "user", "content": "Hello"})
entry.append_message({"role": "assistant", "content": "Hi there!"})
store.save(entry)

Session manager

from nodus_session import SessionManager, InMemorySessionStore, SessionKey

store = InMemorySessionStore()
manager = SessionManager(store)

key = SessionKey(agent_id="assistant", channel="api", peer="user-42")
manager.append_message(key, {"role": "user", "content": "What time is it?"})

entry = manager.get_or_create(key)
print(len(entry.messages))  # 1

Pruning policy

from nodus_session import SessionManager, SessionPruningPolicy, InMemorySessionStore

policy = SessionPruningPolicy(
    max_age_days=30,
    max_inactivity_days=7,
    max_messages=200,
    max_sessions_per_agent=10,
)
manager = SessionManager(InMemorySessionStore(), policy=policy)

# Delete sessions that violate the policy
deleted = manager.prune(agent_id="assistant")

Compaction

# Pass any callable (messages: list[dict]) -> list[dict]
def keep_last_50(messages):
    return messages[-50:]

removed = manager.compact(key, strategy=keep_last_50)
print(f"Compacted {removed} messages")

Metadata

Release files for nodus-session 0.1.0

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

Source distribution (sdist)

Source distribution for nodus-session 0.1.0
File Size Uploaded
nodus_session-0.1.0.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nodus-session 0.1.0
File Interpreter ABI Platform
nodus_session-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / nodus_session-0.1.0.tar.gz

Download URL nodus_session-0.1.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2072d82fed4ab59b5e478f498c499cf4cd4163331f4540dcd04fd96ecb9d658f
BLAKE2b-256 checksum
How to use checksums
4771fec50b4f024f5c0f42916b3a59aa0df87f0c72f02856d0850ae8a073445f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release files / nodus_session-0.1.0-py3-none-any.whl

Download URL nodus_session-0.1.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b91de6ff2192daf614aa8a954f5f250643bd770ef0a272ef600fef375e7d191
BLAKE2b-256 checksum
How to use checksums
8fa8809480e3b9e016d2c0c40aaf7fcf256b0eeec5d5a75f9b18764884dbe0a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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