Skip to main content
The sample agent is a small airline customer support bot that can help with demo booking lookups, baggage policies, seat changes, and flight-change guidance. Each terminal conversation is saved under logs/, so you can turn real conversations into RELAI learning environments.

Before you start

You’ll need the following to run the agent:
  • Python 3.11+
  • uv
  • OPENAI_API_KEY or ANTHROPIC_API_KEY — add one provider key for the airline support agent.
  • RELAI_API_KEY — from the API keys page.
  • GitHub CLI (gh) — authenticated with gh auth login; recommended for forks and PRs created by the optimizer.
Some commands in this walkthrough can take a few minutes while RELAI inspects the agent, generates support files, or runs simulations. Optimizer runs usually take longer and may run for several minutes.
Fork the sample repo to your GitHub account, then clone your fork:

Required RELAI setup

Before running any learning loop, complete these setup steps. Installation and setup are machine-level steps you only need once on a new machine. The provider key is needed whenever you run simulations or the sample agent. Initialization is project-level and should be run once per agent repository.
1

Install the RELAI CLI

Install the CLI locally so setup, simulation, and optimization commands can run. See Install & setup for the installer and prerequisites.
2

Set up RELAI

Configure your RELAI API key and CLI preferences with relai setup. See the relai setup reference for options, checks, and credential details.
3

Add a provider API key

Add either OPENAI_API_KEY or ANTHROPIC_API_KEY to the current shell before running relai commands. RELAI uses the provider key for simulating this sample agent. Agent runs you start yourself with start.sh also use this key.
or
4

Initialize RELAI

From the airline customer support agent repository root, register the project and generate a simulator harness for this agent. See the relai init reference for more information on what this creates. When relai init asks whether to mock components or tools, it is safe to accept the defaults for this agent. Those choices control how the simulator handles the agent’s components and tools.
After initialization completes, review and commit the RELAI-managed changes if you did not accept init’s interactive commit prompt, then push them to GitHub.

Learning loops

After setup and initialization, use a prompt, terminal agent log, or benchmark CSV to run a RELAI learning loop.

Prompt to Optimized Agent

Create a learning environment from a plain-English behavior requirement.

Failure Log to Optimized Agent

Capture a bad terminal conversation, then optimize from the saved JSONL log.

Benchmark to Optimized Agent

Register the CSV benchmark and optimize across a reusable test suite.

Global Evaluators to Optimized Agent

Add a scoring rule that applies across simulations.

Prompt to Optimized Agent

Turn one simple plain-English behavior prompt into a learning environment, measure the current agent against it, then optimize toward that behavior. Use this when you have a target behavior in mind and want the agent to follow it reliably. 1. Create the learning environment from the required response signoff:
2. Simulate the current agent for a baseline:
3. Optimize toward the behavior:

Failure Log to Optimized Agent

Capture undesirable behavior in a terminal session, then turn that log and your feedback into a learning environment. Use this when the agent did something wrong and you want to prevent it from happening again. 1. Run the sample agent with a fixed log name:
Then send this off-topic prompt:
End the session with exit, quit, or q. The agent prints the saved log path: logs/off-topic-guardrail.jsonl. 2. Create the learning environment from the session log and feedback:
3. Simulate the current agent against the guardrail:
4. Optimize to prevent the behavior:

Benchmark to Optimized Agent

Register a reusable benchmark in CSV format, then run simulation and optimization against it. Use this when you have a set of samples, each with inputs, expected outputs, and sample-specific evaluators, that should be rerun together. 1. Register the CSV as a benchmark:
2. Simulate across the suite:
3. Optimize with the benchmark:

Global Evaluators to Optimized Agent

Create one evaluator that applies across all simulations for the agent. Use this when one scoring rule should apply globally instead of living in a single learning environment. Finish the prompt, failure-log, or benchmark loop first so there is a learning environment or benchmark for the global evaluator to score. 1. Create the global response-token evaluator:
2. Simulate against a learning environment or benchmark created by one of the other loops. RELAI applies the global evaluator automatically after it has been created.
If you finished the benchmark loop instead, simulate against the benchmark:
3. Optimize with the global evaluator active:
If you finished the benchmark loop instead, optimize against the benchmark:

Ready for your own agent?

Run the same loop on your own repo: initialize, create one learning environment, simulate, optimize.

The learning loop

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