Skip to content

feat: (and fix) Add enable_streaming_passthrough to ToolInvoker and add missing params to to_dict#9498

Merged
sjrl merged 7 commits intomainfrom
pass-on-streaming-callback-tool-invoker
Jun 6, 2025
Merged

feat: (and fix) Add enable_streaming_passthrough to ToolInvoker and add missing params to to_dict#9498
sjrl merged 7 commits intomainfrom
pass-on-streaming-callback-tool-invoker

Conversation

@sjrl
Copy link
Copy Markdown
Contributor

@sjrl sjrl commented Jun 5, 2025

Related Issues

  • fixes #issue-number

Proposed Changes:

Add enable_streaming_passthrough at the request of the platform team (@tstadel). This is to allow the ToolInvoker to pass the streaming_callback to the tool invocation if the tool supports it. This only occurs if this flag is set to True and if the tool has a streaming_callback parameter in its invoke method signature. This is to more easily enable Tools that contain Components or SuperComponents that support streaming (e.g. Agent) and allow them to stream in a deployment setting. @tstadel has more details on the complexity on this.

Fixed the to_dict and from_dict methods of ToolInvoker to properly serliaze it's init parameters. For example, streaming_callback serialization was missing.

How did you test it?

  • Added unit tests

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

@sjrl sjrl requested review from a team as code owners June 5, 2025 14:28
@sjrl sjrl requested review from dfokina and mpangrazzi and removed request for a team June 5, 2025 14:28
@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Jun 5, 2025
@sjrl sjrl self-assigned this Jun 5, 2025
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Jun 5, 2025

Pull Request Test Coverage Report for Build 15486550666

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 66 unchanged lines in 7 files lost coverage.
  • Overall coverage increased (+0.07%) to 90.463%

Files with Coverage Reduction New Missed Lines %
dataclasses/init.py 1 46.15%
utils/hf.py 2 85.29%
dataclasses/streaming_chunk.py 5 90.38%
components/generators/chat/openai.py 7 95.76%
components/generators/chat/hugging_face_api.py 8 95.63%
components/generators/utils.py 9 76.0%
components/tools/tool_invoker.py 34 83.94%
Totals Coverage Status
Change from base Build 15468967841: 0.07%
Covered Lines: 11535
Relevant Lines: 12751

💛 - Coveralls

@tstadel
Copy link
Copy Markdown
Member

tstadel commented Jun 5, 2025

@sjrl thanks a lot for this. Nice & clean, looking great!
Just a bit more context on the issue:

  • we must pass the streaming callback as run param to components when running the pipeline behind a concurrently working api (so each stream is bound to the right request)
  • passing the streaming callback directly to a component that is part of a tool(pipeline) is not possible as the run invocation is fully controlled/owned by ToolInvoker

Looking forward to having this!

@sjrl
Copy link
Copy Markdown
Contributor Author

sjrl commented Jun 5, 2025

@mpangrazzi just realized I should add a specific test for this since I'm unsure if inspect.signature will work well in the case for ComponentTool since it's defined as def component_invoker(**kwargs) and I don't think we update the signature of the component_invoker using the available input_sockets = component.__haystack_input__._sockets_dict .

So for this to work as expected for ComponentTool specifically it may be better to check if the tool_schema has streaming_callback present rather than relying on inspect.signature

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! I've added two comments, one might be relevant.

Comment thread haystack/components/tools/tool_invoker.py Outdated
@sjrl
Copy link
Copy Markdown
Contributor Author

sjrl commented Jun 6, 2025

@mpangrazzi just realized I should add a specific test for this since I'm unsure if inspect.signature will work well in the case for ComponentTool since it's defined as def component_invoker(**kwargs) and I don't think we update the signature of the component_invoker using the available input_sockets = component.__haystack_input__._sockets_dict .

So for this to work as expected for ComponentTool specifically it may be better to check if the tool_schema has streaming_callback present rather than relying on inspect.signature

Added a test and a fix for this. New utility method called _get_func_params which reuses existing code for tackling this exact issue with ComponentTool

@sjrl sjrl requested a review from mpangrazzi June 6, 2025 08: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.

LGTM!

@sjrl sjrl merged commit 54c5057 into main Jun 6, 2025
19 checks passed
@sjrl sjrl deleted the pass-on-streaming-callback-tool-invoker branch June 6, 2025 12:16
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.

4 participants