Skip to main content

Overview

A session is a persistent conversation between an agent and a user (or system). Each session has a unique key, an associated agent, and optional channel routing for message delivery. Sessions store conversation history, token counts, model overrides, and metadata. Sessions are the communication boundary, not the unit of tracked work. Use ravi tasks when the work needs an owner, progress, and a terminal state. Use ravi eval when you need reproducible measurement or regression checks.

Session Types

Permanent Sessions

The default type. Permanent sessions persist indefinitely until explicitly reset or deleted.

Ephemeral Sessions

Sessions with a time-to-live (TTL). When the TTL expires, the session is automatically deleted. Ten minutes before expiration, the agent receives a system notification with CLI commands to extend, keep, or delete the session. The ephemeral lifecycle:
  1. A session is made ephemeral with set-ttl
  2. The countdown starts from the current time
  3. At T-10 minutes, the agent receives a [System] Inform: warning
  4. The agent can extend (add more time), keep (make permanent), or delete
  5. If no action is taken, the session is automatically deleted by the runner

Session Keys

Every session is identified by a hierarchical key that encodes the agent, channel, scope, and peer.

Key Format

The scope portion varies based on the DM scope setting:

Group and Thread Keys

Groups and threads are always fully isolated regardless of DM scope:

Special Session Keys

Certain features create their own isolated sessions:

Listing Sessions

The list shows session name, agent, token usage, last activity, type (permanent/ephemeral), expiration date, and display name.

Session Details

Shows the full session record: key, display name, agent, model override, thinking level, SDK session ID, token breakdown (input/output/total/context), channel routing, ephemeral status, queue configuration, compaction count, and timestamps.

Reading History

Returns normalized message history (user and assistant messages only, no tool calls). Messages are read from the SDK transcript JSONL file. Silent responses (@@SILENT@@) are excluded.

Inspecting Session Trace

Use sessions trace when you need to understand what happened in a real session end to end. Unlike sessions read, trace includes channel ingress, routing, dispatch decisions, runtime startup, adapter requests, tool activity, assistant messages, response emission, delivery observations, and terminal turn state. SQLite is the canonical source for this inspection path. NATS and daemon logs can help with live or process-level debugging, but they are not required to reconstruct the persisted session trace.
Useful filters:
Payload flags are explicit because prompts and request payloads can contain sensitive operational context:
--show-system-prompt resolves the latest system prompt for the session; it does not require a visible turn row in the selected trace window. User prompt and raw request payloads remain turn/request-scoped. When reading a trace, first check whether the sequence reached adapter.request. If it did, Ravi built the final provider request. If it did not, look earlier in channel, routing, prompt, dispatch, and runtime.start rows. Common incident cues from --explain: SDE incident golden path for “the agent saw my message but did not reply”:
Classify the gap by the last reliable row: For abort or context-loss reports, check session.abort, session.timeout, turn.interrupted, provider_session_id_before, provider_session_id_after, and the system prompt hash. resume=false with an existing provider session id is suspicious unless a reset, delete, fork, provider/model change, or runtime capability explains it. Safe examples should use placeholders such as <name>, <turn_id>, and <source_message_id>. Do not paste real phone numbers, group ids, customer prompts, context keys, tokens, or provider session ids into docs or shared incident notes.

Managing Sessions

Rename

Sets the display name shown in listings.

Model Override

Takes effect on the next session start (after reset or daemon restart).

Thinking Level

Also takes effect on the next session start.

Reset

Clears the conversation history but preserves the session configuration (name, routing, model, etc.). The next message starts a fresh conversation. The active SDK subprocess is aborted first.

Delete

Permanently removes the session. The SDK subprocess is aborted, then the session record is deleted from the database.

Ephemeral Sessions

Make a Session Ephemeral

Supported duration formats: 30m, 5h, 1d.

Extend

The extension is added on top of the current expiration time (or the current time, whichever is later).

Make Permanent

Converts an ephemeral session back to a permanent one, removing the TTL and expiration.

Cross-Session Messaging

Sessions can communicate with each other using five message types. This enables multi-agent coordination and information sharing. For tracked execution with progress, dispatch ravi tasks instead of treating session messaging as backlog management.

Message Types

Send

The most versatile command. Supports three modes:
By default, send is still fire-and-forget. Internally it injects an informational prompt with source attribution. Use -w only when the caller needs to wait for and stream the response. sessions send is not a direct external-message primitive. It prompts a Ravi session; it does not itself publish visible text to WhatsApp, Telegram, Matrix, or another channel. For visible channel delivery, use the session’s normal response path or an explicit channel/media/outbound command. Use -a <agent> to auto-create the session if it does not exist:
Interactive mode supports /reset, /info, and /exit commands.

Inform

Send context information. The agent can silently acknowledge (@@SILENT@@) if the information is not relevant:

Execute

Send a task for the agent to perform. The agent uses tools and completes the work without necessarily responding:

Ask / Answer Workflow

The ask/answer pattern enables structured multi-agent coordination:
The ask command includes instructions for the target agent to:
  • Answer immediately if it already knows
  • Otherwise, ask the question in its chat and relay answers back
  • Keep forwarding related follow-ups (not just the first reply)

Channel Overrides

All messaging commands support channel and target overrides:
These overrides describe the prompt/source context used to resolve or create the session. They should not be treated as “send this literal text to that phone number”.

Source Attribution

All cross-session messages include a [from: <sessionKey>] tag so the receiving agent knows who sent it. For ask/answer, an optional sender parameter provides end-user attribution.

Scope Isolation

Sessions respect REBAC permissions. When scope enforcement is active:
  • sessions list only shows accessible sessions
  • sessions info returns “not found” for inaccessible sessions
  • sessions send/ask/answer cannot target sessions outside the caller’s scope
  • Modify operations (rename, reset, delete, set-model, set-thinking, set-ttl, extend, keep) require modify permission
This prevents agents from enumerating or interfering with sessions they should not access.