Skip to content

feat(labbench2_vlm_agent): embed the task's media in agent sessions - #5704

Draft
yaoyu-33 wants to merge 34 commits into
mainfrom
yuya/labbench2-vlm-agent-context
Draft

yaoyu-33 wants to merge 34 commits into
mainfrom
yuya/labbench2-vlm-agent-context

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #5703; review the labbench2_vlm_agent commits (feat(labbench2_vlm_agent): embed the task's media in agent sessions, refactor(labbench2_vlm_agent): embed session media in the session's episode, not responses() fix(labbench2_vlm_agent): require the task's tag and pin session parity with /run feat(labbench2_vlm): run the shipped configs in agent sessions and feat(labbench2_vlm): write agent_context keyed by the agent role). The other commits are #5703's and merges.

What and why

labbench2_vlm_agent embeds each task's images and PDFs in run(), from verifier_metadata.media_dir. It inherits Simple Agent's agent sessions, but an agent session never reaches run(), so under single_agent_turn the model was asked about images it never saw.

With the agent-context contract from #5703:

  • Context. The agent declares agent_context_model: media, the task's media directory (a required artifact), and tag (required: without it a protocolqa2 row would go to the model as images in text mode). prepare_data.py writes agent_context = {"agent": {"values": {"tag": ...}, "artifacts": {"media": {"path": <media_dir>}}}} into every row, keyed by single_agent_turn's one role, agent, and the committed example.jsonl rows carry it. Nothing else in those rows changed.

  • Seed. _new_session_state resolves the media directory under media_base_dir. That also covers a checkpoint restore, which rebuilds sessions through the same method. A row without agent_context or values.tag, or a missing media directory, is refused with a terminal 422, so a session never runs without its images. media_base_dir must be the real directory: a media root that is a symlink to other storage resolves outside it and is refused (the READMEs give an example).

  • Activation. _create_session_episode, the Simple Agent hook from feat(agents): deliver per-task agent context to agent sessions #5703, embeds the media with the configured dpi and media_mode (text only for protocolqa2 tags, as before) through the same embed_media_into_row that run() uses. The agent does not override responses(), so environment validation still infers custom-gym-verifier, the profile the benchmark manifest declares. Overriding responses() in the first version failed test_infers_representative_builtin_agent_profiles[labbench2_vlm_agent-custom-gym-verifier].

  • Observations. With strip_images_from_output on, the session's trajectory, and so its observations and ng_trajectory, lose the base64 images and gain a multimodal_history_redacted gap. Model-call capture still keeps the original request, as on /run.

  • Shipped configs. resources_servers/labbench2_vlm/configs/labbench2_vlm.yaml and benchmarks/labbench2_vlm/config.yaml now put single_agent_turn_legacy in front of the agent instead of the legacy_agent relay, so their episodes run in agent sessions. A row prepared before agent_context existed, including the v0.0.1 validation JSONL behind gitlab_identifier, is refused at the seed with 422; prepare_data.py, which these rows need anyway for their media, writes the key. The README says so.

The legacy /run path is unchanged.

#5703 now keys a row's agent_context by participant role, so prepare_data.py and the example rows write the context under agent. A row in the earlier unkeyed shape is refused with 422 at the task input, before the agent is seeded.

#5695, which refused agent sessions in this agent until media delivery existed, is closed in favor of this PR.

No public issue: this is the media-delivery migration of one agent onto the contract in #5703.

Validation

Primary venv with the worktree on the path, Python 3.13, pymupdf added from a scratch directory:

  • responses_api_agents/labbench2_vlm_agent/tests and resources_servers/labbench2_vlm/tests: 46 passed. New session tests check that:
    • the task's image reaches the model as an input_image block before the question;
    • the session's observations carry no image and record the multimodal_history_redacted gap;
    • a seed without agent_context, or with a missing media directory, is refused with 422 before any model call.
  • With feat(agents): deliver per-task agent context to agent sessions #5703's app.py in place of this one, the three new session tests fail.
  • pre-commit run --files <changed files>: passed.

