> ## Documentation Index
> Fetch the complete documentation index at: https://cli-docs.relai.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# The learning loop

> How RELAI turns a requirement gap into a reviewed fix, one pass at a time.

RELAI turns a gap between how your agent behaves and the business requirements it should meet into a validated fix ready for review. You define the behavior you expect as learning environments, benchmarks, or global evaluators. RELAI optimizes against that definition and validates the result, then prepares any accepted improvement for review. The next gap starts the loop again, and over successive passes the agent's behavior moves toward the requirements you care about.

## The loop at a glance

<Frame caption="One pass through the loop: a requirement gap goes in, a validated and reviewed fix comes out, then the next gap starts it again.">
  <img className="block dark:hidden" src="https://mintcdn.com/relai/ABFAyGwi7FITf7mY/images/learning-loop-light.svg?fit=max&auto=format&n=ABFAyGwi7FITf7mY&q=85&s=fe9a291a2a3d857e2ddeae62f0c90946" alt="The RELAI learning loop. A failure or gap in meeting business requirements is identified, the expected behavior is defined as learning environments, benchmarks, or global evaluators, a fix is optimized and validated, and the improvement ships as a reviewed pull request. The loop then repeats." width="760" height="720" data-path="images/learning-loop-light.svg" />

  <img className="hidden dark:block" src="https://mintcdn.com/relai/ABFAyGwi7FITf7mY/images/learning-loop-dark.svg?fit=max&auto=format&n=ABFAyGwi7FITf7mY&q=85&s=31f6370be69578a880e8456bbf008142" alt="The RELAI learning loop. A failure or gap in meeting business requirements is identified, the expected behavior is defined as learning environments, benchmarks, or global evaluators, a fix is optimized and validated, and the improvement ships as a reviewed pull request. The loop then repeats." width="760" height="720" data-path="images/learning-loop-dark.svg" />
</Frame>

## Before the loop

[`relai init`](/cli/init) seeds, locally validates, and registers the simulator
harness that lets RELAI run your git-tracked agent project. Run it once per
project, before the first pass. If it pauses for input, approval, an external
action, or an interruption, continue with `relai init --resume`.

## The loop, step by step

Each pass moves through four stages: a requirement gap is found, the expected behavior is defined, a fix is optimized and validated, and the improvement is shipped for review. Then the loop repeats.

<Steps titleSize="h3">
  <Step title="Requirement gap">
    Every pass starts with a real signal: a failure in production, or any gap between how the agent behaves and the business requirements it should meet. You bring the case that fell short and the outcome you expected, and the rest of the loop turns it into a fix.
  </Step>

  <Step title="Define expectations">
    Define the behavior you expect so RELAI has something concrete to target. You can express it three ways:

    * **Learning environments** are the unit of behavior: a repeatable scenario RELAI can simulate and optimize against. Create one from a prompt, or from a real run log plus your feedback, with [`relai learning-env`](/cli/learning-env).
    * **Benchmarks** are reusable evaluation suites built from a CSV, so you measure against the same cases on every pass. Register and list them with [`relai benchmark`](/cli/benchmark).
    * **Evaluators** score agent behavior, so the loop has a number to act on instead of a pass-or-fail judgment. Scope one to an environment or a benchmark, or register it globally so it applies across runs, with [`relai evaluator`](/cli/evaluator).
  </Step>

  <Step title="Optimize & validate">
    Measure where the agent stands, then let RELAI improve it and prove the improvement held.

    * **Simulate** runs your agent against the environments or benchmarks you select and reports the evaluator scores. It does not change your agent; it shows where the agent stands today. Run it with [`relai simulate`](/cli/simulate). Simulating first is optional — optimize runs its own before-and-after evaluation.
    * **Optimize** runs its own before-and-after evaluation, then proposes improvements to prompts, configs, and structure and validates the result. Run it with [`relai optimize`](/cli/optimize).
  </Step>

  <Step title="Review improvements">
    Accepted changes are committed to a separate local optimizer branch. When GitHub CLI is available and authenticated, RELAI can push that branch and open a pull request; otherwise, review and publish it yourself. Once the change merges, the next gap you spot becomes a new learning environment, and the loop runs again. Optimize's before-and-after evaluation pass provides the attached proof, and memory carries forward, so each pass builds on what earlier ones learned.
  </Step>
</Steps>

## Memory and tags

Memory and tags shape the whole loop rather than a single stage. **Memory** is markdown guidance RELAI considers during later generation and optimization, scoped to an agent, tag, component, or evaluator. **Tags** group learning environments into a reusable suite you can select by name when you simulate and optimize. Manage both with [`relai tag & memory`](/cli/tag-and-memory).

## Related pages

<CardGroup cols={2}>
  <Card title="Quickstart" icon="bolt" href="/quickstart">
    Run init, simulate, and optimize on your own project in 5 minutes.
  </Card>

  <Card title="All commands" icon="terminal" href="/cli/overview">
    Every `relai` command with flags, examples, and failure modes.
  </Card>
</CardGroup>
