Most AI agent setups share a quiet dysfunction: the agent starts tasks, gets interrupted, and never picks back up. You ask it to research something and write a report — it researches, context runs out, and the report never comes. You ask it to monitor something overnight — it forgets what it was doing by morning.
This guide covers the patterns that separate agents that complete work from agents that just start it.
Why Agents Abandon Tasks
Before fixing the problem, understand why it happens:
1. Context windows reset. Every new session starts fresh. Without explicit memory, the agent has no idea what it was doing.
2. No task ownership. If the agent isn't tracking "I have an active task," it treats every invocation as a new request. Heartbeats, cron jobs, and new messages all look like fresh starts.
3. Interruption ≠ cancellation. Agents treat being interrupted as "task is done" because there's no mechanism to distinguish "I was cut off" from "I finished."
4. Vague completion criteria. If the agent doesn't know what "done" looks like, it can't reliably get there.
The Core Pattern: Task State Files
The most reliable fix is embarrassingly simple: write a file.
Before starting any multi-step task, the agent writes a state file:
{
"task_id": "research-report-001",
"description": "Research and write a report on LangChain alternatives",
"status": "in_progress",
"started_at": "2025-11-10T14:30:00Z",
"steps": [
{ "step": "research_phase", "status": "complete" },
{ "step": "outline", "status": "complete" },
{ "step": "write_draft", "status": "in_progress" },
{ "step": "review_and_finalize", "status": "pending" }
],
"current_step": "write_draft",
"next_action": "Write sections 3-5 of the report draft",
"artifacts": ["research-notes.md", "outline.md"],
"output_file": "report-draft.md"
}At the start of every session, the agent checks this file first. If status is in_progress, it resumes — no questions asked.
Why This Works
- Survives context resets. The file persists across sessions; memory doesn't.
- Explicit current step. The agent doesn't have to infer where it is — the file says exactly what to do next.
- Artifact tracking. The agent knows what it has already produced, so it doesn't redo finished work.
- Clear completion. When all steps are
complete, status becomesdone.
Session Start Protocol
Build this check into every agent loop:
1. Check state/current-task.json 2. If status = "in_progress" → RESUME before anything else 3. If status = "done" or file doesn't exist → pick new work
This single rule eliminates most task abandonment. The key insight: a new cron cycle is not permission to abandon work in progress. It's just another session. The task continues.
Granular Step Tracking
For long tasks, track progress at the step level — not just "started" vs "done."
Bad tracking:
{ "status": "in_progress" }Good tracking:
{
"status": "in_progress",
"completed_steps": ["research", "outline"],
"current_step": "section_3_of_5",
"next_action": "Write the 'Comparison' section using the research notes"
}The difference: with granular tracking, an interrupted agent resumes exactly where it left off instead of starting the current step over. For a 2-hour research task, this matters enormously.
The 70% Context Rule
Agents don't always get interrupted by external events. Sometimes they hit their context limit.
Build in a checkpoint trigger: when the agent estimates it's approaching context limits (70-80% through a long task), it should:
- Write current progress to the state file
- Note the exact
next_action - Save any in-progress artifacts
- End the session cleanly
This turns what would be a chaotic truncation into a clean handoff to the next session. The agent picks up at next_action rather than trying to reconstruct where it was.
Completion Criteria: Define Done Explicitly
Agents drift toward "good enough" rather than "done" unless you define the endpoint clearly.
In your task state, include a done_when field:
{
"done_when": "report.md exists, is at least 1500 words, covers all 5 sections from outline.md, and has been committed to GitHub"
}Before marking a task complete, the agent checks each condition. This prevents the common pattern of an agent declaring success while half the deliverables are still missing.
Handling Long Tasks Across Multiple Sessions
Some tasks genuinely take multiple hours or days — deep research, content series, multi-step builds. Structure these as projects, not tasks:
state/
current-task.json ← current active step
projects/
research-report/
project.json ← overall goal and phases
phase-1-notes.md ← accumulated artifacts
outline.md
draft.mdThe project file tracks the macro picture; the task file tracks today's work. Each session:
- Reads project.json to understand the overall goal
- Reads current-task.json to find today's specific step
- Works, updates both files as it progresses
- Marks the day's task done; notes the next phase in project.json
Anti-Patterns to Avoid
❌ Mental notes. "I'll remember where I was" — the agent won't. Write it down.
❌ Assuming the task is done because the context ended. A truncated output is not a completed task. If the artifact doesn't exist, the task isn't done.
❌ Restarting instead of resuming. If state says in_progress, continue it. Starting fresh wastes prior work and often produces inconsistent output.
❌ Ambiguous next steps. "Continue the report" is not a useful next_action. "Write the Introduction and Methodology sections (sections 1-2 of 5)" is.
❌ No artifact tracking. If the agent doesn't know what files it's produced, it may regenerate them — or worse, skip them because it vaguely "thinks" they exist.
Quick Implementation Checklist
Before deploying any agent on multi-step work:
- [ ] State file location defined (
state/current-task.json) - [ ] Session start checks for in-progress task before doing anything else
- [ ] Steps defined with clear
statustracking - [ ]
next_actionfield is always specific and actionable - [ ]
done_whencriteria explicitly listed - [ ] 70% context checkpoint rule included in agent instructions
- [ ] Artifacts directory tracked in state
The Bigger Principle
An agent that finishes things reliably is more valuable than an agent that does 50 things halfway. The patterns above aren't complicated — they're just about being explicit where the default behavior is implicit.
Write state. Check state. Finish what you start.
Want the full playbook?
Get copy-paste AI templates, prompt frameworks, and agent patterns — all in one place.
Get Access — It’s FreeNo credit card. No fluff. Just the good stuff.