Skip to content

Pattern

How AI agents follow a task for days or weeks

An AI agent can follow a task for days or weeks only if the task lives outside the agent, as a saved record of goal, progress and next step that survives restarts. The agent wakes, reads the record, does one step, writes it back and sleeps, so nothing depends on one long conversation.

StudiedLast reviewed 4 min read

Explained from public sources. Mai has not built this yet.

On this page

In plain English

Most useful work takes longer than one conversation. Chasing an overdue invoice, onboarding a new supplier or getting three quotes for a repair can stretch over days, with long gaps while someone replies. A long-running job keeps a written file on the task: what the goal is, what has been done, and what happens next. The agent opens that file whenever there is something to do, takes one step, updates it and puts it away, which is roughly how a good assistant keeps a folder for each open matter.

How it works

The key move is to separate the job from the agent. A language model forgets everything between calls, and even within one session its working context fills up. So the state of the job lives in a database, not in the model’s head.

A job record usually holds:

  • The goal and its definition of done. “Get the boiler repair booked with a quote under the approved limit” is checkable. “Sort the boiler” is not.
  • A step log. Every completed step, with its result and a timestamp.
  • The next step and when it is due. For example “chase supplier B on Thursday at 9am if no reply”.
  • Waiting conditions. What the job is waiting for: a reply, an approval, a date.

Something has to wake the job. That can be a schedule (see heartbeats and schedules), an incoming event such as a reply landing in the inbox, or a person approving a draft. On each wake-up the agent loads the record, reads the log, decides the single next step, does it, writes the result back and goes quiet again.

Wake: Schedule, Reply arrives, Approval. Then Job record. Then Agent takes one step. Then You approve. Then Act, Save progress.

The job lives in a store; the agent visits it, takes one step and saves

Workflow engines have solved the hard part of this for ordinary software. Temporal, for example, records every step of a workflow in an event history and, after a crash, rebuilds the workflow’s state by replaying that history, so it continues where it stopped and does not re-run work it already recorded. Agent frameworks offer a lighter version: LangGraph saves a checkpoint of the graph’s state per thread, which lets a run pause for a person and pick up later, or recover after a failure, as long as the checkpoints are kept in a persistent database rather than in memory.

Anthropic’s engineering team has written about the same problem for coding agents that work across many sessions. Their approach gives each new session a short routine: read the progress notes and the task list, check the current state of the work, then take on one item and leave things tidy for the next session. The lesson carries over to business jobs: a fresh agent should be able to understand the job from the record alone.

Where it goes wrong

  • Doing a step twice. If the agent sends an email and crashes before saving, a naive retry sends it again. The fix is to give each side effect an idempotency key and record it, so a retry can see it already happened.
  • Declaring victory early. An agent that sees some progress can wrongly decide the whole job is done. Anthropic’s write-up names this as a common failure. A written definition of done, checked by code where possible, guards against it.
  • Trying to do everything in one go. An agent that attempts the whole job in one session can run out of context halfway and leave a mess. One step per wake-up is slower and much safer.
  • Stale context. A job started on Monday may rest on facts that changed by Friday: the supplier has been paid, the client called. Each wake-up should re-read the live systems, not trust the log alone.
  • Jobs that never end. Without a timeout or an escalation rule, a job waiting for a reply can wait forever. Every job needs a “give up and tell a person” point.
  • Losing the record. Keeping state in memory works in a demo and fails at the first redeploy. The LangGraph documentation makes the same point about its in-memory saver.

How Mai AI uses it

In a Mai AI system, anything that takes longer than a single exchange becomes a job with its own record: the goal, a step log, the next step and the date it falls due. I design jobs so that each wake-up does one step and saves before acting again, every outward action carries a key so it cannot be sent twice, and every job has a deadline after which it hands back to a named person instead of carrying on.

Jobs pause cleanly for approval. When a step needs sign-off, the job waits in a “pending approval” state and resumes only when someone approves it, which is the same rule the human approval gates entry describes. In the AI chief of staff I built for a UK property group, anything that matters needs a signed approval token and the trail goes to an audit log; a long-running job follows the same rules, so a week-long task leaves a complete history you can read in the traces and audit logs.

Long-running jobs are one of the parts that move a system from a chat window to something that genuinely carries work. If you want one designed around your own processes, start with the custom AI operations systems page.

Questions and answers

Can an AI agent work on a task for several days?

Yes, if the task is stored as a durable record rather than held in one conversation. The agent picks the record up on each wake-up, does the next step and saves its progress, so restarts, deployments and long waits do not lose the thread.

What happens to a long-running agent job if the server restarts?

In a well-built system, nothing is lost. Progress is saved after every step, so the job resumes from the last completed step rather than starting again, and steps that already sent an email or updated a record are not repeated.

How do you stop a long-running AI agent from repeating actions?

Record every completed side effect, such as a sent email, with a unique key before moving on, and check that record before acting. On a retry the agent sees the step is done and skips it.

What is durable execution for AI agents?

Durable execution means a workflow's progress is recorded step by step so it can resume exactly where it stopped after a crash or a long pause. Workflow engines such as Temporal and agent frameworks with checkpointing, such as LangGraph, provide it.

Sources

  1. Anthropic engineering, Effective harnesses for long-running agentsanthropic.com
  2. Temporal documentation, Workflowsdocs.temporal.io
  3. LangGraph documentation, Persistencedocs.langchain.com