Skip to content

Commit 9dd447e

Browse files
denismegerleDenis Megerle
andauthored
[tool] fix: handle empty image inputs in ToolAgentLoop (#5420)
### What does this PR do? > Fixes a compatibility issue in `ToolAgentLoop`, downstream image-processing pipelines require passing passing `images=None` (instead of an empty list) when a tool call returns no new images. ### Checklist Before Starting - [x] Search for similar PRs. Paste at least one query link here: https://github.com/verl-project/verl/pulls?q=is%3Apr+ToolAgentLoop+images+None - [x] Format the PR title as `[{modules}] {type}: {description}` (This will be checked by the CI) - `{modules}` include `fsdp`, `megatron`, `veomni`, `sglang`, `vllm`, `rollout`, `trainer`, `ci`, `training_utils`, `recipe`, `hardware`, `deployment`, `ray`, `worker`, `single_controller`, `misc`, `perf`, `model`, `algo`, `env`, `tool`, `ckpt`, `doc`, `data`, `cfg`, `reward` - If this PR involves multiple modules, separate them with `,` like `[megatron, fsdp, doc]` - `{type}` is in `feat`, `fix`, `refactor`, `chore`, `test` - If this PR breaks any API (CLI arguments, config, function signature, etc.), add `[BREAKING]` to the beginning of the title. - Example: `[BREAKING][fsdp, megatron] feat: dynamic batching` ### Test > Not covered by an existing upstream test in this PR. Change is a narrow input-normalization to `apply_chat_template(images=...)` when no images are produced. ### API and Usage Example > No API change. ```python # No API changes. Behavior change: images passed to chat template is None when empty. ``` ### Design & Code Changes > - In `verl/experimental/agent_loop/tool_agent_loop.py`, normalize `images` to `None` when `new_images_this_turn` is empty. ### Checklist Before Submitting > [!IMPORTANT] > Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review. - [x] Read the [Contribute Guide](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md). - [x] Apply [pre-commit checks](https://github.com/volcengine/verl/blob/main/CONTRIBUTING.md#code-linting-and-formatting): `pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=always` - [x] (not required) Add / Update [the documentation](https://github.com/volcengine/verl/tree/main/docs). - [x] (not required) Add unit or end-to-end test(s) to [the CI workflow](https://github.com/volcengine/verl/tree/main/.github/workflows) to cover all the code. If not feasible, explain why: not feasible quickly here because current agent-loop tests stub the tokenizer and don't assert image/video kwargs flow; can be added if maintainers want it. - [ ] Once your PR is ready for CI, send a message in [the `ci-request` channel](https://verl-project.slack.com/archives/C091TCESWB1) in [the `verl` Slack workspace](https://join.slack.com/t/verl-project/shared_invite/zt-3855yhg8g-CTkqXu~hKojPCmo7k_yXTQ). (If not accessible, please try [the Feishu group (飞书群)](https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=772jd4f1-cd91-441e-a820-498c6614126a).) - [x] (not related) If your PR is related to the `recipe` submodule, please also update the reference to the submodule commit via `git submodule update --remote` or `cd recipe && git pull origin main`. Co-authored-by: Denis Megerle <denis.megerle@deepl.com>
1 parent 32705dc commit 9dd447e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

verl/experimental/agent_loop/tool_agent_loop.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,14 @@ async def _handle_processing_tools_state(self, agent_data: AgentData) -> AgentSt
353353
None, lambda: self.tokenizer.encode(tool_response_text, add_special_tokens=False)
354354
)
355355
else:
356+
# Note that we have to pass None to the images and videos if there are no new images / videos
357+
# to stay compatible with downstream image processing logic!
358+
images = new_images_this_turn if new_images_this_turn else None
359+
videos = None
356360
response_ids = await self.apply_chat_template(
357361
add_messages,
358-
images=new_images_this_turn, # Using local variable
359-
videos=None,
362+
images=images,
363+
videos=videos,
360364
remove_system_prompt=True,
361365
)
362366

0 commit comments

Comments
 (0)