Skip to content

fix(agent): detect stop tool anywhere in a multi-tool batch#3169

Open
nankingjing wants to merge 1 commit into
volcengine:mainfrom
nankingjing:fix/stop-tool-position-batch
Open

fix(agent): detect stop tool anywhere in a multi-tool batch#3169
nankingjing wants to merge 1 commit into
volcengine:mainfrom
nankingjing:fix/stop-tool-position-batch

Conversation

@nankingjing

Copy link
Copy Markdown
Contributor

Summary

The agent loop's stop-tool detection only inspected a single tool in a batch, so when the model emitted several tool calls in one turn and a stop tool was not in the first position, the loop failed to recognize it and did not stop.

Problem

The check tested one entry rather than the whole batch, missing a stop tool anywhere but the checked position.

Fix

Detect a stop tool anywhere in the batch:

any(t.get("tool_name") in stop_tools for t in tools_used)

so a stop tool in any position terminates the loop as intended.

Test

bot/vikingbot/tests/unit/test_agent/test_stop_tool_preservation.py — covers a stop tool in a non-first batch position triggering stop (3 passed).

Tools execute in parallel, so tools_used[-1] is not necessarily the
stop tool when it was co-called with another tool in the same batch.
Check every executed tool with any() to reliably preserve an
intentional empty final reply.
@nankingjing

Copy link
Copy Markdown
Contributor Author
Self-reviewed: diff is correct, minimal, and well-tested. No issues found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant