How to Manage Sessions
Sessions hold per-conversation agent state: message history, model settings, and reset policy. Each session runs as a Durable Object with persistent storage.
List sessions
gsv session listShows the most recent sessions sorted by last activity. Limit the count:
gsv session list --limit 10Inspect a session
Get session info (settings, status, message count):
gsv session get agent:main:cli:dm:mainPreview the message history:
gsv session preview agent:main:cli:dm:main
gsv session preview agent:main:cli:dm:main --limit 5View token usage statistics:
gsv session stats agent:main:cli:dm:mainView previous session IDs (from past resets):
gsv session history agent:main:cli:dm:mainReset a session
Resetting archives the current conversation to R2 and clears the message history. The agent starts fresh on the next message.
gsv session reset agent:main:cli:dm:mainThe default session key is agent:main:cli:dm:main, so for the main CLI session you can simply:
gsv session resetCompact a session
Compaction trims the conversation to the most recent messages without a full reset. Use this when the context is getting long but you don't want to lose continuity:
gsv session compact agent:main:cli:dm:main --keep 20Automatic compaction also runs when the conversation approaches the model's context window limit. Configure it via:
gsv config set compaction.enabled true
gsv config set compaction.reserveTokens 20000
gsv config set compaction.keepRecentTokens 20000When extractMemories is enabled, compaction writes durable observations to the daily memory file before trimming.
Configure auto-reset policies
Auto-reset policies control when sessions automatically clear themselves. Set the default for all new sessions:
gsv config set session.defaultResetPolicy.mode "daily"
gsv config set session.defaultResetPolicy.atHour 4Available modes:
| Mode | Behavior |
|---|---|
manual | Only reset when explicitly requested |
daily | Reset if the last message was before atHour (0-23, default 4) |
idle | Reset after idleMinutes of inactivity (default 60) |
Override the policy on a specific session:
gsv session set agent:main:cli:dm:main resetPolicy.mode "idle"
gsv session set agent:main:cli:dm:main resetPolicy.idleMinutes 30Override session model settings
Change the model for a specific session without affecting the global config:
gsv session set agent:main:cli:dm:main model.provider openai
gsv session set agent:main:cli:dm:main model.id gpt-4.1Understanding session keys
Session keys follow the pattern: agent:{agentId}:{channel}:{accountId}:dm:{peerId}
For the CLI, the default is agent:main:cli:dm:main.
The dmScope config setting controls how much of this key varies across conversations:
main(default) -- all DMs collapse intoagent:{agentId}:cli:dm:mainper-peer-- each peer getsagent:{agentId}:cli:dm:{peerId}per-channel-peer-- per channel per peerper-account-channel-peer-- fully isolated
Change the scope:
gsv config set session.dmScope "per-peer"When using per-peer or more specific scoping, each distinct conversation partner gets their own session with independent history and reset policy.
What happens during a reset
- The current message history is serialized and archived as a gzipped JSONL file in R2 at
agents/{agentId}/sessions/{sessionId}.jsonl.gz - The session's message list is cleared
- A new session ID is generated
- On the next inbound message, the agent workspace is reloaded and a fresh conversation begins
The archived session can be retrieved later via the R2 mount or direct R2 access.