Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sessions

Sessions are the core durability primitive in Duragent. A session is a persistent conversation context that survives crashes, restarts, and disconnects.

Why Sessions Matter

Without SessionsWith Sessions
Crash = context lostCrash = reconnect and continue
One client onlyAccess from CLI, HTTP, Telegram, web
Tied to terminalPortable across devices
No history APIQuery conversation history programmatically

Session States

StateDescription
activeRunning, client connected
runningRunning, client disconnected (continue mode)
pausedWaiting for reconnect (pause mode)
completedCompleted or explicitly ended

Disconnect Behavior

When a client disconnects, the agent’s behavior is configurable per-agent:

ModeBehaviorUse Case
continueAgent keeps executing, buffers outputAsync workflows, fire-and-forget tasks
pauseAgent pauses, waits for reconnectInteractive chat
# agent.yaml
spec:
  session:
    on_disconnect: pause  # or: continue

Multi-Gateway Access

Sessions are accessible from any gateway — the same session can be started from CLI, continued via Telegram, and queried via HTTP API.

Storage

Each session is stored as files:

.duragent/sessions/{session_id}/
├── events.jsonl     # Append-only event log
└── state.yaml       # Snapshot for fast resume
  • events.jsonl — Every message, tool call, and status change is appended here
  • state.yaml — Periodic snapshot for fast resume (no need to replay all events)

Session Lifecycle

TTL and Expiry

Sessions can be configured to expire after a period of inactivity:

# duragent.yaml
sessions:
  ttl_hours: 168    # 7 days (default). 0 disables auto-expiry.

Per-agent TTL overrides are also supported in agent.yaml.

Event Log Compaction

To prevent unbounded growth, Duragent compacts the event log after each snapshot:

# duragent.yaml
sessions:
  compaction: discard   # discard (default) | archive | disabled
ModeBehavior
discardRemove events covered by the snapshot
archiveMove old events to events.archive.jsonl before removing
disabledNo compaction (events grow unbounded)

Gateway Commands

In gateway chats (Telegram, Discord), you can use slash commands:

CommandBehavior
/resetEnd current session; next message starts fresh
/statusShow current session info