Scheduling
Scheduling is a technique for triggering Letta agents at regular intervals. Many real-world applications require proactive behavior, such as checking emails every few hours or scraping news sites. Scheduling can support autonomous agents with the capability to manage ongoing processes.
Native scheduling functionality is on the Letta Cloud roadmap. The approaches described in this guide are temporary solutions that work with both self-hosted and cloud deployments.
Common Use Cases
When building autonomous agents with Letta, you often need to trigger them at regular intervals for tasks like:
- System Monitoring: Health checks that adapt based on historical patterns
- Data Processing: Intelligent ETL processes that handle edge cases contextually
- Memory Maintenance: Agents that optimize their own knowledge base over time
- Proactive Notifications: Context-aware alerts that consider user preferences and timing
- Continuous Learning: Agents that regularly ingest new information and update their understanding
This guide covers simple approaches to implement scheduled agent interactions.
Option 1: Simple Loop
The most straightforward approach for development and testing:
Pros: Simple, easy to debug
Cons: Blocks terminal, stops if process dies
Option 2: System Cron Jobs
For production deployments, use cron for reliability:
Add to crontab with crontab -e
:
Pros: System-managed, survives reboots
Cons: Requires cron access
Best Practices
- Error Handling: Always wrap API calls in try-catch blocks
- Logging: Log both successes and failures for debugging
- Environment Variables: Store credentials securely
- Rate Limiting: Respect API limits and add backoff for failures
Example: Memory Maintenance Bot
Complete example that performs periodic memory cleanup:
Choose the scheduling method that best fits your deployment environment. For production systems, cron offers the best reliability, while simple loops are perfect for development and testing.