agents-persistence
Database-backed persistence implementations for the Rust Deep Agents SDK.
This crate provides production-ready checkpointer implementations for various storage backends, allowing users to choose the persistence layer that best fits their infrastructure.
Available Backends
Backend | Feature Flag | Best For |
---|---|---|
Redis | redis |
High-performance, distributed systems, caching |
PostgreSQL | postgres |
ACID guarantees, relational data, analytics |
DynamoDB | (in agents-aws crate) |
AWS serverless, auto-scaling, global tables |
Installation
Add to your Cargo.toml
:
# Choose the backend(s) you need
[]
= { = "0.0.1", = ["redis"] }
# or
= { = "0.0.1", = ["postgres"] }
# or
= { = "0.0.1", = ["dynamodb"] }
# Enable multiple backends
= { = "0.0.1", = ["redis", "postgres"] }
Quick Start
Redis Checkpointer
use ;
use Arc;
use Duration;
async
PostgreSQL Checkpointer
use ;
use Arc;
async
DynamoDB Checkpointer (AWS)
use ;
use Arc;
use Duration;
async
Setup Instructions
Redis
Using Docker:
Production Setup:
- Use Redis Cluster for high availability
- Enable AOF persistence for durability
- Configure maxmemory-policy for eviction
PostgreSQL
Using Docker:
Table Creation: The checkpointer automatically creates the required table:
TEXT PRIMARY KEY,
state JSONB NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW ,
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW
);
(
thread_id
DynamoDB
Using AWS CLI:
Enable TTL (optional):
Feature Comparison
Feature | Redis | PostgreSQL | DynamoDB |
---|---|---|---|
Performance | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐⭐ |
Durability | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
Scalability | ⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
Cost | $ | $$ | $ (pay-per-request) |
Setup Complexity | Low | Medium | Low (managed) |
Query Capabilities | Limited | Full SQL | Limited |
Multi-region | Clustering | Replication | Global Tables |
Best Practices
Redis
- Use connection pooling (built-in)
- Set appropriate TTL for automatic cleanup
- Use namespaces for multi-tenant applications
- Monitor memory usage
- Enable persistence (AOF/RDB) for durability
PostgreSQL
- Use connection pooling (built-in via sqlx)
- Create indexes on
updated_at
for efficient queries - Regular backups and point-in-time recovery
- Monitor connection limits
- Use read replicas for high-read workloads
DynamoDB
- Use on-demand billing for variable workloads
- Enable TTL for automatic cleanup
- Use global tables for multi-region deployments
- Monitor read/write capacity
- Use DynamoDB Streams for event-driven architectures
Error Handling
All checkpointers return anyhow::Result
and provide detailed error messages:
match checkpointer.save_state.await
Testing
Each backend includes integration tests:
# Requires running services
License
MIT OR Apache-2.0