[tool] fix: forward extra_fields through ToolAgentLoop output#5515
[tool] fix: forward extra_fields through ToolAgentLoop output#5515cavities12 wants to merge 1 commit intoverl-project:mainfrom
Conversation
ToolAgentLoop.run() constructs AgentLoopOutput with extra_fields={},
silently dropping any custom data written to agent_data.extra_fields
during tool execution (e.g. tool_history, session state).
Replace the empty dict with dict(agent_data.extra_fields) to shallow-copy
all custom fields into the output. turn_scores and tool_rewards are then
merged on top via .update(), preserving their override priority.
|
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an issue where custom data in agent_data.extra_fields was being dropped. The solution, which involves creating a shallow copy of the fields, is appropriate and prevents unintended side effects. The change is accompanied by a comprehensive new test suite that thoroughly validates the fix and covers important edge cases. The implementation is clean and the tests are well-structured. No issues were found.
|
I have fixed the issue in this PR; merging it will suffice. @wuxibin89 |
What does this PR do?
Fixes
ToolAgentLoop.run()silently dropping custom data fromagent_data.extra_fields.When tools write session data (e.g.
tool_history, browse cache state) toagent_data.extra_fieldsduringtool.execute(), this data is lost because the output is constructed withextra_fields={}. This PR replaces the empty dict withdict(agent_data.extra_fields)to shallow-copy all custom fields into the output.turn_scoresandtool_rewardsare merged on top via.update(), preserving their override priority.Checklist Before Starting
[{modules}] {type}: {description}Test
Unit test: Added
tests/experimental/agent_loop/test_extra_fields_forwarding.py(CPU-only, runs withpytest):test_custom_extra_fields_survivetest_turn_scores_and_tool_rewards_mergedtest_turn_scores_overrides_custom_field.update()correctly overrides conflicting keystest_empty_extra_fields_still_has_turn_scorestest_shallow_copy_isolationProduction validation: Verified during multi-turn GRPO training with custom tool session data.
API and Usage Example
No API changes.
Design & Code Changes
One-line fix in
tool_agent_loop.py:dict(...)creates a shallow copy, preventing mutations tooutput.extra_fieldsfrom affectingagent_data.extra_fields.Checklist Before Submitting
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=alwaystests/experimental/agent_loop/test_extra_fields_forwarding.py(CPU-only, runs withpytest).ci-requestchannel. — Will request after review.recipesubmodule, update the reference. — N/A.