Sessions
Sessions in Agentium track conversation history and arbitrary state per conversation. TheSessionManager stores raw messages and replays them as context to the LLM on each run.
How It Works
Every time you callagent.run() or agent.stream() with a sessionId, the agent:
- Loads the session’s message history from storage
- Includes the history as conversation context to the LLM
- After the run, appends the new user/assistant exchange to the session
sessionId across multiple calls, the agent maintains a continuous conversation.
sessionId is omitted, a new UUID is generated per run — each call is a fresh conversation.
Session Object
History Overflow
WhennumHistoryRuns is set on the agent, the session automatically trims older messages to stay within the limit. This prevents the context window from growing unboundedly.
Token-Based Trimming
For tighter control, setmaxContextTokens to automatically trim history based on estimated token count:
Session State
Sessions support arbitrarystate for persisting data across turns. Access it via RunContext.sessionState in hooks or tools:
updateState after each run.
SessionManager API
SessionManager is used internally by agents but can also be used standalone:
Storage Drivers
InMemoryStorage
Default. Sessions live in process memory. Lost on restart. Good for development.
MongoDBStorage
Persistent sessions in MongoDB. Use for production.
SqliteStorage
Persistent sessions in SQLite. Good for single-node deployments.
PostgresStorage
Persistent sessions in PostgreSQL. Use for scalable deployments.
Session vs Memory vs User Memory
Session is always active. Memory kicks in when history overflows. User Memory persists facts about a person across all their sessions. See Memory and User Memory for details.