diff --git a/packages/yugos/src/yugos/inspect_engine/measure.py b/packages/yugos/src/yugos/inspect_engine/measure.py index 0ce2519..d8fa493 100644 --- a/packages/yugos/src/yugos/inspect_engine/measure.py +++ b/packages/yugos/src/yugos/inspect_engine/measure.py @@ -26,6 +26,8 @@ # Limits that are Yugos deadlines rather than task rules; hitting one is a non-answer. _DEADLINE_LIMITS = frozenset({"time", "working", "cost"}) +# Task rules an agent can exhaust itself; stopped mid tool loop by one, it never answered. +_TASK_LIMITS = frozenset({"message", "token", "turn"}) # Text values Inspect's `value_to_float` converts; any other text is a malformed score. _SENTINELS = frozenset({CORRECT, INCORRECT, PARTIAL, NOANSWER}) _BOOLEAN_TEXT = frozenset({"yes", "no", "true", "false"}) @@ -118,12 +120,13 @@ def _finite(text: str) -> bool: def _unscored_grade( - score: Score, grader: str, *, truncated: bool, router_failed: bool + score: Score, grader: str, *, truncated: bool, unfinished: bool, router_failed: bool ) -> GradingResult | None: """The Yugos grade for a sample the scorer left unscored, as legacy grading gates it. - A router non-answer decides first: truncation is a settled zero and a - router failure or deadline has no grade. Otherwise the grader could not + A router non-answer decides first: truncation is a settled zero, a task limit + reached mid tool loop is incorrect, and a router failure or deadline has + no grade. Otherwise the grader could not establish a grade (invalid reference, grader error, unusable judgment, unknown completion status), which needs review and leaves the category incomplete. @@ -135,6 +138,13 @@ def _unscored_grade( return GradingResult( score=0.0, grader=grader, code=GradeCode.TRUNCATED, status="skipped", details=details ) + if unfinished: + return GradingResult( + score=0.0, + grader=grader, + code=GradeCode.INCORRECT, + details={**details, "cause": "task_limit_mid_tool_loop"}, + ) if router_failed: return None return GradingResult( @@ -224,6 +234,9 @@ def measure_log( score, grader, truncated=finish == "length", + unfinished=finish == "tool_calls" + and sample.limit is not None + and sample.limit.type in _TASK_LIMITS, router_failed=deadline, ) value = 0.0 diff --git a/packages/yugos/tests/test_inspect_measure.py b/packages/yugos/tests/test_inspect_measure.py index d26f919..1b7c006 100644 --- a/packages/yugos/tests/test_inspect_measure.py +++ b/packages/yugos/tests/test_inspect_measure.py @@ -5,7 +5,7 @@ pytest.importorskip("inspect_ai") -from inspect_ai.log import read_eval_log # noqa: E402 +from inspect_ai.log import EvalSampleLimit, read_eval_log # noqa: E402 from inspect_ai.scorer import Score # noqa: E402 from inspect_fakes import ScriptedRouter, exact_question, pack_task, reply, run # noqa: E402 @@ -297,6 +297,26 @@ def test_an_unscored_truncated_answer_is_the_routers_settled_zero(tmp_path): assert chat.execution_complete and chat.grades == {"q": Decimal(0)} +@pytest.mark.parametrize( + "limit,code,status", + [("message", "incorrect", "graded"), ("operator", "needs_review", "unavailable")], +) +def test_a_task_limit_mid_tool_loop_is_incorrect(tmp_path, limit, code, status): + # Catches an agent that spends its own message budget on tool calls voiding the run. + question = exact_question("q", "Paris") + router = ScriptedRouter({question.prompt: reply("", finish_reason="tool_calls")}) + log = rescored( + run(pack_task([question], name="pack"), router, tmp_path), + Score.unscored(reason="scoring_failed"), + ) + reached = EvalSampleLimit(type=limit, limit=20) + log = log.model_copy( + update={"samples": [s.model_copy(update={"limit": reached}) for s in log.samples]} + ) + [row] = measure_log(log, router.receipts.receipts()) + assert (row.grade.code, row.grade.status, row.grade.score) == (code, status, 0.0) + + @pytest.mark.parametrize( "score,key,match", [