---
title: How to Structure Context for Long-Running AI Agents
url: "https://goremy.ai/blog/articles/long-running-ai-agents-context-repo-structure"
author: Luis Chavez-Mattos
editor: Luis Chavez-Mattos
editor_title: Director, Product
published: "2026-11-23T09:40:24.995Z"
updated: "2026-11-23T09:40:24.995Z"
topic: AI Agents & Automation
description: Long AI agent runs go wrong when you repeat yourself. Organize context, decisions and skills like a shared repo so agents stop needing corrections.
---

# How to Structure Context for Long-Running AI Agents

> Long AI agent runs go wrong when you repeat yourself. Organize context, decisions and skills like a shared repo so agents stop needing corrections.

Edited by Luis Chavez-Mattos, Director, Product · Published 2026-11-23

## How do you structure context so long agent runs don't need repeated corrections?

Treat your project knowledge like code in a shared repository (a central folder of files that every agent and every person works from). Put instructions, examples, checks for known mistakes, and a running record of decisions in that one place, in plain files an agent can read. Give each piece of work its own folder, spell out what each role may change, and update the record whenever you change your mind. The agent then starts every run with your current thinking instead of your first draft.

## TL;DR

- Long runs fail less because the AI is weak and more because **the assignment and its context were never written down** in a form the next agent can read.
- Keep **decisions, examples, instructions and error checks** in one central folder, even if your work has nothing to do with code.
- Write **skills for the team's problem**, not for your personal setup, so anyone using any AI tool gets consistent results.
- Define **what each role's agent is allowed to change**, even if it is only a plain text file, and add real permissions where you can.
- Give each piece of work **its own folder or page** so agents and people stop overwriting each other.
- Judge success by whether you **stop repeating yourself** and catch mistakes before a customer does, and by whether a human still owns the result.

## Why do long AI agent runs keep going wrong?

Labs have reported very long runs. OpenAI described AI sessions running for hundreds of hours finding and fixing problems in a code-management system. Anthropic reported more than 1,000 agents working for 8 days to build a prototype operating system. Most of us are nowhere near that, and a common reason is simple: we explain the same thing over and over.

Here is a concrete case. One person used Codex to research a topic. It found over 339 sources and wrote more than a thousand questions to think through. They told it to keep going. Later, an agent got stuck repeating work while trying to synchronize all the files. By then, what the person wanted had changed: the 50 most valuable answers, with stronger evidence, not a thousand questions.

The research was there. The data was not the problem. The assignment had not caught up with what the person had learned during the run. The distinction between a discovery phase and a refinement phase lived in their head, not in a file the next agent could read.

You pay twice for this. First in tokens (the units AI services bill by) for a run that went the wrong way. Then in your own time, fixing a result that was never what you wanted.

## What does it mean to treat project knowledge like code?

It means storing your project information the way a software team stores code: in a central repository, organized in folders, with every change recorded. Agents can find it, read it, and follow it.

This works even when the work is not software. Say you agreed on an offer and a price with a client. A contractor's AI picks up an older proposal as its example. The new draft reads well, but it has the wrong price in it. That is a versioning error, and it creeps in whenever non-technical information is not managed with some discipline.

There is also a practical reason this suits AI. Current models are trained heavily on code, which is a domain where results can be checked. A pile of files an agent can traverse, with clear names and structure, is a format it handles well. It also helps people. New employees at AI labs are reportedly encouraged to ask Codex or Claude questions about existing project material, so they learn from how the context evolved. Agents benefit from the same trail.

## What should go in the shared folder?

Not just facts. The things that change as you work matter most: decisions, examples you developed with the AI, and instructions you revised.

| What to store | What it prevents | Example |
|---|---|---|
| Goal and phase | An agent doing discovery when you want refinement | "We are in refinement. Reduce to the 50 most valuable questions." |
| Decision records | Agents following choices you have reversed | "Price is fixed at the amount in the signed offer. Ignore older proposals." |
| Examples | Agents copying outdated samples | One approved proposal marked as the current model |
| Skills (written instructions for a task) | Every person inventing their own method | How we write a PRD, a proposal, a deck |
| Error checks | Repeated mistakes | "Check any price against the latest decision record before sending." |
| Role rules | Overwrites and scope creep | What the PM's agent, the engineer's agent and a contractor's agent may edit |

### A decision record template

Copy this into a file such as `decisions/2025-001-pricing.md` and adjust it.

```
# Decision: [short title]
Date:
Status: Current / Replaced by [file]
What we decided:
Why:
What this replaces:
What agents must do differently:
What agents must NOT do:
```

The "Replaced by" status line matters. An agent that finds two conflicting decisions needs to know which one is live.

## Why should skills live in the repo instead of on each person's machine?

Skills are often described as personal superpowers for your own AI. The stronger approach is to write them as instructions for any AI, used by anyone, against the work stored right next to them.

