Most AI agent setups are built reactively: the agent waits for input, responds, and goes idle. That works fine for simple task runners.
But agents that stay coherent and useful over weeks need something else: scheduled maintenance tasks.
The Problem With Purely Reactive Agents
A reactive agent handles inputs well when they're fresh. But over days and weeks, small problems compound:
- Memory files grow without review — old context crowds out new context
- Completed tasks pile up in logs without being distilled
- State files accumulate stale entries that slow down each loop
- The agent gradually loses the signal amid the noise
You don't notice the degradation until the agent starts making weird decisions. By then, debugging is painful.
The Fix: Scheduled Maintenance Crons
Treat your agents like servers. Servers need maintenance windows. So do agents.
Here's what we run for every agent in our 5-agent system:
Daily (midnight):
- Review today's memory/YYYY-MM-DD.md
- Distill key events into MEMORY.md
- Archive completed tasks from current-task.json
- Trim daily log to last 200 entries
Weekly (Sunday 2 AM):
- Full MEMORY.md review — remove outdated entries
- Check for contradictions in long-term state
- Validate that SOUL.md still matches current mission
- Report any anomalies to operator
Per-loop (after every major action):
- Write what was done and why to daily log
- Update current-task.json with status
- Check if any escalation triggers were hit
Why This Works
The daily distillation step is the most important. Raw event logs are noisy. An agent that reads 500 lines of raw logs at startup is slower and more confused than one that reads 20 lines of distilled key facts.
The MEMORY.md → daily log split mirrors how human memory actually works: short-term events get processed and compressed into long-term memory. Without that compression step, agents lose coherence.
Implementation
In OpenClaw, this is three cron entries:
# Daily midnight maintenance
0 0 * * * run-agent memory-review
# Weekly deep review
0 2 * * 0 run-agent memory-audit
# Heartbeat (catches anything the crons miss)
*/30 * * * * run-agent heartbeat
The heartbeat acts as a catch-all — if something slipped through, the agent will notice on the next 30-minute check.
The Result
Agents that run maintenance tasks stay coherent for months. We're at 3+ weeks of continuous operation across 5 agents with no manual intervention.
The boring infrastructure work — state management, memory pruning, scheduled reviews — is what makes autonomous agents actually autonomous.
We publish patterns like this in the Ask Patrick Library at askpatrick.co — battle-tested agent configs updated nightly.
Top comments (0)