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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class ChatRunner(OfflineRunner):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
conversation_id: str,
) -> dict[str, Any]:
return {"response": reply(case.input["query"])}
Expand All @@ -58,7 +57,6 @@ class Greets(Judge):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
response = case.run_results.get("response", "")
Expand Down
8 changes: 3 additions & 5 deletions docs/app/cases-and-runners/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ OFFLINE_CASES = [

</LanguageCode>

A case also has `run_results`, which is what your system returned. eac fills them in after your runner runs, so your judges can read them.
A case also has `run_results`, which is what your system returned, and `seed_results`, what each of its seeds' `setup()` returned, by seed name. eac fills in `seed_results` before your runner runs and `run_results` after, so your runner and judges can read them.

A few other options you might want:

Expand Down Expand Up @@ -70,10 +70,9 @@ class OfflineTriageRunner(OfflineRunner):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
conversation_id: str,
) -> dict[str, Any]:
alert = case.input["alert"].format(release=seed_results["incident"]["release"])
alert = case.input["alert"].format(release=case.seed_results["incident"]["release"])
model = self.args.get("model", DEFAULT_MODEL)
return triage(alert, conversation_id=conversation_id, model=model)
```
Expand All @@ -82,9 +81,8 @@ class OfflineTriageRunner(OfflineRunner):

</LanguageCode>

Return plain JSON and leave the scoring to your judges. Along with the case, you get:
Return plain JSON and leave the scoring to your judges. Here the seed made a new release, so the runner reads it from `case.seed_results` and puts it in the alert. Along with the case, you get:

- `seed_results`, what each seed's `setup()` returned, by seed name. Here the seed made a new release, so the runner puts it in the alert.
- `conversation_id` to tag your agent's run, so judges can find its trace later.
- `self.args`, whatever was passed with `--args`, as a plain dict. eac doesn't check it, so check anything you rely on.

Expand Down
2 changes: 0 additions & 2 deletions docs/app/introduction/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class ChatRunner(OfflineRunner):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
conversation_id: str,
) -> dict[str, Any]:
return {"response": reply(case.input["query"])}
Expand All @@ -132,7 +131,6 @@ class Greets(Judge):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
ok = "hello" in case.run_results.get("response", "")
Expand Down
6 changes: 2 additions & 4 deletions docs/app/judges/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ class FoundIssueJudge(Judge):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
error = case.expected_output["error"]
expected = seed_results["incident"]["issues"][error] if error else None
expected = case.seed_results["incident"]["issues"][error] if error else None
actual = case.run_results.get("issue")

if actual == expected:
Expand All @@ -38,7 +37,7 @@ class FoundIssueJudge(Judge):

</LanguageCode>

`seed_results` holds what the case's seeds set up, by name, the same as the runner got. This judge needs them because the issue's ID only exists once the seed has created it.
`case.seed_results` holds what the case's seeds set up, by name, the same as the runner saw. This judge needs them because the issue's ID only exists once the seed has created it.

If the judge doesn't apply to a case, return `None`. A score of `None` is saved but doesn't count toward pass or fail. If a judge throws, its score records the error instead, and the case errors.

Expand Down Expand Up @@ -86,7 +85,6 @@ An LLM judge asks a model to grade the trace. This one asks two true-or-false qu
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
if agent_trace is None:
Expand Down
2 changes: 1 addition & 1 deletion docs/app/seeds/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Incident(Seed):

</LanguageCode>

`setup()` returns the seed's **results**: plain JSON, like IDs and URLs, that says what it made. Attach the seed with `Case(seeds=[Incident()])`, then read its results in your runner and judges as `seed_results["incident"]`. `cleanup()` gets the same results back.
`setup()` returns the seed's **results**: plain JSON, like IDs and URLs, that says what it made. Attach the seed with `Case(seeds=[Incident()])`, then read its results in your runner and judges as `case.seed_results["incident"]`. `cleanup()` gets the same results back.

## Caching

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def judge(
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
expected = case.expected_output["function"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ def judge(
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
error = case.expected_output["error"]

expected = seed_results["incident"]["issues"][error] if error else None
expected = case.seed_results["incident"]["issues"][error] if error else None
actual = case.run_results.get("issue")

if actual == expected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def judge(
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
if agent_trace is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def run_case(
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
conversation_id: str,
) -> dict[str, Any]:
alert = case.input["alert"].format(release=seed_results["incident"]["release"])
alert = case.input["alert"].format(release=case.seed_results["incident"]["release"])
return triage(alert, conversation_id=conversation_id, model=self.args.get("model", DEFAULT_MODEL))
11 changes: 3 additions & 8 deletions sdks/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ CASES = [
- `run_results` and `conversation_id` are what the system produced. eac sets
them to what the runner returned before judging, and an online runner sets
them on the cases it collects.
- `seed_results` maps each of the case's seed names to what its `setup()`
returned. eac sets it before running and judging. It's empty online.
- `enabled=False` leaves a case out unless it's picked by name or split.
- `seeds` lists the fixtures the case needs. See [Seeds](#seeds).
- `cache=False` sets the case's seeds up fresh and tears them down after the
Expand All @@ -122,16 +124,14 @@ class ChatRunner(OfflineRunner):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
conversation_id: str,
) -> dict[str, Any]:
model = self.args.get("model", "small")
reply = my_chatbot(case.input["query"], model=model, tag=conversation_id)
return {"response": reply}
```

