Persistence ensures your agent workflows maintain continuity by preserving conversation history, computational state, and environmental configurations across requests and sessions.
Overview
The Persistence primitive is a foundational capability that enables agents to maintain state across multiple interactions. Unlike stateless systems that forget everything between requests, Agentbase’s persistence model allows agents to build on previous work, remember context, and preserve computational environments. Persistence operates at two distinct tiers:- Chat & Message History: Automatic, zero-cost persistence of all conversation messages
- Computational Environment: On-demand persistence of files, packages, and system state
Zero-Cost Chat History
All messages persist automatically with no storage fees or configuration required
Smart Environment Management
Computational resources auto-pause when idle and resume instantly when needed
Session-Based Architecture
Isolated persistence scopes per session for security and multi-tenancy
Long-Term Continuity
Maintain workflows over hours, days, or weeks with automatic state preservation
How Persistence Works
Two-Tier Model
Agentbase implements a sophisticated two-tier persistence model optimized for both cost and performance: Tier 1: Message History (Always Active)- Automatically persists all messages and responses
- Zero storage cost
- Instantly available for context
- No configuration required
- Unlimited retention
- Created when agents need code execution, file operations, or web browsing
- Persists files, installed packages, and system state
- Auto-pauses after 5 minutes of inactivity
- Resumes in 1-2 seconds when accessed again
- Full environment preservation across sessions
Cost Optimization: Message history is completely free. Computational environments are only created when needed and automatically pause to minimize costs.
Session-Scoped Persistence
Each session maintains its own isolated persistence scope:- Session Creation: New session starts with empty state
- State Accumulation: Messages, files, and environment changes persist within session
- Cross-Request Continuity: State remains available across all requests in the session
- Automatic Cleanup: Sessions eventually expire after extended inactivity
- Isolation: Complete separation between different sessions
Code Examples
Basic Persistence Pattern
Long-Running Project Persistence
Multi-Step Workflow with Persistence
What Persists
Message History
Everything in the conversation persists automatically:- User Messages: All requests sent to the agent
- Agent Responses: Complete responses including reasoning
- Tool Calls: Record of all tools used and their inputs
- Tool Results: Outputs from tool executions
- Timestamps: When each interaction occurred
- Metadata: Session information, modes used, cost tracking
Computational Environment
When a computational environment is created, these persist:- Files: All files created, modified, or downloaded
- Installed Packages: npm, pip, apt packages remain installed
- Environment Variables: Custom environment configurations
- Working Directory: Current directory state and structure
- Process State: Background processes and their status
- System Modifications: Configuration changes and system state
What Doesn’t Persist
Some ephemeral state is intentionally not persisted:- Memory State: RAM contents are cleared on pause
- Network Connections: Active connections are closed
- Temporary Files: /tmp contents may be cleaned up
- Running Processes: Processes terminate on pause (but can be restarted)
Use Cases
1. Iterative Development Projects
Build software projects across multiple sessions:Web Application Development
Web Application Development
Data Science Pipeline
Data Science Pipeline
2. Customer Support Conversations
Maintain context throughout support interactions:3. Research and Analysis
Accumulate research over extended periods:4. Scheduled Jobs and Automation
Maintain state across scheduled executions:Best Practices
Session Management
Store Session IDs Securely
Store Session IDs Securely
Track Session Activity
Track Session Activity
Use Descriptive Session Metadata
Use Descriptive Session Metadata
Performance Optimization
Keep Active Sessions Warm
Make requests within 5 minutes to avoid auto-pause overhead
Separate Independent Workflows
Use different sessions for unrelated work to keep context focused
Clean Up Large Files
Remove unnecessary files to reduce storage and improve performance
Periodic Checkpoints
Save important state externally for critical long-running workflows
Data Management
Integration with Other Primitives
With Sessions
Persistence is session-scoped - each session maintains its own state:With States
States represent the current snapshot of persisted data:With Versioning
Combine persistence with versioning for rollback capabilities:Performance Considerations
Environment Startup Times
- New Environment: 2-5 seconds to create from scratch
- Warm Environment: Instant access if active (< 5 min since last request)
- Resume from Pause: 1-2 seconds to wake up paused environment
Storage Impact
Message history is free and unlimited. For computational environments:- Small Projects (< 100 MB): Negligible impact
- Medium Projects (100 MB - 1 GB): Normal performance
- Large Projects (> 1 GB): Consider periodic cleanup
Optimization Strategies
Troubleshooting
Files Not Persisting
Files Not Persisting
Problem: Files created in one request don’t appear in the nextSolutions:
- Verify you’re passing the same session ID
- Check that files are created in persistent directories (not /tmp)
- Ensure session hasn’t expired
Session Not Found Error
Session Not Found Error
Problem: Error when trying to use a session IDSolutions:
- Session may have expired after extended inactivity
- Session ID may be incorrect or corrupted
- Start a new session and restore state if needed
Slow Environment Resume
Slow Environment Resume
Problem: Noticeable delay when resuming paused environmentSolutions:
- This is expected behavior (1-2 second resume time)
- Keep environment warm with periodic requests if low latency is critical
- Consider if you really need environment persistence for simple tasks
Related Primitives
Sessions
Session containers that enable persistence
States
Current snapshot of persisted data
Versioning
Version control for persisted state
Background Tasks
Long-running tasks with persistence
Additional Resources
API Reference
Session and persistence parameters
Agent Computer
Environment capabilities and tools
Use Cases
Real-world persistence patterns