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
8 changes: 8 additions & 0 deletions src/agent_env/config/model_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ def takes(route: ModelRoute, param: str) -> bool:
return param in (supported or ())


def context_overflow(exc: BaseException) -> bool:
import litellm

return isinstance(exc, litellm.ContextWindowExceededError) or (
isinstance(exc, litellm.BadRequestError) and "maximum context length" in str(exc).lower()
)


def refused_setting(exc: BaseException) -> bool:
"""Whether ``exc`` is LiteLLM refusing a param's value for the model before sending the call, as GPT-5 refuses
``reasoning_effort="xhigh"``: the call wasn't made, so nothing was spent."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
TrajectoryText,
compact_otel_trajectory,
final_image_frames,
strip_base64_images,
strip_trajectory_images,
)

Expand Down Expand Up @@ -1238,6 +1239,8 @@ async def judge_agent() -> _JudgeAgent:
trajectory_inline = await asyncio.to_thread(self._read_trajectory_text, compacted.container_object_url)
if trajectory_content is not None:
trajectory_inline = trajectory_content
if not use_agent_judge and trajectory_inline is not None and overrides.get("apply_trajectory_filter") is not False:
trajectory_inline = await asyncio.to_thread(strip_base64_images, trajectory_inline)

def trajectory_path_of(one: _JudgeAgent) -> Optional[str]:
if one.staged is not None:
Expand Down Expand Up @@ -1800,6 +1803,8 @@ async def _prompt_llm_judge(
last_exc = exc
if judge is not None:
_record_failed_call(judge, exc, model=model, endpoint_host=route.endpoint_host, sent=judge_input)
if model_call.context_overflow(exc):
raise
if params and model_call.refused_setting(exc):
raise JudgeSettingRefused(f"{model} refused the judge's "
f"{sorted(key for key in _JUDGE_SETTINGS if key in sent)}: {exc}") from exc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
from tst.util.config import install_model_config


@pytest.mark.asyncio
async def test_direct_judge_does_not_retry_context_overflow(monkeypatch):
import litellm

exc = litellm.BadRequestError(message="This endpoint's maximum context length is 1048576 tokens",
model='test', llm_provider='openai')
completion = AsyncMock(side_effect=exc)
monkeypatch.setattr(litellm, 'acompletion', completion)
with pytest.raises(litellm.BadRequestError, match='maximum context length'):
await _verifier()._prompt_llm_judge('test', model='openai/test', context=TaskStepContext())
completion.assert_awaited_once()


def _criteria(ids: list[str]) -> list[dict]:
return [{"id": cid, "title": f"Test {cid}"} for cid in ids]

Expand Down
20 changes: 20 additions & 0 deletions tst/unit/task_step/verifiers/test_rubrics_verifier_multiturn.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ async def test_direct_judge_multiturn_inlines_all_turns_marked(monkeypatch):
assert ctx.metadata["verifications"]["vt"]["score"] == 1.0


@pytest.mark.asyncio
@pytest.mark.parametrize("turns", [1, 2])
async def test_direct_text_judge_omits_actor_image_bytes(monkeypatch, turns):
png = 'iVBORw0KGgo' + 'A' * 4000
raw = json.dumps([{'parts': [{'file': {'bytes': png}}]},
{'message': {'content': [{'image_url': {'url': 'data:image/png;base64,' + png}}]}},
{'message': {'content': 'dealer reply'}}])
urls = [f's3://t/{i}.json' for i in range(turns)]
verifier = _verifier()
monkeypatch.setattr(verifier, '_read_trajectory_text', lambda uri: raw)
captured = _capture_judge(monkeypatch, verifier)
await verifier.execute(TaskStepContext(prompt_responses=[_pr(
target_agent_per_turn_trajectory_object_urls=urls, agent_trajectory_object_url=urls[-1],
)]))
prompt = captured['eval_prompt']
assert png not in prompt and 'data:image' not in prompt
assert prompt.count('<image omitted>') == 2 * turns
assert prompt.count('dealer reply') == turns


# --- _merge_per_turn_text logic ----------------------------------------------

def test_merge_per_turn_text_default_filter_compacts_each_turn(monkeypatch):
Expand Down