If every person writes their own version of "how we prepare proposals," you end up with a set of home-brewed AIs. Each takes a slightly different approach, and often they don't refer to the same data. Undoing that later is painful. Putting the skills in the shared knowledge base means nobody has to depend on each person installing the same correct skill.

This also changes how you write them. Start from the problem the team solves: your way of writing PRDs, preparing proposals, building decks, applying brand guidelines. Then make sure anyone with any AI tool can run them.

Once skills live in the repo, you can build in some helpful behavior. A skill can tell an agent to alert a person: "Version 12 just landed. Do an edit pass before we go further." That assumes several agents and several people working together, and it is hard to get from a purely individual setup.

The goal is not a mini-me for each person. It is a shared setup that produces consistent work, which leaves a person free to be accountable for the final deliverable. "The AI wrote that" is not an answer to a client. You own what goes out.

## How do you set roles and permissions for agents?

Say in the repo what each role's agent does. A PM's agent, an engineer's agent and a contractor's agent should not have the same freedom to change things. Otherwise someone can overwrite your work just because their agent can see the folder.

Be honest about the limits. A text file describing roles is not a security system. Larger organizations are building identity and permission structures that restrict what agents can do, and those are worth having. Many teams can't afford or set those up yet. In the meantime, clear role rules in the repo can get you most of the way (the source's estimate is 80 to 90 percent), with humans overseeing the rest.

A starting point:

1. List the roles that touch the project (PM, engineer, contractor, reviewer).
2. For each, write what their agent can read, what it can edit, and what needs a human sign-off.
3. Mark certain files, such as final pricing or approved decisions, as read-only for most roles.
4. Add real permissions in your tools wherever they are available.

## How do you stop agents and people from overwriting each other?

If many agents swarm over the same material with no structure, you get collisions: edits stepping on each other, the same thing touched twice. Software engineers call these merge conflicts and race conditions. The plain version: several people or agents change one thing at once.

The labs have written up both what goes wrong and what works better. The better approach is separation of concerns. Each piece of work gets its own page, tied to its own folder and topic. This resembles how engineers fork parts of a repo to work on them separately.

For knowledge work, that can be as simple as one page per version or per deliverable. Your skills teach the agent to check whose work is where. If a colleague is already working on the pricing page, your agent writes to its own page instead of editing theirs.

## How do you know it's working?

Use the outcomes the approach is meant to deliver:

- **You stop repeating yourself.** If you explain the same decision twice, it belongs in a file.
- **Mistakes get caught before a customer sees them.** Wrong prices, stale examples and old versions should be flagged internally.
- **A new person can catch up.** Someone joining should be able to read the record and see how your thinking evolved.
- **Different tools reach the same answer.** Colleagues using different AI services should draw from the same data.
- **A human can say "I own this."** Accountability stays with a person.

Watch for what the source calls skill theater: elaborate personal setups that look productive. A simpler setup, with data in one place and shared skills, scales better.

## What does this mean for you?

If you run long AI tasks alone, start small. Create one folder per project with a goal file, a decision log and an examples folder. Update the log whenever you change your mind, before you start the next run.

If you lead a team, pick one shared location for knowledge and skills. Ask people to retire their private versions. Write role rules, and name who reviews outputs.

If you work with contractors or clients, keep the signed-off details (price, scope, offer) in a file marked as current, and mark old proposals as replaced.

## Could you build your own decision log and request tracker?

A shared folder of files works, but a small internal app can make it easier to use: a decision log where each entry has a status, a request form for new work, and sign-in with roles so a contractor sees only what they should. With [Remy](https://goremy.ai), you describe a tool like that in plain English and it builds and deploys a full-stack app with a database and role-based access. That can replace a tangle of spreadsheets or another subscription. Agents can then be pointed at an app you own, and the record stays in one place your team controls.

## Frequently Asked Questions

### Do I need to know how to code to use a repo for project knowledge?
No. The point is the discipline: central files, clear names, a record of changes. A repo is just a well-organized shared folder with history. Many people start with a simple set of Markdown or text files.

### Won't a second AI just fix the problem if the first one got stuck?
Usually not. Handing the same unclear assignment to a different model, such as Claude or Gemini, doesn't help if the structure is wrong. The next agent needs the learning from the first run: what you want, which phase you are in, and what you already decided.

### Is a roles file enough to keep agents safe?
No. It is a useful stopgap that gets you a long way, but real guardrails such as identity and permission controls are stronger. Use the file for clarity now, add enforced permissions as you can, and keep a human reviewing important changes.

### Why write skills for the team instead of for myself?
Personal skills produce personal quirks. When each person builds their own, results drift and the agents often don't use the same data. Team-level skills give everyone, and any AI tool, the same approach to a task.

### What is the first thing I should write down?
The decision you are most tired of repeating. Write it as a record with a date, a reason, what it replaces and what an agent must not do. Then point every new run at that file.
