Connect an agent
To connect an agent, you put Reef between the agent and its model. The agent sends each model call to Reef. Reef stores the call as a record, and returns the record's ID: the receipt. The agent then sends one report for each run, with the receipt and your feedback. For a coding agent, Reef also gives the harness: the rules, the skills and the commands that the agent loads.
This page has one section for each way to connect:
|
Your agent |
Way |
What it needs |
|---|---|---|
|
A program or an agent framework that calls the OpenAI or the Anthropic API |
The address of Reef, a token, and one header. It works with any recipe. | |
|
A Python program |
pip install reef-client. It works with any recipe. | |
|
Claude Code, Codex, OpenCode or pi |
A deployment of a harness recipe whose adapter is the agent | |
|
Another coding agent |
An adapter.yaml in a Python package |
Before you start #
You need a Reef that runs, its address and a token. The examples read them from two variables, and use a scenario with the name demo:
export REEF_URL=http://127.0.0.1:8900
export REEF_TOKEN=reef-localThe first two ways work with any deployment, such as the one of Use Reef. Without a deployment, start with the next section: it needs no GPU and no recipe.
Start Reef in front of a model that you already use #
Without a deployment file, reef serve puts Reef in front of a hosted model. You need a Reef checkout and the key of the provider:
export REEF_TOKEN=reef-local
export REEF_UPSTREAM_API_KEY=sk-...
reef serve --inference.upstream-url https://api.openai.com --inference.upstream-model gpt-4oReef listens on http://127.0.0.1:8900 and stays in the foreground. It stores each call and each report, and it trains nothing: the default recipe only stores records.
|
Setting |
Variable |
Value |
|---|---|---|
|
inference.upstream-url |
REEF_UPSTREAM_URL |
The base URL of the provider, without /v1 |
|
inference.upstream-model |
REEF_UPSTREAM_MODEL |
The model that Reef asks the provider for |
|
inference.upstream-api-key |
REEF_UPSTREAM_API_KEY |
The key of the provider |
|
inference.upstream-api |
No variable |
openai (default), responses or anthropic: the API that Reef speaks when it calls the model itself, as in the runs of a harness recipe |
|
reef.token |
REEF_TOKEN |
The token that a client sends to Reef |
Each setting is a flag of the same name, such as --inference.upstream-api anthropic. Without the flag, reef serve reads the variable. A deployment file holds the same settings (recipes/basic/external-provider.yaml):
# The OpenAI-compatible provider (no /v1 suffix), its credential, and model.
inference:
upstream-url: https://api.openai.com
upstream-api-key: ${REEF_UPSTREAM_API_KEY}
upstream-model: gpt-4o
timeout-s: 300In a second terminal, make a scenario, and read the state of its model:
curl -fsS "$REEF_URL/reef/scenarios" \
-H "Authorization: Bearer $REEF_TOKEN" -H 'Content-Type: application/json' -d '{"name": "demo"}'
curl -fsS "$REEF_URL/reef/scenarios/demo/inference/status" -H "Authorization: Bearer $REEF_TOKEN"A scenario holds one workload: its records, its samples and its versions. Repeat the second request until state is ready. If state is failed, error says why. Then send one call and one report, as the next section shows.
Any OpenAI-compatible client #
This way works with any recipe. Your agent does two things: it sends each model call to Reef, and it sends one report for each run.
The model call #
Point the client at Reef:
|
Setting of the client |
Value |
|---|---|
|
Base URL |
http://<host of Reef>:8900/v1. A client that adds /v1 itself, as an Anthropic client does, takes the address without /v1. |
|
API key |
The Reef token. Reef reads it from Authorization: Bearer <token>, or from x-api-key when the request has no Authorization header. |
|
Extra header x-reef-scenario |
The name of the scenario. The scenario must exist: POST /reef/scenarios makes it. |
|
model of each request |
active: the version that the scenario serves now. The ID of a served version selects that version, and any other value means active. |
Reef answers three provider APIs. The body of a request is the body of that API:
|
Route |
API |
|---|---|
|
POST /v1/chat/completions |
OpenAI Chat Completions |
|
POST /v1/responses |
OpenAI Responses |
|
POST /v1/messages, POST /v1/messages/count_tokens |
Anthropic Messages |
Reef sends the body to the same route of the model behind it, so that model decides which routes answer. A hosted provider answers the routes of its own API. A model that Reef serves on SGLang or vLLM answers /v1/chat/completions and the two /v1/messages routes. Tinker answers /v1/chat/completions only.
One call:
curl -sS -i "$REEF_URL/v1/chat/completions" \
-H "Authorization: Bearer $REEF_TOKEN" -H "x-reef-scenario: demo" -H 'Content-Type: application/json' \
-d '{"model": "active", "messages": [{"role": "user", "content": "What is 2 + 2?"}]}'The response is the provider's response, with two more headers:
HTTP/1.1 200 OK x-reef-artifact-id: artifact:ee34fb67... x-reef-agent-record-id: 312c7577...
-
x-reef-agent-record-id is the receipt. A stream has no such header: its receipt is the field reef.agent_record_id of an event at the end of the stream.
-
x-reef-artifact-id names the version that answered.
-
A client that cannot send a header puts the scenario in the path: POST /reef/scenarios/<scenario>/v1/chat/completions, and the same for the other routes. Its base URL is http://<host of Reef>:8900/reef/scenarios/<scenario>/v1.
|
Status |
Cause |
|---|---|
|
400 |
The request has no x-reef-scenario header, or its body is not a JSON object that the model takes |
|
401 |
The token is missing or wrong |
|
404 |
The scenario does not exist |
|
503 |
The model of the scenario starts. Read GET /reef/scenarios/<scenario>/inference/status until state is ready. |
The report #
A report is one call, with the receipt and your feedback:
curl -sS "$REEF_URL/reef/report" \
-H "Authorization: Bearer $REEF_TOKEN" -H "x-reef-scenario: demo" -H 'Content-Type: application/json' \
-d '{"references": ["<receipt>"], "score": 1.0}'Reef answers with the ID of the stored report:
{"agent_record_id": "83dda9e2...", "scenario": "demo", "request_type": "report"}-
references names the run by the receipt of its last model call.
-
The recipe decides what else a report holds, such as a score. Reef answers 400, with the name of the field, to a report that the recipe does not take. Use Reef gives the report of each recipe.
-
The report has no path form: it needs the header x-reef-scenario.
The client contract has every header and every field of the two calls.
A run of several calls #
A run of several calls gets one report, with the receipt of its last call. Reef finds the earlier calls of the run from the last one: the request of the last call holds the conversation of the run. This agent drafts an answer and then checks it (recipes/minimal/examples/agent.py):
def run(question: str) -> tuple[str, str]:
"""One run of the agent: two model calls. Return the final answer and the receipt of the last call."""
messages = [{"role": "user", "content": question}]
draft, _ = call(messages)
# The second call continues the conversation of the first.
messages += [
{"role": "assistant", "content": draft},
{"role": "user", "content": "Check your work. Reply with the final number alone."},
]
return call(messages)answer, receipt = run(f"What is {left} + 2?")
score = float(str(left + 2) in answer)
# One report for the whole run: reference its last call only.
client.report(SCENARIO, {"score": score}, references=[receipt])With the minimal recipe, both replies of such a run train: the sample of a run holds every reply of the served model in it.
reef-client (Python) #
reef-client is a Python package without dependencies. ReefClient sends the token and the scenario header with each call, and returns the receipt. Each method is one of the HTTP calls above.
pip install reef-clientThe client of the minimal recipe makes every call of a run (recipes/minimal/examples/client.py). It imports ReefClient from reef_client, and makes one client for the deployment:
client = ReefClient("http://127.0.0.1:8900", token=os.environ["REEF_TOKEN"], timeout_s=600)It makes the scenario, and waits until the model serves:
# A scenario holds one workload: its records, its samples and its versions.
client.post("/reef/scenarios", SCENARIO, {"name": SCENARIO})
wait_until_the_model_serves()def wait_until_the_model_serves() -> None:
while client.get(f"/reef/scenarios/{SCENARIO}/inference/status")["state"] != "ready":
time.sleep(5)Then it calls the model, and reports on the run:
def ask(question: str) -> tuple[str, str]:
"""One model call through Reef; return the answer and the call's receipt."""
request = {"model": "active", "messages": [{"role": "user", "content": question}], "max_tokens": 64}
body, receipt = client.inference_with_record(SCENARIO, "/v1/chat/completions", request)
return body["choices"][0]["message"]["content"], receipt
def report(receipt: str, score: float) -> None:
"""Report on the run that ends with the call ``receipt``: the score of your own check."""
client.report(SCENARIO, {"score": score}, references=[receipt])-
inference_with_record returns the response body and the receipt.
-
report adds references to the body, and sends POST /reef/report.
-
post and get call any other route.
-
An answer with a status of 400 or more raises ReefClientError, which has its status and its body.
-
ReefClient reads the whole response of a call. For a stream, use the client of the provider.
Use Reef runs this client through the whole loop.
A coding agent #
One command connects Claude Code, Codex, OpenCode or pi to a scenario of a harness recipe. The agent then loads the harness that Reef serves, and sends its model calls through Reef.
The harness is a tree of files that the agent reads:
-
rules: the instructions that the agent reads at the start of every session;
-
skills: Agent Skills, which the agent loads when their description fits the task;
-
commands: prompt templates that a person runs as /name;
-
extensions: code that the agent loads in its process.
A harness recipe changes this tree from your reports, and serves each new version (Evolve your harness).
What it needs #
-
A deployment of a harness recipe. recipe.config.evolution.adapter names the agent of the deployment, and the default is pi (gepa.yaml):
YAMLrecipe: implementation: recipes.gepa.recipe:GEPARecipe config: evolution: adapter: pi -
A model behind Reef that answers the API of the agent: see The adapters.
-
On your machine: Linux or macOS, Python 3.10 or later, and reef-client. connect installs a missing agent with npm, so it then needs Node.js.
With another recipe, reef-client harness connect answers that the scenario serves no files. A coding agent can still send its calls through Reef: set its own provider settings as for any OpenAI-compatible client, with the scenario in the path. Reef then records the calls, and gives no harness.
Connect #
pip install reef-client
reef-client harness connect my-agent --reef "$REEF_URL"The clients of one scenario share one harness. connect prints one line when it is done, here for pi:
Done. Open a new terminal and run pi.
connect does these steps:
-
It reads the address from --reef or REEF_URL, and the token from REEF_TOKEN. It asks for the token when Reef answers 401. Without a scenario name, it takes the only scenario of the deployment, or asks.
-
It makes the scenario when the scenario is new.
-
It installs the harness that the scenario serves in ~/.local/share/reef-client/harness/<scenario>/, or under $XDG_DATA_HOME when you set it. The directory also keeps the token, in a file that only you can read.
-
It installs the agent with npm when your machine has none, at the version that Reef's own runs use.
-
It runs the agent's own command that loads the harness as a plugin, so each session of the agent loads it. reef-client does not edit your own configuration of the agent.
-
It puts a command with the name of the agent in ~/.local/share/reef-client/bin/, and puts that directory first on PATH in the startup file of zsh, bash or fish. For another shell, it prints the directory.
|
Agent |
The command that loads the harness |
Your own configuration, which stays |
|---|---|---|
|
Claude Code |
claude plugin marketplace add <install>, then claude plugin install reef@reef |
~/.claude |
|
Codex |
codex plugin marketplace add <install>, then codex plugin add reef@reef |
~/.codex |
|
OpenCode |
opencode plugin -g <install>/plugin |
~/.config/opencode |
|
pi |
pi install <install>/plugin |
~/.pi/agent |
From now on, start the agent as before: pi, claude, codex or opencode. Each session does three things:
-
Before the agent starts, it syncs: it sends the files that you changed, and installs the harness that the scenario serves now. When Reef does not answer, the agent starts on the files that it has.
-
The agent sends its model calls to <address of Reef>/reef/scenarios/<scenario>/v1/... with your token. Reef stores each call as a record.
-
When the agent exits, a background process sends the harness files that the session changed, such as a new skill.
The commands #
SCENARIO is optional when one scenario is installed.
|
Command |
What it does |
|---|---|
|
reef-client harness connect [SCENARIO] [--reef URL] |
Sets the machine up, as above |
|
reef-client harness run [SCENARIO] [-- AGENT ARGS] |
One session: sync, run the agent, send its changes. The agent's command in bin/ runs it for you. |
|
reef-client harness sync [SCENARIO] [--discard] |
Sends the files that you changed, and installs the harness that the scenario serves. --discard drops your changes instead. |
|
reef-client harness status [SCENARIO] |
Shows the installed version, whether it is the version that the scenario serves, and the files that you changed and did not send |
|
reef-client harness disconnect [SCENARIO] [--discard] |
Removes the install, the plugin and the agent's command. It refuses while changes are not sent, unless you give --discard. |
To change the harness yourself, edit a file of the install, such as ~/.local/share/reef-client/harness/my-agent/plugin/rules.md for pi. Then run reef-client harness sync. Reef merges your change with its own: by line for rules, skills and commands, and by file for code. Sync refuses when you and Reef changed the same lines, or the same code file. Fix the file and sync again, or drop your change with sync --discard. While a training step runs, Reef refuses the files, and they wait for the next session or the next sync.
Report on a session #
A coding agent does not show the receipts of its calls. To report on a session, read the last call that the scenario recorded, and reference it. Run this right after the session, while no other client uses the scenario. It needs jq:
RECORDS="$REEF_URL/reef/scenarios/my-agent/records?request_type=inference&limit=100"
AFTER=0
while [ "$AFTER" != null ]; do
PAGE=$(curl -fsS -H "Authorization: Bearer $REEF_TOKEN" "$RECORDS&after_sequence=$AFTER")
AFTER=$(jq '.next_after_sequence' <<< "$PAGE")
done
LAST=$(jq -er '.records[-1].agent_record_id' <<< "$PAGE")
curl -fsS "$REEF_URL/reef/report" \
-H "Authorization: Bearer $REEF_TOKEN" -H "x-reef-scenario: my-agent" -H 'Content-Type: application/json' \
-d "{\"references\": [\"$LAST\"], \"score\": 0}"With a harness recipe, the reports start training steps. A step changes the harness, and the next session installs the version that Reef keeps (Evolve your harness).
The adapters #
An adapter describes one agent to Reef. A deployment of a harness recipe has one adapter, and Reef ships eight:
|
Adapter |
Agent |
Provider API |
harness connect |
Reef runs it for evaluations |
|---|---|---|---|---|
|
claude |
Claude Code |
anthropic |
Yes |
Yes, installed from npm |
|
codex |
OpenAI Codex CLI |
responses |
Yes |
Yes, installed from npm |
|
opencode |
OpenCode |
openai, anthropic |
Yes |
Yes, installed from npm |
|
pi (default) |
pi |
openai, responses, anthropic |
Yes |
Yes, installed from npm |
|
dsh |
DeepSeek Harness |
openai, anthropic |
No |
Yes, installed from npm |
|
hermes |
Hermes Agent |
openai |
No |
Yes, installed from a Git checkout |
|
native |
Reef's own agent loop, reef-native |
openai |
No |
Yes, but not on Harbor task directories: it has no install |
|
python |
A Python program, which uv runs |
openai |
No |
Yes, with uv installed from PyPI |
-
Provider API is the API that the agent speaks: openai is OpenAI Chat Completions, responses is OpenAI Responses, and anthropic is Anthropic Messages. The model behind Reef must answer one of them. With an upstream provider, set inference.upstream-api to that API. Its default is openai, so a deployment for claude sets anthropic, and one for codex sets responses.
-
Reef runs it for evaluations: a harness recipe runs the agent on tasks to score a new harness. Reef installs the version that the adapter pins, on the host of the runs, unless evolution.binary names a binary.
-
The adapter also lists the kinds of file that Reef may change. Most adapters take rules, skills, commands and extensions. codex takes skills and commands only. native takes rules, skills, and the tools, hooks, graphs, agents and loop code of the loop. python takes the modules of the program.
GET /reef/harness/adapters lists the adapters that a deployment can load.
Write an adapter #
Write an adapter to connect another coding agent. An adapter is one file, adapter.yaml, which Reef loads as an AdapterDescriptor (descriptor.py). The file says which files Reef may change, how the agent reaches the model, how a run starts the agent, and where the agent writes its sessions.
The file #
The smallest built-in adapter is python (adapter.yaml):
name: python
binary: uv
# uv from PyPI at the pinned version. Reef uploads the same version into a task's container.
install:
kind: uv
package: uv
version: "0.13.4"
binary_path: "venv/bin/uv"
# What Reef may evolve: the program's modules. A program is code, so a change always waits for a person.
evolve:
program: program/{name}.py
dirs:
program/sessions: REEF_PROGRAM_SESSION_DIR
sessions: {format: python-jsonl, path: program/sessions}
# The served model reaches the program through this file only. base_url ends in /v1, as an OpenAI client takes it.
model:
openai:
- target: model
data:
api: openai
base_url: "{base_url}/v1"
api_key: "{api_key}"
model: "{model}"
run:
task:
argv: ["run", "--script", "{root}/program/main.py", "{task}"]
# The program's own settings (primary), which a tree's config/primary.json sets, and the model binding (model).
config:
primary:
path: "program/config.json"
defaults: {}
model:
path: "program/model.json"
defaults: {}The loader requires six keys, and refuses a key that it does not know:
|
Key |
Required |
What it declares |
|---|---|---|
|
name, binary |
Yes |
The name that a deployment selects, and the program that a run starts |
|
evolve |
Yes |
Each kind of file that Reef may change, with the path where the agent reads it |
|
sessions |
Yes |
The path and the format of the session log. format names a built-in reader, or a TrajectoryReader class of yours as package.module:ClassName (trajectory.py). |
|
run.task |
Yes |
argv, the arguments of one headless run: {task} is the text of the task, and {root} is the directory of the run |
|
config |
Yes: the target primary |
The config files of the agent. Each target has a path, and optional defaults and checks. |
|
model |
No, but a run needs it |
For each provider API, the config that points the agent at the model: {base_url}, {api_key}, {model} |
|
install |
No |
The pinned version of the agent, which Reef's runs and harness connect install |
|
run.layer |
No, but harness connect needs it |
How a person's machine runs the agent |
The docstring of descriptor.py describes every key, with the other optional ones. Harness adapter says when Reef reads each key.
run.layer of pi (adapter.yaml):
layer:
args:
- ["--model", "reef/{model}"]
register:
- ["install", "{root}/plugin"]
unregister:
- ["remove", "{root}/plugin"]-
args are arguments that each session adds to the agent's command. env holds variables of the session.
-
register are commands of the agent that the client runs after it installs the files. unregister are the commands that disconnect runs to undo them.
-
{root} is the install directory, and {model} and {base_url} are those of the scenario. {token} is the token of the client. Put it only in env: other processes can read a command line.
The kinds of file #
evolve lists kinds of this table (parts.py). The kind gives the path of the file in the tree, and how Reef merges your change of the file with its own. List only the kinds that the agent reads in each mode that the adapter supports.
|
Merge |
Kind, and its path in the tree |
|---|---|
|
By line |
rules (rules.md), skill (skills/{name}/SKILL.md), command (commands/{name}.md) and memory (memory/{name}.md) |
|
By file |
extension (extensions/{name}, with the suffix of the path where the agent reads it), program (program/{name}.py), and the five native_* kinds under native/ |
|
Not sent back by a client |
config/<target>.json, which each adapter takes: Reef merges it into the config file of that target |
Register and select #
A built-in adapter is a directory reef/harness/adapters/<name>/ with its adapter.yaml, and a name in BUILTIN_ADAPTERS (adapters/__init__.py).
An adapter of your own is in a Python package, which ships the adapter.yaml as package data. The package registers the adapter with an entry point of the group reef.harness_adapters. The entry point names an AdapterDescriptor, or a function without arguments that returns one. The Terminal-Bench example of the Meta-Harness recipe registers its adapter terminus this way (reef_terminus):
def descriptor() -> AdapterDescriptor:
"""The terminus adapter: the ``reef.harness_adapters`` entry point that installing the campaign registers."""
return load_descriptor(Path(__file__).parent / ADAPTER_FILE)[project.entry-points."reef.harness_adapters"] terminus = "reef_terminus:descriptor"
A deployment selects the adapter by its name: recipe.config.evolution.adapter: terminus. Reef refuses to start with a name that it cannot load, and the message lists the names that it knows.
Rules for an adapter #
-
Keep the model endpoint and its key out of the tree. model writes them when Reef renders the tree for a run. Name in checks each config key that selects a model, so that a tree cannot set another route. A refusal names the key and the reason, never the value.
-
Pin the version of the agent in install.
-
Keep a renderer without state. A renderer is an AdapterRenderer class, for the render steps that the file cannot state. Each step is a static method, and raises RenderError to refuse a tree.
-
Declare what a Harbor task gives the agent: run.task.skills for the skills of a task, and run.task.mcp for its MCP servers. Reef refuses a task that needs one that the adapter does not declare.
-
Take the token limits from Reef: write {context_window} and {max_output_tokens} in model where the agent sets token limits.
Test it #
Test the adapter as tests/harness/ tests the built-in ones:
python -m pytest tests/harness -q|
Test |
What it checks |
|---|---|
|
The file loads: load_descriptor parses each key and each match expression of checks | |
|
The render of one tree is the files in tests/harness/data/harness_goldens/<adapter>/. test_terminus_render.py does the same for an adapter of a package. | |
|
A tree cannot select another model or another endpoint | |
|
The real agent runs one task against a stand-in model, and Reef reads its session log. A test runs only when a variable such as REEF_REAL_PI_BINARY names the program; the workflow harness-smoke sets it. |
Limits #
-
Every token opens every route. For the permissions of one user or one scenario, put a gateway in front of Reef.
-
Reef serves HTTP. Put a proxy that ends TLS in front of it.
-
A stream that fails after its first event gives no receipt, so its run cannot be reported.
-
In a deployment with one process for each service, the model calls go to the inference service, and the report goes to control (Run Reef in production).
-
reef-client harness runs on Linux and macOS. It installs a missing agent only with npm, and it changes the startup file of zsh, bash and fish only.
-
The command of one agent runs one scenario. A second connect for the same agent replaces the first.
-
OpenCode has no command that removes a plugin. After disconnect, its plugin entry stays, and OpenCode skips the path that no longer exists.
-
evolution.adapter takes a name, not a class reference: an adapter of your own needs an installed package.
-
The tests run each real agent against a stand-in model, not against the model of a provider.
Next steps #
-
Use Reef: the whole loop, from the reports to a new version of the model.
-
Evolve your harness: a harness recipe that changes the rules of a coding agent.
-
Run Reef in production: the processes, the state, the sandboxes and the tokens.
-
Production interfaces: the full contract of the client and of the harness adapter.