Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,27 @@ jobs:
- name: Update Rust
run: |
rustup update stable --no-self-update && rustup default stable
rustup component add clippy
rustup component add clippy rustfmt

- name: Lint
run: make lint

generate:
name: make generate-check
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Update Rust
run: rustup update stable --no-self-update && rustup default stable

# Other repos read schemas/, and the SDKs' types come from the protocol's
# schema, so both must match the Rust types.
# No Python setup: the script needs only the image's python3.
- name: Check generated files
run: make generate-check

version:
name: make version-check
runs-on: ubuntu-latest
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PYTHON ?= python3
MANIFEST := core/Cargo.toml

.DEFAULT_GOAL := help
.PHONY: help build install test lint generate generate-check version version-check
.PHONY: help build install test lint fmt generate generate-check version version-check

help: ## list the targets
@awk -F ':.*## ' '/^[a-z-]+:.*## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
Expand All @@ -17,10 +17,14 @@ install: ## install eac into ~/.cargo/bin
test: ## run the CLI's tests
$(CARGO) test --manifest-path $(MANIFEST)

lint: ## run clippy on the CLI and its tests, failing on any warning
lint: ## check formatting and run clippy on the CLI and its tests, failing on any warning
$(CARGO) fmt --manifest-path $(MANIFEST) --check
$(CARGO) clippy --manifest-path $(MANIFEST) --all-targets -- -D warnings

generate: ## regenerate protocol.schema.json and the Python SDK's protocol.py
fmt: ## format the CLI's code
$(CARGO) fmt --manifest-path $(MANIFEST)

generate: ## regenerate the protocol's and results' JSON Schemas and the Python SDK's protocol.py
$(PYTHON) scripts/generate.py

generate-check: ## fail if a generated file is out of date
Expand Down
61 changes: 24 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,14 @@ You write the runner that calls your system, the cases, and the judges that scor
pip install -e sdks/python # into the environment your evals run in
```

2. Add a project. An empty `eac.yml` marks its root, and each dataset gets a folder with a `dataset.yml` and its code:
2. Add a dataset: a folder anywhere in your repo with a `dataset.yml` and its code. eac finds every `dataset.yml` under the repo's root, or under the nearest folder with an [`eac.yml`](core/README.md#eacyml) if you need shared settings.

```
eac.yml
evals/chat/
dataset.yml
dataset.py
```

```yaml
# eac.yml
runtimes:
python:
# TODO
env: {PYTHONPATH: ../../sdks/python}

```

```yaml
# evals/chat/dataset.yml
name: chat
Expand All @@ -46,37 +36,38 @@ You write the runner that calls your system, the cases, and the judges that scor

```python
# evals/chat/dataset.py
from eac import Case, OfflineRunner
from eac.judges import Contains
from eac import Case, Judge, OfflineRunner, Score


def reply(query: str) -> str:
return "hello there" # call your system here


class ChatRunner(OfflineRunner):
def execute(self, case, ctx):
def run_case(self, case, *, seeds, conversation_id):
return {"response": reply(case.input["query"])}


CASES = [
Case(
name="greets",
input={"query": "hi"},
judges=[Contains(["hello"])]
)
]
class Greets(Judge):
name = "greets"

def judge(self, case, *, seeds, agent_trace=None):
ok = "hello" in case.output.get("response", "")
return Score(name=self.name, score=1.0 if ok else 0.0)


CASES = [Case(name="greets", input={"query": "hi"}, judges=[Greets()])]
```

3. Run it from the project's root:
3. Run it from the repo's root:

```sh
eac list # the datasets and cases eac found
eac offline run --dataset chat # seed, collect and judge every case in the chat dataset

# Alternatively, run each step separately
eac offline seed --dataset chat # seed (create fixtures) into a new run
eac offline collect # collect (execute cases) for the latest run
eac offline collect # collect (run each case) for the latest run
eac offline judge # judge (judge output of collect) for the latest run
```

Expand All @@ -85,7 +76,7 @@ project to start from.

### Online evals

Online evals judge what your system already did in production, so there are no cases or seeds. You write the runner that collects production records and the judges that score them.
Online evals judge what your system already did in production, so nothing is re-run and there are no seeds. You write the runner that collects production runs as cases, and the judges that score them.

1. Install the `eac` CLI and SDK as in step 1 above.

Expand All @@ -98,34 +89,30 @@ Online evals judge what your system already did in production, so there are no c
online:
runner: ./dataset.py:ProdChats
judges:
- {name: greets, path: ./dataset.py:GREETS}
- {name: greets, path: ./dataset.py:Greets}
```

```python
# evals/chat/dataset.py
from eac import OnlineRunner, Record
from eac.judges import Contains
# evals/chat/dataset.py, next to the Greets judge above
from eac import Case, OnlineRunner


