Skip to content

fix: honor exit_conditions when LLM emits parallel tool calls#11393

Merged
sjrl merged 4 commits into
deepset-ai:mainfrom
Aarkin7:fix/agent-exit-conditions-parallel-tool-calls
May 26, 2026
Merged

fix: honor exit_conditions when LLM emits parallel tool calls#11393
sjrl merged 4 commits into
deepset-ai:mainfrom
Aarkin7:fix/agent-exit-conditions-parallel-tool-calls

Conversation

@Aarkin7
Copy link
Copy Markdown
Contributor

@Aarkin7 Aarkin7 commented May 25, 2026

Related Issues

Proposed Changes:

Agent._check_exit_conditions was reading msg.tool_call (singular), which only returns the first ToolCall in the message. So when the LLM emitted a parallel batch like [search, finish] with exit_conditions=["finish"], the finish call was invisible to the exit check and the agent kept looping silently until max_agent_steps was reached.

Switched to iterating msg.tool_calls (plural) so every call in the batch is checked. The existing error-suppression behaviour is preserved, if the exit-condition tool errored, the agent still does not exit. The helper is shared by both run and run_async, so one fix covers both flows.

How did you test it?

  • Added 3 regression unit tests in test/components/agents/test_agent.py covering: exit-condition tool not first in the batch, error on the exit tool (must not exit), error only on a sibling non-exit tool (must still exit).
  • hatch run test:unit test/components/agents/146 passed, no regressions.
  • hatch run test:types and hatch run fmt → clean.

Notes for the reviewer

Behaviour-correcting bug fix, not a breaking change.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@Aarkin7 Aarkin7 requested a review from a team as a code owner May 25, 2026 18:19
@Aarkin7 Aarkin7 requested review from davidsbatista and removed request for a team May 25, 2026 18:19
@vercel
Copy link
Copy Markdown

vercel Bot commented May 25, 2026

@Aarkin7 is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels May 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/agents
  agent.py
Project Total  

This report was generated by python-coverage-comment-action

@sjrl sjrl requested review from sjrl and removed request for davidsbatista May 26, 2026 07:10
Comment thread haystack/components/agents/agent.py Outdated
Comment thread test/components/agents/test_agent.py Outdated
Comment thread test/components/agents/test_agent.py Outdated
@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview May 26, 2026 7:29am

Request Review

Copy link
Copy Markdown
Contributor

@sjrl sjrl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

@sjrl sjrl merged commit 7437fbd into deepset-ai:main May 26, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent does not exit when LLM emits parallel tool calls and the exit-condition tool is not the first one

2 participants