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+
uvOPENAI_API_KEYorANTHROPIC_API_KEY— add one provider key for the airline support agent.RELAI_API_KEY— from the API keys page.- GitHub CLI (
gh) — authenticated withgh auth login; recommended for forks and PRs created by the optimizer.
- Python
- TypeScript (experimental)
- Go (experimental)
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 or
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.4
Initialize RELAI
From the airline customer support agent repository root, register the
project and generate a simulator harness for this agent. See the
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.
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.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: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: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:
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: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: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.