At 4c102b133 (#5703's updated branch and main 379ae226d merged, after a review round): labbench2_vlm_agent + labbench2_vlm tests: 50 passed; test_session_contract_repo.py + test_global_config.py: 233 passed; pre-commit run --files: clean. A new test checks that /run and a session send byte-identical model requests for the committed rows, protocolqa2 in text and image mode and figqa2-img in text mode, so CI now covers the parity the smoke below showed; forcing image mode in the session, or defaulting the tag, makes it fail.

At 7c0c1528b (#5703 at ccd50dc04 and main 099832fa7 merged, configs switched), on a Linux workstation with Python 3.13.14: labbench2_vlm_agent and labbench2_vlm tests, test_session_contract_repo.py, tests/unit_tests/config, test_environment_validation.py, test_add_legacy_agent_environment_servers.py, test_harness_conformance_ci.py and both test_agent_context.py: 654 passed. gym env validate on labbench2_vlm.yaml with its judge config, and on benchmarks/labbench2_vlm/config.yaml: valid. pre-commit run --files <changed files>: clean.

At 4cb76a685 (role-keyed rows; #5703 at 79b7c92c1 merged), on a Linux workstation with Python 3.13.14: labbench2_vlm_agent and labbench2_vlm tests, single_agent_turn and single_agent_turn_legacy tests, and tests/unit_tests/server_runtime/test_agent_context.py: 378 passed. The session-parity test now takes the seed context from the committed rows through SingleAgentTurnTaskInput, as an episode does. TestRepoDataMatchesSchemas: passed. pre-commit run --files <changed files>: clean.

At 577952026: #5703 at 12eb72992 merged (main f636596db, documentation only); no conflicts.

Left: files under the media directory are read by embed_media_into_row, shared with /run, without a per-file check that they stay under it; the directory is operator-configured, so this is not reachable from a row.

Rollout evidence

Scripted-model smoke (no real model). Real servers from gym env start (openai_model for policy and judge, both pointed at a local stub), then gym eval run --no-serve on two committed example rows: one figqa2-img (a PNG) and one protocolqa2 (a PDF rendered to page images). The same rows ran twice: through a scratch copy of the config that puts single_agent_turn_legacy in front of the agent, and through the shipped legacy_agent relay.

Path Policy requests (images, text blocks) Judge calls Rollout rows Images in rows
Agent session (single_agent_turn_legacy) figure: 1 + 1; protocol: 3 + 1 2 2, no failures none
Legacy /run (legacy_agent) figure: 1 + 1; protocol: 3 + 1 2 2, no failures none

For each task, the policy request had the same SHA-256 on both paths, images included, and so did each judge request. The reward of 1.0 is the stub judge's fixed [[A=B]], not a score.

Real-model smoke (2026-11-09, at 7c0c1528b). On a Linux workstation: gym env start with the shipped labbench2_vlm.yaml, hosted nvidia/nemotron-3.5-super-vl-120b-a12b (through vllm_model, thinking off) as both policy and judge, and model-call capture on; then gym eval run --no-serve on the committed example rows at temperature 0. Each row ran twice: through the shipped config, an agent session (/v1/agent_sessions on the agent, 4 times), and through a run config that puts the legacy_agent relay back (the agent's /run, 4 times, no sessions).

Row Media sent Policy request, session vs /run Input tokens Reward /run / session
protocolqa2 3 page images + question same SHA-256 8236 0.0 / 0.0
protocolqa2 1 page image + question same SHA-256 2785 0.0 / 0.0
figqa2-img 1 image + question same SHA-256 3303 0.0 / 1.0
tableqa2-img 1 image + question same SHA-256 1911 0.0 / 0.0
  • Both runs are healthy: no failed or masked rows, and no images in the saved rows.
  • The hosted model is not deterministic at temperature 0 (output lengths differ between runs of the same request), so per-row rewards are not expected to match; the evidence is the identical requests. An earlier pass without temperature 0 gave figqa2-img 1.0 on /run and 0.0 in the session.
  • In that earlier pass with all five example rows, the provider's content screening rejected the figqa2-pdf row (31 page images) with HTTP 422, from the same request on both paths. On /run the agent answered 500 and the collection stopped. In the session, Simple Agent returned the classified model_request_error (422), and single_agent_turn's default outcome policy (400, 413 and 422 are verified) scored it 0. The tables above leave that row out.

Real-model smoke with role-keyed rows (2026-11-09, at 4cb76a685). The same setup and rows, now written as {"agent": {...}}, through the shipped config only (4 agent sessions, no failed or masked rows, no images in saved rows).

Row Policy request vs the 7c0c1528b session run Input tokens Reward
protocolqa2 same SHA-256 8236 0.0
protocolqa2 same SHA-256 2785 0.0
figqa2-img same SHA-256 3303 1.0
tableqa2-img same SHA-256 1911 0.0

One row in the unkeyed shape ran through the same config as a check: the Environment Server refused it with 422 at task.task_input.agent_context before seeding the agent, no model call was made, and the failures file carries the message naming the agent role.

🤖 Generated with Claude Code

yaoyu-33 and others added 4 commits November 5, 2026 14:23
An agent session gets its initial model input and its grants, but no task
data. Harnesses that build part of their input from the task row, such as
gdp_pdf_agent's document manifest, labbench2_vlm_agent's media directory
and CritPt's formatting prompt, had no supported way to receive it under
single_agent_turn.

A task row now carries that data in a reserved agent_context key: small
inline values (at most 64 KiB) and artifact references, paths relative to
a root the agent configures. SingleAgentTurnTaskInput lifts it out of
task_data, so the Resources Server never receives it, and single_agent_turn
passes it in AgentSeedSessionRequest.agent_context, omitted when empty.

Each agent declares the keys it reads in agent_context_model. The base
seed refuses with a terminal 422 a context the agent declares no model
for, an undeclared key, a missing required key or a mistyped value, so a
task never runs without data it was given. Agents read the typed context
with parse_agent_context() and resolve artifacts with
resolve_agent_context_artifact(), which refuses paths that leave the root.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…idation

A server's TaskData schema validates the task-owned fields of a row and reports unknown keys. agent_context goes to the agent session, never to the Resources Server, so it joins RESERVED_ROW_KEYS instead of showing up as an unknown task field.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
labbench2_vlm_agent embeds a task's images and PDFs in run(). Under an
agent session that never ran, so the model answered without the media.

The agent now declares its agent_context: artifacts.media, the task's
media directory (required), and values.tag. It resolves the directory
under media_base_dir when the session is seeded, also when a checkpoint
restore rebuilds the session, and embeds the media in responses() with
the configured dpi and media_mode. A session whose row has no
agent_context, or whose media directory is missing, is refused with a
terminal 422. With strip_images_from_output on, the images are removed
from the session's trajectory and observations and replaced by a
multimodal_history_redacted gap.

prepare_data.py writes agent_context into every row, and the committed
example rows carry it. The legacy /run path is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33 yaoyu-33 added feature New capabilities, enhancements, or enablement work area:agent Agent harnesses and Responses API agent behavior labels Nov 5, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e5dc10f

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

yaoyu-33 and others added 3 commits November 5, 2026 14:48
…tate

An agent whose task context lives in its session state, such as a
document or media to put in the model request, had to override
responses() to reach that state from the episode it creates. Environment
validation then infers custom-gym-agent-loop for it, though the agent loop
is still Simple Agent's.

responses() now creates a session activation's episode through
_create_session_episode(state, body, **kwargs), which by default calls
_create_episode. A subclass overrides it to use the session's context and
leaves responses() and the agent loop alone. The sessionless path is
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…pisode, not responses()

Overriding responses() made environment validation infer the
custom-gym-agent-loop profile, though the agent loop is still Simple
Agent's and the manifest declares custom-gym-verifier. The media is now
embedded in _create_session_episode, which also strips the images from
the session's trajectory, so responses() stays Simple Agent's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test be18505

yaoyu-33 and others added 8 commits November 6, 2026 11:14
…erifier

- Refuse an artifact path with a NUL byte at validation, and turn a path the filesystem cannot look up (name
  too long, no permission) into a 422 seed refusal instead of a 500; other OS errors stay retryable.
- Count the 64 KiB values limit in UTF-8 bytes, not ASCII-escaped JSON.
- Treat an empty agent_context as none in the task input and the seed, so the seed and task digest match a row
  without the key and an agent server that predates the key still accepts the seed.
- Skip a task_data container's agent_context in dataset validation, as the task input lifts it out.
- single_agent_turn_legacy: answer a row that fails the episode request model with the typed /run's 422.
- Re-verification no longer sends a stored agent_context to the Resources Server's /verify.
- Docs and helper docstring: a Simple Agent subclass resolves context in _new_session_state (restores rebuild
  through it) and overrides _create_session_episode, never responses(); configure the real directory as the
  root; files under a directory artifact are the agent's to confine.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…ty with /run

- Make values.tag required in the agent context: it picks extracted text or page images for protocolqa2 under
  media_mode=text, so a row without it is refused at seed instead of reaching the model with another prompt.
- Test that an agent session sends the model the same request as /run for the committed protocolqa2 and
  figqa2 rows, in text and image mode.
- READMEs: point media_base_dir at the real directory the media paths are relative to when the media lives on
  other storage behind a symlink; a session refuses a media directory that resolves outside it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

yaoyu-33 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 4c102b1

yaoyu-33 and others added 4 commits November 9, 2026 18:08
…o yuya/labbench2-vlm-agent-context

Signed-off-by: yaoyu-33 <[email protected]>
The environment servers move from the legacy_agent relay to
single_agent_turn_legacy, so each episode runs the agent in an agent
session that embeds the media named by the row's agent_context. A row
prepared before agent_context existed, such as the v0.0.1 validation
JSONL, is refused at the seed with HTTP 422; prepare_data.py writes the
key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 7c0c152

yaoyu-33 and others added 7 commits November 9, 2026 20:22
AgentContext is held by the stored seed, which is compared on every retry;
freeze it as AgentContextArtifact already is. A root the agent configured
but that does not exist now says so, instead of reporting each artifact as
missing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
An episode can seed several agents, so a flat context cannot say which agent a key is for.
A row's agent_context now maps each participant role to the AgentContext that role's session
receives. single_agent_turn has one role, `agent`, and refuses any other role, including the
unkeyed shape, with a 422 at the task input. The seed contract and parse_agent_context are
unchanged, and the 64 KiB limit applies to each role's context.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
A row's agent_context now maps each participant role to its context, and single_agent_turn's one
role is `agent`. prepare_data.py and the example rows wrap the media and tag under it, and the
session test takes the seed context through SingleAgentTurnTaskInput as an episode does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: yaoyu-33 <[email protected]>
…ent-context

Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…o yuya/agent-context-sessions

Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ent-context

Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 4cb76a6

yaoyu-33 and others added 2 commits November 9, 2026 21:08
…ent-context

Signed-off-by: yaoyu-33 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@yaoyu-33

Copy link
Copy Markdown
Contributor Author

/ok to test 5779520

This branch was previously deployed

1 inactive deployment
public — 57795202 Deployed Nov 10, 2026 by copy-pr-bot[bot] via release / finalize / notify #11308
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior feature New capabilities, enhancements, or enablement work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant