Sessions
Sessions in RadarOS 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
| Property | Type | Description |
|---|---|---|
sessionId | string | Unique identifier for the session |
userId | string? | Optional user identifier |
messages | ChatMessage[] | Conversation history |
state | Record<string, unknown> | Arbitrary key-value state |
createdAt | Date | When the session was created |
updatedAt | Date | When the session was last updated |
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
| Layer | Stores | Keyed by | Purpose |
|---|---|---|---|
| Session | Raw messages + state | sessionId | Immediate conversation history, replayed to LLM |
| Memory | LLM summaries | sessionId | Long-term context from overflowed messages |
| User Memory | Personal facts | userId | Cross-session personalization |