• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

deepset-ai / haystack / 14831172275

05 May 2025 07:20AM UTC coverage: 90.418% (-0.1%) from 90.513%
14831172275

Pull #9290

github

web-flow
Merge 65c6ba7e0 into 7db719981
Pull Request #9290: feat: enable streaming ToolCall/Result from Agent

10908 of 12064 relevant lines covered (90.42%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.67
haystack/components/generators/utils.py
1
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
2
#
3
# SPDX-License-Identifier: Apache-2.0
4

5
from openai.types.chat.chat_completion_chunk import ChoiceDeltaToolCall
1✔
6

7
from haystack.dataclasses import StreamingChunk
1✔
8

9

10
def print_streaming_chunk(chunk: StreamingChunk) -> None:
1✔
11
    """
12
    Default callback function for streaming responses.
13

14
    Prints the tokens of the first completion to stdout as soon as they are received.
15
    Also prints the tool calls in the meta data of the chunk.
16
    """
17
    if chunk.meta.get("tool_calls"):
×
18
        for tool_call in chunk.meta["tool_calls"]:
×
19
            if isinstance(tool_call, ChoiceDeltaToolCall) and tool_call.function:
×
20
                if tool_call.function.name and not tool_call.function.arguments:
×
21
                    print(f"[TOOL CALL - {tool_call.function.name}] ", flush=True, end="")
×
22

23
                if tool_call.function.arguments:
×
24
                    if tool_call.function.arguments.startswith("{"):
×
25
                        print("\nArguments: ", flush=True, end="")
×
26
                    print(tool_call.function.arguments, flush=True, end="")
×
27
                    if tool_call.function.arguments.endswith("}"):
×
28
                        print("\n\n", flush=True, end="")
×
29

30
    if chunk.meta.get("tool_result"):
×
31
        print(f"[TOOL RESULT]\n{chunk.meta['tool_result']}\n\n", flush=True, end="")
×
32

33
    if chunk.content:
×
34
        print(chunk.content, flush=True, end="")
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc