Major

How to Build AI Agents That Survive Run 1,000

Every guide teaches you to get one run working. None covers what breaks on run 1,000: vanishing state, climbing token spend, unscoped credentials, and no record of what the agent did. Here is the build, through to production.

Rahul RamakrishnanUpdated
Two engineers sketching an agent workflow on a whiteboard while planning how to build an AI agent

An AI agent is a model with instructions, tools, and a loop that runs until an exit condition fires. You can build that in an afternoon. Building one that still works on run 1,000 takes four more things: state that lives outside the context window, a credential scoped to each tool, an audit record of every action, and repeated steps moved out of the model and into code. Major is where that last step happens by default: the agent builds an app for the repeatable work, and the app carries the state, permissions, and logs.

This guide is for engineers and AI operators who have a prototype and need it to run unattended against real systems.

What is an AI agent, precisely?

Three parts. Instructions define the job and its limits. Tools are the functions the model can call to read data or take action. The loop feeds tool results back to the model until it decides the task is done or a guard stops it. OpenAI's practical guide to building agents describes the same three components: model, tools, and instructions.

Everything else in this article is what the prototype leaves out.

Step 1: Pick one task you can score

Choose a job with a measurable outcome and a clear stopping point. "Reconcile each Stripe payout against the matching invoice and flag mismatches" qualifies. "Help finance" does not.

Write two lists before any code. What counts as done. What the agent must never do, such as send external email or write to a ledger without approval. The second list becomes your tool permissions later.

Step 2: Build the prototype loop

Give the model two or three tools, a short system prompt, and a maximum step count. Run it against ten real examples, not synthetic ones. Read every trace.

Expect it to work. That is the trap. A prototype that passes ten examples tells you nothing about the failure modes that appear at volume.

Why agents break on run 1,000

Four things fail, in roughly this order.

  • State vanishes. The context window holds the current run. When it ends, the agent cannot tell which invoices it already processed, so a retry reapplies side effects.
  • Cost climbs with usage. An agent that re-reasons the same routine step on every run pays for that reasoning every time. Spend scales with volume.
  • Credentials are too broad. One API key with write access to everything means one bad tool call can touch anything.
  • Nobody can reconstruct what happened. If an agent took an irreversible action, you need the tool inventory, the decision, the side effects, and the identity it acted under. A chat transcript does not give you that.

The fix for all four is the same move. Stop treating the agent as the place where work runs, and treat it as the thing that decides what to do and builds the software that does it.

Build the production agent on Major

Major is the enterprise platform where agents build the software they run on. Here is the reconciliation example as a concrete build.

  • Connectors. Attach Stripe, NetSuite, Gmail, and Slack as connectors. Each agent action goes through a scoped credential, so the agent never holds a raw key.
  • The app that holds state. The agent builds a reconciliation app with a managed database: a payouts table, an invoice-match table, and a run log keyed by payout ID. A retry finds the existing row and skips completed work.
  • Deterministic steps in code. Fetching payouts, matching amounts, and writing results are the same every run, so they live in the app and run as code, not as fresh reasoning.
  • Agent judgment. The model handles only what code cannot: a partial payment, a duplicate with a different reference, a contract clause that changes the expected amount. It writes its decision and rationale back to the app.
  • Trigger. A scheduled workflow runs the app nightly. A Slack approval step gates any write above a threshold you set.
  • Governance. Role-based access controls who can view, run, and edit the app. Every run, tool call, and approval lands in an audit trail.

Reason once, run forever. The agent works out the matching logic one time. After that the app runs it, and the model is called only for the exceptions. Cost is front-loaded and then flat rather than rising with every run. The model still does less, not nothing: judgment calls still go through it.

Start building free and describe the reconciliation job to see the app and workflow it produces.

Step 3: Scope every credential

OpenAI's guide recommends rating each tool by read versus write access, reversibility, and financial impact, then using that rating to decide how much oversight a call needs. Apply it literally. A read-only lookup runs freely. A reversible write runs with logging. An irreversible or financial write waits for a human.

Give each tool its own credential limited to what that tool does. A credential proxy at the point of action also means you can revoke one tool without breaking the others.

Step 4: Log for reconstruction, not for debugging

Debug logs tell you why something broke. An audit record tells a reviewer what happened in March. Capture, per action: the tools available at that moment, the agent's stated decision, the side effects that landed, the identity used, and enough input to replay the deterministic part.

This is straightforward when the work lives in an app, because the app writes its own logs. It is hard when the work lives inside a prompt, because the only record is a transcript of the model talking to itself.

What this guide does not cover

Evaluation, meaning how you score an agent's judgment calls over time, is a separate and harder problem. Multi-agent coordination is another. A task simple enough to fit in a single prompt with no side effects does not need any of this; run it as a prompt.

Start building on Major

Bring one real workflow that crosses two or three of your systems, and have Major's agent build the app, state, and approval gate that make it safe to run unattended.

Related articles

Frequently asked questions

How do I start making my first AI agent?
Pick one narrow task with a measurable outcome, then assemble three things: a model, the tools it can call, and instructions describing its job and its limits. Wrap them in a loop that runs until an exit condition fires. Write down what success means and what the agent must never do before you choose a framework or a model.
What do you need to build an AI agent?
A model to reason, tools it can call to read data and take action, instructions that define the job and its boundaries, a loop with explicit exit conditions, and somewhere durable for state to live. The last one gets skipped most often, and it determines whether the agent can resume after a failure.
How long does it take to build an AI agent?
A working prototype takes hours to days for someone comfortable with an LLM API. Getting the same agent ready to run unattended takes longer, because durable state, scoped credentials, audit logging, and idempotency are each real engineering work. The timeline depends on how many systems of record the agent writes to.
Where does an AI agent store its memory between runs?
In whatever durable store you give it, usually a database. The context window holds the current run and disappears when the run ends, so an agent relying on it alone cannot tell what it already processed. Recording each action against a stable key in a database prevents repeated side effects and allows resumption.
How do you keep an AI agent secure in production?
Give each tool its own credential scoped to exactly what that tool does, rather than one key with broad write access. OpenAI's guide recommends rating each tool by read versus write access, reversibility, and financial impact; use that rating to set the credential scope and whether a human approves the call. Log every action so it stays attributable.