AI Hints
Home›Agentic AI Tutorial›Agents at Work
Agentic AI · Lesson 81 of 100

Long-Running Tasks

Surviving across sessions.

⏱ 2 min read▶ Video at 2:23:47🎓 Free
Watch this lesson in the Agentic AI courseWatch on YouTube ↗Full Agentic AI course

Some jobs take longer than one session. Migrating a code base. Reviewing a thousand contracts. No context window can hold all of that. So how do people do long projects? They write things down, and come back to them tomorrow. Agents need to do the same.

Long-Running Tasks
From the video: Long-Running Tasks
  • Some jobs take many hours
  • No context can hold it all
  • Write things down

A plan on disk

We keep the plan in a file, rather than in the model's memory. Each worker reads the file, does a little, marks items as finished, and saves it. Here, one worker does two tasks, and stops. Then a brand new one starts, knowing nothing. Run it. The second process picks up from exactly where the first one finished. It didn't need any memory of its own, because the state lives on disk. That's how long running coding agents work. They keep to do lists and progress notes in files, and each fresh session reads them first.

resume.pypython
import json, pathlib

PLAN = pathlib.Path("plan.json")

def load():
    if PLAN.exists():
        return json.loads(PLAN.read_text())
    return [{"task": t, "done": False} for t in ["Read the order", "Check the policy", "Draft the reply"]]

def work(limit):
    items = load()
    for item in items:
        if not item["done"] and limit > 0:
            item["done"], limit = True, limit - 1
            print("Done:", item["task"])
    PLAN.write_text(json.dumps(items))

work(limit=2)
print("--- the process stops, then a new one starts ---")
work(limit=2)
print("Remaining:", [i["task"] for i in load() if not i["done"]])
Output
Done: Read the order
Done: Check the policy
--- the process stops, then a new one starts ---
Done: Draft the reply
Remaining: []

Working over many sessions

For long jobs, keep a progress file, and update it as you go. Use git, so that each step is saved and can be undone. Do one small piece at a time, and test it before moving on. Leave clear notes for the next session, as if for a new colleague. Teams who've studied this say that small steps, and good notes, matter far more than a clever model.

Progress filewhat's done, what's next
Gitsave and undo
Small stepstest each one
Notes for tomorrowlike a new colleague

Summary

State on disk beats state in memory. Next, what to do when a session fills up.

Key takeaways
  • Keep plans in files
  • Fresh workers read the plan
  • Small tested steps
Next up: Automatic Compaction — never running out of context