Long-running agents that stay on course
How to use Stateful to keep a multi-day agent on track without micromanaging it.
A long-running agent — a migration, a refactor, a research sweep — drifts across sessions. It forgets the constraints you set on day one, re-proposes approaches you already rejected, and loses track of what's done versus in-progress.
This tutorial shows how to back an agent run with Stateful so it resumes where it left off, without drift.
What you'll need
- Stateful connected to GitHub (or GitLab), and the Local Codebase source if you want the agent to see your files
- MCP wired to your AI (Claude.ai, Cursor, or Claude Code)
- The task your agent will work on
Step 1: Capture your constraints before you start
Tell the assistant the hard rules for this project, one at a time:
"For the migration project: never modify files in
services/node/src/app/core/directly — those changes go through PR review. Always runpnpm testbefore marking a task complete. Prefer small, atomic commits."
Each one is captured as a typed constraint and added to your profile. From then on they're surfaced to the agent via get_context every time it starts a new session. You set them once; the agent follows them across every restart.
Step 2: Write the project brief
In your wiki, type [[ and create a new page for this run as a Project — something like "Migration: Node → Python services." Fill it in with:
- Goal — one sentence
- Scope — what's in, what's out
- Decisions made — choices already locked in
- Progress — what's done, what's next
The agent can read this page with read_subject and propose updates with propose_subject_edit (which land in your inbox for approval).
Step 3: Start the agent with a grounded prompt
Your first prompt should make the agent read its context before doing anything:
Step 4: End each session with an update
Before you close a session, have the agent update its own brief:
The proposed edit lands in your inbox. Approve it, and the next session starts from the updated brief.
Step 5: Spot-check for drift
At the start of each session:
If the answers are right, you're in sync. If something's off, correct it explicitly so your wiki reflects the truth.
Why this works
The agent loses its conversational memory at every reset. What it keeps is access to Stateful. Your wiki becomes the agent's external memory — persistent, structured, and editable by you when it drifts. The constraints you set on day one are still there on day six, surfaced automatically via get_context.