- `seed_results` maps each of the case's seed names to what its `setup()`
returned.
- Read what the case's seeds set up from `case.seed_results`.
- Tag your agent's run with `conversation_id`, so a judge's
`get_agent_trace()` can find the trace.
- `self.args` is the run's `--args`, as a plain dict. eac doesn't check them,
Expand All @@ -156,7 +156,6 @@ class Matches(Judge):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
expected = case.expected_output.get("response")
Expand All @@ -176,15 +175,12 @@ class CalledTool(Judge):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
ok = self.tool in (case.run_results.get("tool_calls") or [])
return Score(name=self.name, score=1.0 if ok else 0.0)
```

- `seed_results` maps each of the case's seed names to what its `setup()`
returned.
- `agent_trace` is the case's agent trace, from a judge's
`get_agent_trace()`, or `None`.
- Return `None` when the judge doesn't apply to the case.
Expand Down Expand Up @@ -231,7 +227,6 @@ class UsedTheRightTool(SentryJudge):
self,
case: Case,
*,
seed_results: dict[str, dict[str, Any]],
agent_trace: Any = None,
) -> Score | None:
...
Expand Down
8 changes: 3 additions & 5 deletions sdks/python/eac/judge/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ class Judge(ABC):
credentials: Sequence[Credential] = ()

@abstractmethod
def judge(self, case: Case, *, seed_results: dict[str, dict[str, Any]], agent_trace: Any = None) -> Score | None:
def judge(self, case: Case, *, agent_trace: Any = None) -> Score | None:
"""Score `case.run_results`, or return None if this judge doesn't apply to
the case, e.g. one without the expected output it compares against.

Cases whose runner raised are never judged. `seed_results` maps each
of the case's seed names to what its setup() returned, and is empty
online. `agent_trace` is the trace a judge's get_agent_trace() found,
or None.
Cases whose runner raised are never judged. `agent_trace` is the trace
a judge's get_agent_trace() found, or None.
"""

def get_agent_trace(self, run: AgentRun) -> AgentTrace | None:
Expand Down
3 changes: 3 additions & 0 deletions sdks/python/eac/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class Case:
#: The ID the agent's run was tagged with, for get_agent_trace(). Set
#: like `run_results`.
conversation_id: str | None = None
#: What each of the case's seeds' setup() returned, by seed name. eac
#: sets it before running and judging. Empty online.
seed_results: dict[str, dict[str, Any]] = field(default_factory=dict)
#: Named groups `eac --split` picks cases by.
splits: Sequence[str] = ()
#: A disabled case runs only when picked by name or by one of its splits.
Expand Down
5 changes: 2 additions & 3 deletions sdks/python/eac/runner/offline_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ class OfflineRunner(Runner):
"""

@abstractmethod
def run_case(self, case: Case, *, seed_results: dict[str, dict[str, Any]], conversation_id: str) -> dict[str, Any]:
def run_case(self, case: Case, *, conversation_id: str) -> dict[str, Any]:
"""Run the case and return its results as a JSON-serializable dict.

`seed_results` maps each of the case's seed names to what its setup()
returned. Tag the agent's run with `conversation_id`, so a judge's
Tag the agent's run with `conversation_id`, so a judge's
get_agent_trace() can find it.
"""
19 changes: 11 additions & 8 deletions sdks/python/eac/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@ def seed_teardown(self, sent: wire.Seed, seed_results: dict[str, Any]) -> dict[s
return {}

def run_case(self, params: wire.CaseRunParams) -> wire.CaseRunResult:
case = self.case(params["case"]["name"])
case = dataclasses.replace(self.case(params["case"]["name"]), seed_results=params.get("seed_results") or {})
runner = self.with_args(self.runner, params.get("args") or {})
seed_results = params.get("seed_results") or {}
run_results = _call(runner.run_case, case, seed_results=seed_results, conversation_id=params["conversation_id"])
run_results = _call(runner.run_case, case, conversation_id=params["conversation_id"])
return {"run_results": _json_dict(run_results, f"{type(runner).__name__}.run_case()")}

def collect_cases(self, params: wire.OnlineExecuteParams) -> wire.OnlineExecuteResult:
Expand Down Expand Up @@ -286,7 +285,12 @@ def judge(self, params: wire.CaseJudgeParams) -> wire.CaseJudgeResult:
if run_results is None:
return {"judge_results": []}
own = self.case(sent["name"]) if self.offline else Case(name=sent["name"], input=sent.get("input") or {})
case = dataclasses.replace(own, run_results=run_results, conversation_id=sent.get("conversation_id"))
case = dataclasses.replace(
own,
run_results=run_results,
conversation_id=sent.get("conversation_id"),
seed_results=params.get("seed_results") or {},
)
judge_args = params.get("judge_args") or {}
names = params.get("judges") or []
judges = self.judges_named(names) if names else [(judge.name, judge) for judge in case.judges]
Expand All @@ -307,17 +311,16 @@ def judge(self, params: wire.CaseJudgeParams) -> wire.CaseJudgeResult:
if fetched.metrics is not None:
result["trace_metrics"] = _wire_metrics(fetched.metrics)

seed_results = params.get("seed_results") or {}
judge_results = [_score(judge, case, seed_results, agent_trace) for _, judge in judges]
judge_results = [_score(judge, case, agent_trace) for _, judge in judges]
result["judge_results"] = [score for score in judge_results if score is not None]
return result


def _score(judge: Judge, case: Case, seed_results: dict[str, dict[str, Any]], agent_trace: Any) -> wire.Score | None:
def _score(judge: Judge, case: Case, agent_trace: Any) -> wire.Score | None:
"""The judge's score, or None if it doesn't apply. A judge that raises
gets its error instead of a score, which errors the case."""
try:
score = _call(judge.judge, case, seed_results=seed_results, agent_trace=agent_trace)
score = _call(judge.judge, case, agent_trace=agent_trace)
if score is None:
return None
if not isinstance(score, Score):
Expand Down
Loading