Skip to content
Closed
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
19 changes: 16 additions & 3 deletions packages/yugos/src/yugos/inspect_engine/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down Expand Up @@ -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.
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion packages/yugos/tests/test_inspect_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
[
Expand Down