class ProdChats(OnlineRunner):
def fetch(self, since, until, limit):
def collect_cases(self, window):
rows = [{"id": "trace-1", "query": "hi", "reply": "hello there"}] # query production here
return [
Record(id=row["id"], input={"query": row["query"]}, output={"response": row["reply"]})
for row in rows[:limit]
Case(name=row["id"], input={"query": row["query"]}, output={"response": row["reply"]})
for row in rows[: window.limit]
]


GREETS = Contains(["hello"])
```

3. Run it from the project's root:
3. Run it from the repo's root:

```sh
eac online run --dataset chat --judge greets --since 24h # fetch the last 24h of records and judge them
eac online run --dataset chat --judge greets --since 24h # collect the last 24h of production runs and judge them

# Alternatively, run each step separately
eac online collect --dataset chat --since 24h # collect (fetch records) into a new run
eac online collect --dataset chat --since 24h # collect production runs as cases into a new run
eac online judge --judge greets # judge the latest collected run
```

Expand Down
42 changes: 19 additions & 23 deletions core/PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The protocol is defined by the Rust types in [`src/schema/`](src/schema). `make

Workers (`python -m eac.worker`) import the user's datasets and do the real work: setting up seeds, running cases and judging outputs. Connections to outside services, like a seed cache shared between machines or a source of agent traces, are methods on the user's seeds and judges, so the worker calls them too.

eac starts each worker the first time it's needed, in the project root next to `eac.yml`, and reuses it for the rest of the command.
eac starts each worker the first time it's needed, in the project root, and reuses it for the rest of the command.

**One request at a time.**

Expand Down Expand Up @@ -44,19 +44,19 @@ eac sets these variables for the workers it starts:
| `EAC_WORKER=1` | Tells the worker the CLI started it |
| `EAC_ROOT` | The project root |

Workers also get the variables in the `.env` next to `eac.yml`, unless the real environment, saved credentials or the runtime's `env` in `eac.yml` already set them.
Workers also get the variables in the `.env` in the project root, unless the real environment, saved credentials or the runtime's `env` in `eac.yml` already set them.

## What each command sends

Each phase sends its own methods, so a worker only needs to answer the ones for the phases it's used in:

```
offline seed discover → args.validate → seed.setup
offline collect case.execute
offline collect case.run
offline judge case.judge
offline run all three phases, then seed.teardown for uncached seeds (compare does the same for each arm)
offline prune discover → seed.teardown
online collect discover → args.validate → online.fetch
online collect discover → args.validate → online.collect
online judge args.validate → online.judge
list, catalog discover
auth discover → args.validate → credentials.check → credentials.login
Expand All @@ -69,8 +69,9 @@ Before each phase, eac also sends `credentials.check` for what the phase needs,
These types show up in the params and results of many methods:

```jsonc
// Case
// Case: an offline case, or a production run collected for online judging
{"name": "get_dsn", "input": {}, "expected_output": {},
"output": {}, "conversation_id": "abc", // what the system produced: set by online.collect, and by eac when judging
"splits": ["smoke"], "enabled": true, // disabled cases run only when picked by name or split
"seeds": [Seed], "judges": ["regex"]} // judge names are for display; judges run in the worker

Expand All @@ -96,16 +97,14 @@ These types show up in the params and results of many methods:
"judges": [{"name": "polite", "path": "evals.chat.judges:Polite"}]} // online: named judges

