Overview
Handler’s session management system persists conversation state across CLI invocations and TUI sessions. Sessions store:- context_id: Conversation context for continuity
- task_id: Current or most recent task
- credentials: Authentication tokens (bearer, API key)
~/.handler/sessions.json and automatically loaded when interacting with known agents.
Session Storage Location
Sessions are stored in your home directory:session.py:17-18
Session Data Structure
Each agent URL maps to a session:Example Session File
sessions.json
Automatic Session Management
Handler automatically saves session state after each interaction:mcp/server.py:203-204
Using Sessions with the CLI
- Automatic Use
- Override Context
Sessions are automatically loaded and used:The CLI loads sessions on startup:
session.py:200-207
Managing Sessions
Session Persistence
Sessions are loaded on demand and saved after modifications:Context Continuity
Context IDs enable multi-turn conversations with agents:app.py:162-163
app.py:218-224
Using Sessions with MCP
The MCP server provides tools for session management:- list_sessions
- get_session_info
- clear_session_data
Credentials in Sessions
Sessions can store authentication credentials for automatic reuse:Session File Permissions
Protect your session file:.gitignore if working in a repo:
.gitignore
Troubleshooting
Session not loading
Session not loading
Check if the session file exists and is valid JSON:If corrupt, backup and recreate:
Context not persisting
Context not persisting
Verify session is being saved:Check for write permissions:
Credentials not working
Credentials not working
List sessions to verify credentials are saved:Check the session file:
Best Practices
One Session Per Agent
Each agent URL gets its own session. Use different URLs (ports, paths) for different agent instances.
Clear Stale Sessions
Periodically clear old sessions:
Explicit Context
For critical workflows, pass
--context-id explicitly rather than relying on session state.Backup Sessions
Before major changes: