Persist conversation history across agent runs using pluggable storage backends.
Session management is experimental. APIs may change in future releases.
Sessions let your agent remember previous conversations. When you attach a SessionManager to an agent, it automatically loads history at the start of each run and saves it when the run completes — so the agent picks up exactly where the last conversation left off.
Create a SQLite engine and set up the database tables. Do this once at application startup.
from nexau.archs.session.orm import SQLDatabaseEngineengine = SQLDatabaseEngine.from_url("sqlite+aiosqlite:///sessions.db")await engine.setup_models()
2
Create a SessionManager
from nexau.archs.session import SessionManagersession_manager = SessionManager(engine=engine)
3
Attach the manager to your agent
Pass session_manager, user_id, and session_id when constructing the agent.
from nexau.archs.main_sub.agent import Agent, AgentConfigagent = Agent( config=agent_config, session_manager=session_manager, user_id="user_123", session_id="sess_456",)response = await agent.run_async("Hello, how are you?")# The next run loads this conversation automaticallyresponse2 = await agent.run_async("What did I just ask?")
If you omit session_id, a new session is created. Pass the returned session ID in subsequent requests to continue the same conversation.
When multiple requests try to run against the same session simultaneously, SessionManager uses a distributed lock to prevent conflicting writes. Only one agent run can modify a session at a time.
session_manager = SessionManager( engine=engine, lock_ttl=30.0, # Lock expires after 30 seconds heartbeat_interval=10.0, # Renew lock every 10 seconds)
Parameter
Default
Description
lock_ttl
30.0
Seconds before a lock expires automatically. Prevents deadlocks if a run crashes.
heartbeat_interval
10.0
Seconds between lock renewals during a long-running operation.
For operations that take longer than the default TTL, increase lock_ttl and set heartbeat_interval to roughly one-third of it.