Skip to content

fix: adjust the async executor in ToolInvoker#9562

Merged
Amnah199 merged 8 commits intomainfrom
fix-toolinvoker-async
Jun 30, 2025
Merged

fix: adjust the async executor in ToolInvoker#9562
Amnah199 merged 8 commits intomainfrom
fix-toolinvoker-async

Conversation

@Amnah199
Copy link
Copy Markdown
Contributor

@Amnah199 Amnah199 commented Jun 27, 2025

Related Issues

Proposed Changes:

Remove the context manager for executor in run_async.

How did you test it?

Added the test mentioned in the issue.

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I 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 documented my code
  • I ran pre-commit hooks and fixed any issue

@Amnah199 Amnah199 added the ignore-for-release-notes PRs with this flag won't be included in the release notes. label Jun 27, 2025
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Jun 27, 2025

Pull Request Test Coverage Report for Build 15973645048

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 35 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.04%) to 90.223%

Files with Coverage Reduction New Missed Lines %
components/tools/tool_invoker.py 35 85.13%
Totals Coverage Status
Change from base Build 15972242053: -0.04%
Covered Lines: 11729
Relevant Lines: 13000

💛 - Coveralls

@Amnah199 Amnah199 marked this pull request as ready for review June 29, 2025 18:35
@Amnah199 Amnah199 requested a review from a team as a code owner June 29, 2025 18:35
@Amnah199 Amnah199 requested review from mpangrazzi and vblagoje and removed request for a team June 29, 2025 18:35
Copy link
Copy Markdown
Contributor

@mpangrazzi mpangrazzi left a comment

Choose a reason for hiding this comment

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

I've left some comments!

Also, as discussed, we may need to have two final "acceptance" tests with e.g. 2 concurrent run() / run_async() calls (which in turn call multiple tools as in other tests).

Comment thread haystack/components/tools/tool_invoker.py Outdated
Comment thread test/components/tools/test_tool_invoker.py Outdated
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Jun 30, 2025
Comment on lines +780 to +782
else:
with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
# 3) Create async tasks for valid tool calls
Copy link
Copy Markdown
Contributor Author

@Amnah199 Amnah199 Jun 30, 2025

Choose a reason for hiding this comment

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

@mpangrazzi so I separated the two cases as the previously initialized executor cannot be used with context manager. There is a lot of code duplication now, but this will be removed in 2.16.
Wdyt?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good!

@Amnah199 Amnah199 requested a review from mpangrazzi June 30, 2025 10:45
Copy link
Copy Markdown
Contributor

@mpangrazzi mpangrazzi left a comment

Choose a reason for hiding this comment

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

Looks good! Will look even better in 2.16 ;)

@Amnah199 Amnah199 merged commit f11870b into main Jun 30, 2025
17 checks passed
@Amnah199 Amnah199 deleted the fix-toolinvoker-async branch June 30, 2025 13:13
Amnah199 added a commit that referenced this pull request Jun 30, 2025
* Fix bug

* Add a new test

* PR comments

* Add another test

* Small fix

* Fix linting

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

Labels

ignore-for-release-notes PRs with this flag won't be included in the release notes. topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ToolInvoker.run_async shuts down persistent executor after first use

3 participants