Skip to main content

Sessions API

Sessions store conversation history and context for agent interactions. Each session is identified by a unique session key.

Session Keys

Session keys follow the format:
Examples:
  • user:alice - User session
  • signal:+1234567890 - Signal conversation
  • telegram:@username - Telegram chat
  • discord:123456789 - Discord user
  • hook:webhook-123 - Webhook session

List Sessions

List all sessions with optional filtering.

Method: sessions.list

Request:
string
Filter by agent ID
number
default:50
Maximum number of sessions to return
number
default:0
Pagination offset
Response:
array
Array of session objects
number
Total number of sessions

Preview Session

Get session details and recent message history.

Method: sessions.preview

Request:
string
required
Session key
number
default:20
Number of messages to include
Response:
string
Session key
string
Agent ID
string
Model identifier
array
Array of message objects (most recent first)

Patch Session

Update session metadata (agent, model, settings).

Method: sessions.patch

Request:
string
required
Session key
string
New agent ID
string
New model identifier
string
New thinking budget: "low", "medium", "high"
Response:

Reset Session

Clear session conversation history.

Method: sessions.reset

Request:
string
required
Session key
Response:

Delete Session

Permanently delete a session and its history.

Method: sessions.delete

Request:
string
required
Session key
Response:

Compact Session

Compress session history to reduce storage.

Method: sessions.compact

Request:
string
required
Session key
Response:

Session Storage

Sessions are stored in:
  • Format: JSONL (JSON Lines)
  • Structure: DAG-based conversation tree with parentId links
  • Persistence: File-based storage
Do not modify session files directly. Use the Sessions API to ensure data integrity.

Session Events

Session updates trigger events: Session created:
Session updated:

Example: Session Manager

Best Practices

Choose descriptive prefixes and identifiers:
Periodically delete inactive sessions:
Use sessions.compact for sessions with many messages to reduce storage.
Always use the Sessions API. Direct file modification can corrupt the session DAG.

Next Steps

Agent Protocol

Invoke agents with session context

Messages

Send messages via channels