Skip to main content
Sessions in Meerkat are surface-agnostic. The same SessionService trait backs the CLI, REST API, JSON-RPC server, and MCP server. A session created via REST can be resumed via RPC. Sessions can be persisted to JSONL, redb, or a custom backend — swap the store without changing application code.

Lifecycle

OperationWhat it does
create_sessionBuild an agent, run the first turn, return a session ID
start_turnContinue with a new prompt. Fails with SESSION_BUSY if a turn is already running
interruptCancel the in-flight turn
readGet session state (message count, token usage). Non-blocking during a running turn
listList active sessions. In persistent mode, includes stored sessions
archiveRemove from the live map. In persistent mode, the snapshot is kept

Multi-turn example

use meerkat::{AgentFactory, Config, build_ephemeral_service};
use meerkat::service::{CreateSessionRequest, StartTurnRequest, SessionService};

let config = Config::load().await?;
let factory = AgentFactory::new(std::env::current_dir()?);
let service = build_ephemeral_service(factory, config, 64);

let result = service.create_session(CreateSessionRequest {
    model: "claude-sonnet-4-5".into(),
    prompt: "My name is Alice.".into(),
    system_prompt: Some("You are a helpful assistant.".into()),
    max_tokens: None,
    event_tx: None,
    host_mode: false,
}).await?;

let session_id = result.session_id;

let result = service.start_turn(&session_id, StartTurnRequest {
    prompt: "What's my name?".into(),
    event_tx: None,
    host_mode: false,
}).await?;

service.archive(&session_id).await?;

Persistence backends

BackendFeature flagTrade-off
In-memory(default)No disk I/O, lost on process death
JSONLjsonl-storeOne file per session, human-readable, no dependencies
redbsession-storeACID transactions, single database file, crash-safe
All three implement the same AgentSessionStore trait. You can also write your own.

Concurrency guarantees

  • One turn per session at a time, enforced with atomic compare-and-swap
  • No queueing — callers retry on SESSION_BUSY
  • read() and list() never block, even during a running turn
  • interrupt() signals cancellation; the turn returns AgentError::Cancelled
  • Persistent mode saves a snapshot after each turn completes — crash mid-turn loses only that turn
See session contracts for the full specification.