Sessions & Remote Agents
The session system provides stateful conversation management and remote agent connectivity, enabling persistent interactions and distributed agent deployments.Overview
Sessions provide two powerful capabilities:- Stateful Local Sessions: Maintain conversation state, memory, and knowledge across interactions
- Remote Agent Connectivity: Connect to agents running on other machines or cloud services
Local Sessions
Basic Usage
Memory Integration
Sessions can maintain memory across conversations:Knowledge Integration
Attach knowledge bases to sessions:Remote Agents
Connecting to Remote Agents
Remote agents follow the Google ADK (Agent Development Kit) pattern for standardised communication.
Remote Agent Server
Create an agent server for remote access:Session Configuration
Local Session Options
Remote Session Options
State Management
Saving Session State
Restoring Session State
State Persistence Location
By default, session state is saved to:.sessions/{session_id}/state.json
- Session metadata.sessions/{session_id}/memory/
- Memory databases.sessions/{session_id}/knowledge/
- Knowledge databases
Advanced Features
Session Context
Access session context programmatically:Multi-Agent Sessions
Use multiple agents within a session:Session Middleware
Add custom middleware to sessions:Use Cases
Customer Support
Maintain conversation history across support interactions
Personal Assistants
Remember user preferences and past interactions
Collaborative Work
Share context between team members
Distributed Systems
Deploy agents across multiple servers
Complete Example
Best Practices
Session Management
- Use meaningful session IDs
- Clean up old sessions periodically
- Implement session expiry policies
State Handling
- Save state after important interactions
- Implement regular auto-save
- Handle restore failures gracefully
Remote Connections
- Implement proper error handling
- Use timeouts for remote calls
- Add retry logic for failures
Security
- Validate session IDs
- Implement authentication for remote agents
- Encrypt sensitive session data