What are Sessions?
A session represents a distinct conversation between a user and an agent. Sessions provide:- Independent Context - Each session has its own conversation history
- Isolated State - Configuration and mode changes don’t affect other sessions
- Persistent Identity - Sessions can be saved, loaded, and resumed
- MCP Connections - Each session connects to its own set of MCP servers
Think of sessions like browser tabs - each is independent but part of the same application.
Session Lifecycle
Sessions progress through several states:Creating Sessions
New Sessions
Create a new session withsession/new:
src/acp.ts
The agent returns a unique
sessionId that must be included in all subsequent requests for this session.Session ID Format
src/schema/types.gen.ts
Loading Sessions
Load an existing session to restore conversation history:src/acp.ts
How Loading Works
- Client sends
session/loadrequest with existing session ID - Agent restores session state from storage
- Agent streams conversation history via
session/updatenotifications - Client rebuilds UI state from the streamed messages
- Agent responds when streaming is complete
- Session ready for new prompts
Resuming Sessions (Unstable)
Resume a session without replaying history:src/acp.ts
This is an unstable feature (
unstable_resumeSession) and may change in future versions.Forking Sessions (Unstable)
Create a new session based on an existing one:src/acp.ts
Use Cases for Forking
- Generate Summaries - Fork to create a summary without affecting main conversation
- Try Alternatives - Fork to explore different approaches in parallel
- Experimentation - Test agent behavior without modifying original session
Listing Sessions (Unstable)
Query available sessions:src/acp.ts
Session State Management
Session Modes
Agents can support different operational modes that affect behavior:src/acp.ts
- System prompts - Different instructions for the LLM
- Tool availability - Which tools are accessible
- Permission behavior - Automatic vs. manual approval
Available modes are returned in
NewSessionResponse.availableModes and LoadSessionResponse.availableModes.Session Configuration
Set configuration options for a session:src/acp.ts
Session Model (Unstable)
Select which LLM to use for a session:src/acp.ts
Processing Prompts
Once a session is created, send prompts to the agent:src/acp.ts
Prompt Lifecycle
Receiving Updates
Clients receive real-time updates via notifications:Cancelling Operations
Cancel an ongoing prompt:src/acp.ts
Session Persistence
Agents are responsible for persisting session state:Best Practices
Validate Session IDs
Validate Session IDs
Always validate that session IDs exist and are accessible:
Include Session ID in All Requests
Include Session ID in All Requests
Every session-related operation requires the session ID:
Stream History Efficiently
Stream History Efficiently
When loading sessions, batch updates to avoid overwhelming the client:
Handle Session Cleanup
Handle Session Cleanup
Clean up resources when sessions end:
Session Information
Sessions include metadata for organization:MCP Server Connections
Each session can connect to MCP servers for additional tools:MCP servers are connected at session creation/load and provide tools and resources to the agent.
Learn More
Protocol Overview
Understanding the ACP specification
Connections
Establishing agent-client connections
Session Setup
Full specification for session operations
Prompt Turn
How prompts are processed in sessions