diff --git a/README.md b/README.md index 40cf97f..de71484 100644 --- a/README.md +++ b/README.md @@ -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"])} @@ -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", "") diff --git a/docs/app/cases-and-runners/page.mdx b/docs/app/cases-and-runners/page.mdx index 501b46a..164f11d 100644 --- a/docs/app/cases-and-runners/page.mdx +++ b/docs/app/cases-and-runners/page.mdx @@ -39,7 +39,7 @@ OFFLINE_CASES = [ -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: @@ -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) ``` @@ -82,9 +81,8 @@ class OfflineTriageRunner(OfflineRunner): -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. diff --git a/docs/app/introduction/page.mdx b/docs/app/introduction/page.mdx index 9309619..66f46a0 100644 --- a/docs/app/introduction/page.mdx +++ b/docs/app/introduction/page.mdx @@ -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"])} @@ -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", "") diff --git a/docs/app/judges/page.mdx b/docs/app/judges/page.mdx index 017783c..6c65a48 100644 --- a/docs/app/judges/page.mdx +++ b/docs/app/judges/page.mdx @@ -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: @@ -38,7 +37,7 @@ class FoundIssueJudge(Judge): -`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. @@ -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: diff --git a/docs/app/seeds/page.mdx b/docs/app/seeds/page.mdx index e462cdd..0b65e1a 100644 --- a/docs/app/seeds/page.mdx +++ b/docs/app/seeds/page.mdx @@ -46,7 +46,7 @@ class Incident(Seed): -`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 diff --git a/examples/sentry-assistant-python/evals/triage/judges/found_cause_judge.py b/examples/sentry-assistant-python/evals/triage/judges/found_cause_judge.py index 5b57abb..508e33e 100644 --- a/examples/sentry-assistant-python/evals/triage/judges/found_cause_judge.py +++ b/examples/sentry-assistant-python/evals/triage/judges/found_cause_judge.py @@ -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"] diff --git a/examples/sentry-assistant-python/evals/triage/judges/found_issue_judge.py b/examples/sentry-assistant-python/evals/triage/judges/found_issue_judge.py index f172dc2..54dd7e9 100644 --- a/examples/sentry-assistant-python/evals/triage/judges/found_issue_judge.py +++ b/examples/sentry-assistant-python/evals/triage/judges/found_issue_judge.py @@ -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: diff --git a/examples/sentry-assistant-python/evals/triage/judges/triage_llm_judge.py b/examples/sentry-assistant-python/evals/triage/judges/triage_llm_judge.py index 363ec45..5f74c41 100644 --- a/examples/sentry-assistant-python/evals/triage/judges/triage_llm_judge.py +++ b/examples/sentry-assistant-python/evals/triage/judges/triage_llm_judge.py @@ -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: diff --git a/examples/sentry-assistant-python/evals/triage/runners/offline.py b/examples/sentry-assistant-python/evals/triage/runners/offline.py index 02f84c7..77eeed5 100644 --- a/examples/sentry-assistant-python/evals/triage/runners/offline.py +++ b/examples/sentry-assistant-python/evals/triage/runners/offline.py @@ -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)) diff --git a/sdks/python/README.md b/sdks/python/README.md index b3760c3..b2d3906 100644 --- a/sdks/python/README.md +++ b/sdks/python/README.md @@ -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 @@ -122,7 +124,6 @@ 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") @@ -130,8 +131,7 @@ class ChatRunner(OfflineRunner): 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, @@ -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") @@ -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. @@ -231,7 +227,6 @@ class UsedTheRightTool(SentryJudge): self, case: Case, *, - seed_results: dict[str, dict[str, Any]], agent_trace: Any = None, ) -> Score | None: ... diff --git a/sdks/python/eac/judge/judge.py b/sdks/python/eac/judge/judge.py index 623b9d4..5c1a0eb 100644 --- a/sdks/python/eac/judge/judge.py +++ b/sdks/python/eac/judge/judge.py @@ -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: diff --git a/sdks/python/eac/models.py b/sdks/python/eac/models.py index cbe9cc1..9ddf2eb 100644 --- a/sdks/python/eac/models.py +++ b/sdks/python/eac/models.py @@ -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. diff --git a/sdks/python/eac/runner/offline_runner.py b/sdks/python/eac/runner/offline_runner.py index 5a01a7c..d48315d 100644 --- a/sdks/python/eac/runner/offline_runner.py +++ b/sdks/python/eac/runner/offline_runner.py @@ -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. """ diff --git a/sdks/python/eac/worker.py b/sdks/python/eac/worker.py index 4bee89d..29748a8 100644 --- a/sdks/python/eac/worker.py +++ b/sdks/python/eac/worker.py @@ -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: @@ -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] @@ -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):