Skip to main content

Full session lifecycle: entry, transcript, pruning, and compaction for multi-channel AI systems

Project description

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")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nodus_session-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nodus_session-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file nodus_session-0.1.0.tar.gz.

File metadata

  • Download URL: nodus_session-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for nodus_session-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2072d82fed4ab59b5e478f498c499cf4cd4163331f4540dcd04fd96ecb9d658f
MD5 64b1a2a6dd5bbd7dc0d0909d5310e394
BLAKE2b-256 4771fec50b4f024f5c0f42916b3a59aa0df87f0c72f02856d0850ae8a073445f

See more details on using hashes here.

File details

Details for the file nodus_session-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nodus_session-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for nodus_session-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b91de6ff2192daf614aa8a954f5f250643bd770ef0a272ef600fef375e7d191
MD5 06c19fc1147a02bd9bd1fcc08d7cceb7
BLAKE2b-256 8fa8809480e3b9e016d2c0c40aaf7fcf256b0eeec5d5a75f9b18764884dbe0a3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page