// Score: 0..1; null is a diagnostic that doesn't gate pass/fail
{"name": "regex", "score": 1.0, "label": null, "explanation": null, "metadata": {},
{"name": "regex", "score": 1.0, "explanation": null, "metadata": {},
"llm_judge_metrics": Metrics} // optional: what an LLM judge spent on this score

// Metrics: every field optional, default 0
{"input_tokens": 0, "output_tokens": 0, "total_tokens": 0, "cache_read_tokens": 0,
"cache_write_tokens": 0, "reasoning_tokens": 0, "llm_duration_seconds": 0,
"llm_calls": 0, "tool_calls": 0, "cost_usd": 0}

// Record: a production run, for online judging
{"id": "run-123", "conversation_id": "abc", "input": {}, "output": {}}
```

## Worker methods
Expand All @@ -119,21 +118,17 @@ Params: `{"dataset"}`.
Imports the dataset's code and returns what only the code knows. It shouldn't have side effects beyond the import. Everything else, like the name, agent, comparisons, shard config and online judges, comes from the `dataset.yml`.

```jsonc
{"cases": [Case], // offline: every case
"args_schema": {}, // optional: JSON Schema of the runner's args, for `eac catalog`
"judge_args_schemas": {"llm_judge": {}}} // JSON Schema of each judge's args, for judges that take any
{"cases": [Case]} // offline: every case; online: nothing
```

### `args.validate`

Params: `{"dataset", "mode": "offline"|"online", "args", "judges"?, "judge_args"?}`.

eac calls this with `--args` and `--judge-args` before setting anything up, so bad args fail early. `judges` is an online run's chosen judges, or the judges a comparison scores every case with. Check that those can be built.
eac calls this before setting anything up. `judges` is an online run's chosen judges, or the judges a comparison scores every case with. Check that those can be built.

- `judge_args` is keyed by judge name, e.g. `{"llm_judge": {"rubric_file": "r.md"}}`. Check the entries for this dataset's judges and ignore the rest. One run's `--judge-args` cover all its datasets, and eac itself rejects names that no dataset uses.
- Return an error to reject the args.
- Return `{"args": {...}}` with defaults filled in. Those are the args eac records and sends to the runner.
- Also return `"runner_credentials": [Credential]`, what the runner needs with these args, and `"judge_credentials": {name: [Credential]}`, what each of the run's judges needs. eac records both so later phases can check them.
- Return `"runner_credentials": [Credential]`, what the runner needs, and `"judge_credentials": {name: [Credential]}`, what each of the run's judges needs. eac records both so later phases can check them.
- `args` is `--args` and `judge_args` is `--judge-args`, keyed by judge name, e.g. `{"llm_judge": {"rubric_file": "r.md"}}`. eac records them as given and sends them on to the runner and judges, and rejects judge names that no dataset uses. An SDK may return an error to reject them, but doesn't have to check them.

### `seed.setup` / `seed.teardown`

Expand All @@ -147,7 +142,7 @@ eac keeps cached seeds (`cache: true`) in `<artifacts>/seed-cache.json` and only

`eac offline prune` tears down the seeds in eac's local seed cache that no case uses. Seeds in a seed's own cache that no machine has locally are the seed's to clean up.

### `case.execute`
### `case.run`

Params: `{"dataset", "case", "seeds": {name: handle}, "args", "conversation_id"}`.

Expand All @@ -158,27 +153,28 @@ Runs the system under test on one case.

### `case.judge`

Params: `{"dataset", "case", "judges"?, "output", "error"?, "seeds": {name: handle}, "judge_args"?, "trace"?, "conversation_id"?, "agent"?, "started_at"?, "ended_at"?}`.
Params: `{"dataset", "case", "judges"?, "error"?, "seeds": {name: handle}, "judge_args"?, "trace"?, "agent"?, "started_at"?, "ended_at"?}`.

Scores one case's output and returns `{"scores": [Score]}`.

- `case` carries the runner's `output` and `conversation_id`. If the runner failed, it has no `output`, `error` says why, and there's nothing to score.
- `judges`, when given, names judges to score with instead of the case's own, as in a comparison. Build each one from the class of the case's judge with that name.
- `judge_args` is `--judge-args`, keyed by judge name.
- `trace` is the case's agent trace, if an earlier judge phase saved one.

**Agent traces.** Without a `trace`, the judges may fetch the agent run's trace, looking it up by `conversation_id`, the dataset's `agent` and when the case ran (`started_at` and `ended_at`, RFC 3339). Give every judge the same trace, and return it as `"trace"`, with the LLM usage it records as `"trace_metrics"` (a Metrics). eac saves it under `traces/` in the run and sends it back as `trace` when the run is judged again. Its metrics replace the ones `case.execute` returned. A failed fetch should only warn, since judges can run without a trace.
**Agent traces.** Without a `trace`, the judges may fetch the agent run's trace, looking it up by the case's `conversation_id`, the dataset's `agent` and when the case ran (`started_at` and `ended_at`, RFC 3339). Give every judge the same trace, and return it as `"trace"`, with the LLM usage it records as `"trace_metrics"` (a Metrics). eac saves it under `traces/` in the run and sends it back as `trace` when the run is judged again. Its metrics replace the ones `case.run` returned. A failed fetch should only warn, since judges can run without a trace.

### `online.fetch`
### `online.collect`

Params: `{"dataset", "since", "until", "limit", "args"}`.

Returns `{"records": [Record]}`, the production records from the window between `since` and `until` (both RFC 3339 times), at most `limit` of them.
Returns `{"cases": [Case]}`, the production runs from the window between `since` and `until` (both RFC 3339 times), at most `limit` of them. Each case has its `output`, and its `conversation_id` if it has one.

### `online.judge`

Params: `{"dataset", "record", "judges", "judge_args"?, "trace"?, "agent"?}`.
Params: `{"dataset", "case", "judges", "judge_args"?, "trace"?, "agent"?}`.

Scores the record with the named online judges and returns `{"scores": [Score]}`. The names are the ones in the DatasetRef, and `judge_args` is keyed by them. Agent traces work as in `case.judge`, looked up by the record's `conversation_id`, and records have no run times.
Scores a collected case, with its `output` and `conversation_id`, with the named online judges and returns `{"scores": [Score]}`. The names are the ones in the DatasetRef, and `judge_args` is keyed by them. Agent traces work as in `case.judge`, and collected cases have no run times.

### `credentials.check` / `credentials.login`

Expand Down
Loading
Loading