haystack-experimental 0.14.0__py3-none-any.whl → 0.14.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@
5
5
  # pylint: disable=wrong-import-order,wrong-import-position,ungrouped-imports
6
6
  # ruff: noqa: I001
7
7
 
8
+ import inspect
8
9
  from dataclasses import dataclass
9
10
  from typing import Any, Optional, Union
10
11
 
@@ -20,7 +21,6 @@ import haystack_experimental.core.pipeline.breakpoint as exp_breakpoint
20
21
 
21
22
  hs_breakpoint._create_agent_snapshot = exp_breakpoint._create_agent_snapshot
22
23
  hs_breakpoint._create_pipeline_snapshot_from_tool_invoker = exp_breakpoint._create_pipeline_snapshot_from_tool_invoker # type: ignore[assignment]
23
- hs_breakpoint._trigger_tool_invoker_breakpoint = exp_breakpoint._trigger_tool_invoker_breakpoint
24
24
 
25
25
  from haystack import logging
26
26
  from haystack.components.agents.agent import Agent as HaystackAgent
@@ -39,7 +39,7 @@ from haystack.core.serialization import default_from_dict, import_class_by_name
39
39
  from haystack.dataclasses import ChatMessage
40
40
  from haystack.dataclasses.breakpoints import AgentBreakpoint, ToolBreakpoint
41
41
  from haystack.dataclasses.streaming_chunk import StreamingCallbackT
42
- from haystack.tools import Tool, Toolset, deserialize_tools_or_toolset_inplace
42
+ from haystack.tools import ToolsType, deserialize_tools_or_toolset_inplace
43
43
  from haystack.utils.callable_serialization import deserialize_callable
44
44
  from haystack.utils.deserialization import deserialize_chatgenerator_inplace
45
45
 
@@ -122,7 +122,7 @@ class Agent(HaystackAgent):
122
122
  self,
123
123
  *,
124
124
  chat_generator: ChatGenerator,
125
- tools: Optional[Union[list[Tool], Toolset]] = None,
125
+ tools: Optional[ToolsType] = None,
126
126
  system_prompt: Optional[str] = None,
127
127
  exit_conditions: Optional[list[str]] = None,
128
128
  state_schema: Optional[dict[str, Any]] = None,
@@ -172,7 +172,7 @@ class Agent(HaystackAgent):
172
172
  requires_async: bool,
173
173
  *,
174
174
  system_prompt: Optional[str] = None,
175
- tools: Optional[Union[list[Tool], Toolset, list[str]]] = None,
175
+ tools: Optional[Union[ToolsType, list[str]]] = None,
176
176
  **kwargs: dict[str, Any],
177
177
  ) -> _ExecutionContext:
178
178
  """
@@ -213,7 +213,7 @@ class Agent(HaystackAgent):
213
213
  streaming_callback: Optional[StreamingCallbackT],
214
214
  requires_async: bool,
215
215
  *,
216
- tools: Optional[Union[list[Tool], Toolset, list[str]]] = None,
216
+ tools: Optional[Union[ToolsType, list[str]]] = None,
217
217
  ) -> _ExecutionContext:
218
218
  """
219
219
  Initialize execution context from an AgentSnapshot.
@@ -251,7 +251,7 @@ class Agent(HaystackAgent):
251
251
  break_point: Optional[AgentBreakpoint] = None,
252
252
  snapshot: Optional[AgentSnapshot] = None, # type: ignore[override]
253
253
  system_prompt: Optional[str] = None,
254
- tools: Optional[Union[list[Tool], Toolset, list[str]]] = None,
254
+ tools: Optional[Union[ToolsType, list[str]]] = None,
255
255
  **kwargs: Any,
256
256
  ) -> dict[str, Any]:
257
257
  """
@@ -286,7 +286,13 @@ class Agent(HaystackAgent):
286
286
  "snapshot": snapshot,
287
287
  **kwargs,
288
288
  }
289
- self._runtime_checks(break_point=break_point, snapshot=snapshot)
289
+ # The PR https://github.com/deepset-ai/haystack/pull/9987 removed the unused snapshot parameter from
290
+ # _runtime_checks. This change will be released in Haystack 2.20.0.
291
+ # To maintain compatibility with Haystack 2.19 we check the number of parameters and call accordingly.
292
+ if len(inspect.signature(self._runtime_checks).parameters) == 2:
293
+ self._runtime_checks(break_point, snapshot)
294
+ else:
295
+ self._runtime_checks(break_point) # type: ignore[call-arg] # pylint: disable=no-value-for-parameter
290
296
 
291
297
  if snapshot:
292
298
  exe_context = self._initialize_from_snapshot(
@@ -435,7 +441,7 @@ class Agent(HaystackAgent):
435
441
  break_point: Optional[AgentBreakpoint] = None,
436
442
  snapshot: Optional[AgentSnapshot] = None, # type: ignore[override]
437
443
  system_prompt: Optional[str] = None,
438
- tools: Optional[Union[list[Tool], Toolset, list[str]]] = None,
444
+ tools: Optional[Union[ToolsType, list[str]]] = None,
439
445
  **kwargs: Any,
440
446
  ) -> dict[str, Any]:
441
447
  """
@@ -473,7 +479,13 @@ class Agent(HaystackAgent):
473
479
  "snapshot": snapshot,
474
480
  **kwargs,
475
481
  }
476
- self._runtime_checks(break_point=break_point, snapshot=snapshot)
482
+ # The PR https://github.com/deepset-ai/haystack/pull/9987 removed the unused snapshot parameter from
483
+ # _runtime_checks. This change will be released in Haystack 2.20.0.
484
+ # To maintain compatibility with Haystack 2.19 we check the number of parameters and call accordingly.
485
+ if len(inspect.signature(self._runtime_checks).parameters) == 2:
486
+ self._runtime_checks(break_point, snapshot)
487
+ else:
488
+ self._runtime_checks(break_point) # type: ignore[call-arg] # pylint: disable=no-value-for-parameter
477
489
 
478
490
  if snapshot:
479
491
  exe_context = self._initialize_from_snapshot(
@@ -3,12 +3,12 @@
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  from dataclasses import replace
6
- from typing import Any, Optional, Union
6
+ from typing import Any, Optional
7
7
 
8
8
  from haystack import component
9
9
  from haystack.components.generators.chat.openai import OpenAIChatGenerator as BaseOpenAIChatGenerator
10
10
  from haystack.dataclasses import ChatMessage, StreamingCallbackT
11
- from haystack.tools import Tool, Toolset
11
+ from haystack.tools import ToolsType
12
12
 
13
13
  from haystack_experimental.utils.hallucination_risk_calculator.dataclasses import HallucinationScoreConfig
14
14
  from haystack_experimental.utils.hallucination_risk_calculator.openai_planner import calculate_hallucination_metrics
@@ -59,7 +59,7 @@ class OpenAIChatGenerator(BaseOpenAIChatGenerator):
59
59
  streaming_callback: Optional[StreamingCallbackT] = None,
60
60
  generation_kwargs: Optional[dict[str, Any]] = None,
61
61
  *,
62
- tools: Optional[Union[list[Tool], Toolset]] = None,
62
+ tools: Optional[ToolsType] = None,
63
63
  tools_strict: Optional[bool] = None,
64
64
  hallucination_score_config: Optional[HallucinationScoreConfig] = None,
65
65
  ) -> dict[str, list[ChatMessage]]:
@@ -75,9 +75,8 @@ class OpenAIChatGenerator(BaseOpenAIChatGenerator):
75
75
  override the parameters passed during component initialization.
76
76
  For details on OpenAI API parameters, see [OpenAI documentation](https://platform.openai.com/docs/api-reference/chat/create).
77
77
  :param tools:
78
- A list of tools or a Toolset for which the model can prepare calls. If set, it will override the
79
- `tools` parameter set during component initialization. This parameter can accept either a list of
80
- `Tool` objects or a `Toolset` instance.
78
+ A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls.
79
+ If set, it will override the `tools` parameter provided during initialization.
81
80
  :param tools_strict:
82
81
  Whether to enable strict schema adherence for tool calls. If set to `True`, the model will follow exactly
83
82
  the schema provided in the `parameters` field of the tool definition, but this may increase latency.
@@ -127,7 +126,7 @@ class OpenAIChatGenerator(BaseOpenAIChatGenerator):
127
126
  streaming_callback: Optional[StreamingCallbackT] = None,
128
127
  generation_kwargs: Optional[dict[str, Any]] = None,
129
128
  *,
130
- tools: Optional[Union[list[Tool], Toolset]] = None,
129
+ tools: Optional[ToolsType] = None,
131
130
  tools_strict: Optional[bool] = None,
132
131
  hallucination_score_config: Optional[HallucinationScoreConfig] = None,
133
132
  ) -> dict[str, list[ChatMessage]]:
@@ -147,9 +146,8 @@ class OpenAIChatGenerator(BaseOpenAIChatGenerator):
147
146
  override the parameters passed during component initialization.
148
147
  For details on OpenAI API parameters, see [OpenAI documentation](https://platform.openai.com/docs/api-reference/chat/create).
149
148
  :param tools:
150
- A list of tools or a Toolset for which the model can prepare calls. If set, it will override the
151
- `tools` parameter set during component initialization. This parameter can accept either a list of
152
- `Tool` objects or a `Toolset` instance.
149
+ A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls.
150
+ If set, it will override the `tools` parameter provided during initialization.
153
151
  :param tools_strict:
154
152
  Whether to enable strict schema adherence for tool calls. If set to `True`, the model will follow exactly
155
153
  the schema provided in the `parameters` field of the tool definition, but this may increase latency.
@@ -99,7 +99,7 @@ class QueryExpander:
99
99
  If None, a default OpenAIChatGenerator with gpt-4.1-mini model is used.
100
100
  :param prompt_template: Custom [PromptBuilder](https://docs.haystack.deepset.ai/docs/promptbuilder)
101
101
  template for query expansion. The template should instruct the LLM to return a JSON response with the
102
- structure: {"queries": ["query1", "query2", "query3"]}. The template should include 'query' and
102
+ structure: `{"queries": ["query1", "query2", "query3"]}`. The template should include 'query' and
103
103
  'n_expansions' variables.
104
104
  :param n_expansions: Number of alternative queries to generate (default: 4).
105
105
  :param include_original_query: Whether to include the original query in the output.
@@ -8,9 +8,6 @@ from datetime import datetime
8
8
  from typing import TYPE_CHECKING, Any, Optional
9
9
 
10
10
  from haystack import logging
11
- from haystack.core.errors import BreakpointException
12
- from haystack.core.pipeline.breakpoint import _save_pipeline_snapshot
13
- from haystack.dataclasses import ChatMessage
14
11
  from haystack.dataclasses.breakpoints import AgentBreakpoint, PipelineSnapshot, PipelineState, ToolBreakpoint
15
12
  from haystack.utils.base_serialization import _serialize_value_with_schema
16
13
  from haystack.utils.misc import _get_output_dir
@@ -120,55 +117,3 @@ def _create_pipeline_snapshot_from_tool_invoker(
120
117
  final_snapshot = replace(parent_snapshot, agent_snapshot=agent_snapshot)
121
118
 
122
119
  return final_snapshot
123
-
124
-
125
- def _trigger_tool_invoker_breakpoint(*, llm_messages: list[ChatMessage], pipeline_snapshot: PipelineSnapshot) -> None:
126
- """
127
- Check if a tool call breakpoint should be triggered before executing the tool invoker.
128
-
129
- NOTE: Only difference to Haystack's native implementation is that it includes the fix from
130
- PR https://github.com/deepset-ai/haystack/pull/9853 where we make sure to check all tool calls in a chat message
131
- when checking if a BreakpointException should be made.
132
-
133
- :param llm_messages: List of ChatMessage objects containing potential tool calls.
134
- :param pipeline_snapshot: PipelineSnapshot object containing the state of the pipeline and Agent snapshot.
135
- :raises BreakpointException: If the breakpoint is triggered, indicating a breakpoint has been reached for a tool
136
- call.
137
- """
138
- if not pipeline_snapshot.agent_snapshot:
139
- raise ValueError("PipelineSnapshot must contain an AgentSnapshot to trigger a tool call breakpoint.")
140
-
141
- if not isinstance(pipeline_snapshot.agent_snapshot.break_point.break_point, ToolBreakpoint):
142
- return
143
-
144
- tool_breakpoint = pipeline_snapshot.agent_snapshot.break_point.break_point
145
-
146
- # Check if we should break for this specific tool or all tools
147
- if tool_breakpoint.tool_name is None:
148
- # Break for any tool call
149
- should_break = any(msg.tool_call for msg in llm_messages)
150
- else:
151
- # Break only for the specific tool
152
- should_break = any(
153
- tc.tool_name == tool_breakpoint.tool_name for msg in llm_messages for tc in msg.tool_calls or []
154
- )
155
-
156
- if not should_break:
157
- return # No breakpoint triggered
158
-
159
- _save_pipeline_snapshot(pipeline_snapshot=pipeline_snapshot)
160
-
161
- msg = (
162
- f"Breaking at {tool_breakpoint.component_name} visit count "
163
- f"{pipeline_snapshot.agent_snapshot.component_visits[tool_breakpoint.component_name]}"
164
- )
165
- if tool_breakpoint.tool_name:
166
- msg += f" for tool {tool_breakpoint.tool_name}"
167
- logger.info(msg)
168
-
169
- raise BreakpointException(
170
- message=msg,
171
- component=tool_breakpoint.component_name,
172
- inputs=pipeline_snapshot.agent_snapshot.component_inputs,
173
- results=pipeline_snapshot.agent_snapshot.component_inputs["tool_invoker"]["serialized_data"]["state"],
174
- )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haystack-experimental
3
- Version: 0.14.0
3
+ Version: 0.14.2
4
4
  Summary: Experimental components and features for the Haystack LLM framework.
5
5
  Project-URL: CI: GitHub, https://github.com/deepset-ai/haystack-experimental/actions
6
6
  Project-URL: GitHub: issues, https://github.com/deepset-ai/haystack-experimental/issues
@@ -107,9 +107,9 @@ that includes it. Once it reaches the end of its lifespan, the experiment will b
107
107
  [20]: https://github.com/deepset-ai/haystack-experimental/blob/main/haystack_experimental/components/agents/human_in_the_loop/strategies.py
108
108
  [21]: https://github.com/deepset-ai/haystack-experimental/blob/main/haystack_experimental/components/agents/human_in_the_loop/dataclasses.py
109
109
  [22]: https://github.com/deepset-ai/haystack-experimental/blob/main/haystack_experimental/components/agents/human_in_the_loop/errors.py
110
- [23]: https://github.com/deepset-ai/haystack-experimental/discussions/XXX
110
+ [23]: https://github.com/deepset-ai/haystack-experimental/discussions/381
111
111
  [24]: https://github.com/deepset-ai/haystack-experimental/blob/main/haystack_experimental/components/sumarizers/llm_summarizer.py
112
- [25]: https://github.com/deepset-ai/haystack-experimental/discussions/XXX
112
+ [25]: https://github.com/deepset-ai/haystack-experimental/discussions/382
113
113
 
114
114
  ### Adopted experiments
115
115
  | Name | Type | Final release |
@@ -4,7 +4,7 @@ haystack_experimental/chat_message_stores/in_memory.py,sha256=nc_B_70KOvtgsul4QJ
4
4
  haystack_experimental/chat_message_stores/types.py,sha256=QzjA5-A08PlMAy7MMLNNUpob8S60Ypec74gSbz_l49E,2101
5
5
  haystack_experimental/components/__init__.py,sha256=eHD7xrty2PCky_gG3ty19rpM4WfV32TyytM7gJODwl4,110
6
6
  haystack_experimental/components/agents/__init__.py,sha256=Sxu9LxPpQ5cljgoTgUeNC0GY8CwUdiSy1JWkd_-RRJ4,414
7
- haystack_experimental/components/agents/agent.py,sha256=eQJ1at3RZPlXZ6zdphTL-9sE7btrmLs5p7wKLzCSgXs,31972
7
+ haystack_experimental/components/agents/agent.py,sha256=1H8fzEp97QtRWXx336PDRj1lJEUyH4aYr-HcHbNZvTw,32789
8
8
  haystack_experimental/components/agents/human_in_the_loop/__init__.py,sha256=xLr1G9pNWMmCpKN9mbv6yqeFfwMcbZyaVfCkzlwMxhY,1674
9
9
  haystack_experimental/components/agents/human_in_the_loop/breakpoint.py,sha256=GhNdGdFNDnwSiTukD4WVp6-1YgGjq5oqCEcGMC2dcog,2902
10
10
  haystack_experimental/components/agents/human_in_the_loop/dataclasses.py,sha256=OakB0PXBSG0LbQixcuo-d7IC-A3_k6qi80pB8hwY23o,2563
@@ -18,12 +18,12 @@ haystack_experimental/components/embedders/types/__init__.py,sha256=HGR8aavwIEx7
18
18
  haystack_experimental/components/embedders/types/protocol.py,sha256=EEVtggoYWZL6zF-vbasJollCxLbheMYIISAh7hJ8LkA,1038
19
19
  haystack_experimental/components/generators/__init__.py,sha256=eHD7xrty2PCky_gG3ty19rpM4WfV32TyytM7gJODwl4,110
20
20
  haystack_experimental/components/generators/chat/__init__.py,sha256=LEKI1mMtltVbSiU40QgBfnWC-z3_660TWuV-cVHhdTw,465
21
- haystack_experimental/components/generators/chat/openai.py,sha256=QFb-l_VbTkqi46rqE6rkmMoRkT3fX8kEsStOEGMEBRw,10040
21
+ haystack_experimental/components/generators/chat/openai.py,sha256=gX6UI4yfY0pzKhWErquvPF_gV-3Ut0y6wSJytAD07Jk,9855
22
22
  haystack_experimental/components/preprocessors/__init__.py,sha256=x3fM1lpGzYjWB3hpdbDWxXr_rYASb2e9yX0PgYG84rA,518
23
23
  haystack_experimental/components/preprocessors/embedding_based_document_splitter.py,sha256=VyQ--gaMsWid-IRBVXi5YPJpwbFlaK-2mRFvRF8MSBQ,17616
24
24
  haystack_experimental/components/preprocessors/md_header_level_inferrer.py,sha256=1Tn-H4Gvg2yYSUc54cPWKTCK78KXet5u32_1S8PM3NU,5643
25
25
  haystack_experimental/components/query/__init__.py,sha256=quaqe16cbtgIdJx7d56CMdk1zZQ6f_3_TICsU0HF_U8,446
26
- haystack_experimental/components/query/query_expander.py,sha256=zc9i2zP3ciOWWr029wO_lw3Tl8W3_kQcYcoHDs5Nj8c,12293
26
+ haystack_experimental/components/query/query_expander.py,sha256=cZAT6ThSXXfeI-Fg2FrnqWn7uOvl9m5z8Pz8wKvrJuw,12295
27
27
  haystack_experimental/components/retrievers/__init__.py,sha256=CqPvqyvGp5L3Y1gTVQC8DD_xHzbIfTzGlj3oCsZM3J8,528
28
28
  haystack_experimental/components/retrievers/chat_message_retriever.py,sha256=CaAgW1qzzhMYyKNOyk-eIBgSsO7Bg7uDqAtgcorCE60,4030
29
29
  haystack_experimental/components/retrievers/multi_query_embedding_retriever.py,sha256=IAjAh3SqsKx_d8QEfRAqVYNDL5UUuBb3GNJPDGjokjU,8103
@@ -36,7 +36,7 @@ haystack_experimental/components/writers/__init__.py,sha256=iMdeAaZozza8E6dQ4Lc2
36
36
  haystack_experimental/components/writers/chat_message_writer.py,sha256=iu8gmvmRXlqd9S2-9B8p-7C0Y5GTuOI1AqcVKAkrzDc,3502
37
37
  haystack_experimental/core/__init__.py,sha256=eHD7xrty2PCky_gG3ty19rpM4WfV32TyytM7gJODwl4,110
38
38
  haystack_experimental/core/pipeline/__init__.py,sha256=eHD7xrty2PCky_gG3ty19rpM4WfV32TyytM7gJODwl4,110
39
- haystack_experimental/core/pipeline/breakpoint.py,sha256=04a2ngU2I5B2lp7iUqJjax8ZNarq5i753M1hFUGzc4s,7603
39
+ haystack_experimental/core/pipeline/breakpoint.py,sha256=JtwQP8OF5Sdqo0abPRgs1K3SqBkUXhZ53PkeagcK2ZE,5134
40
40
  haystack_experimental/dataclasses/__init__.py,sha256=eHD7xrty2PCky_gG3ty19rpM4WfV32TyytM7gJODwl4,110
41
41
  haystack_experimental/dataclasses/breakpoints.py,sha256=f0kxYXJRHzk6jAW5Na51MZfUuRIlulhN4oTrGWTpSFE,2095
42
42
  haystack_experimental/super_components/__init__.py,sha256=eHD7xrty2PCky_gG3ty19rpM4WfV32TyytM7gJODwl4,110
@@ -48,8 +48,8 @@ haystack_experimental/utils/hallucination_risk_calculator/core_math.py,sha256=8X
48
48
  haystack_experimental/utils/hallucination_risk_calculator/dataclasses.py,sha256=3vk9jsbW-7C9n408Qe730qgdXxIOzsTigf4TMLpryvI,2318
49
49
  haystack_experimental/utils/hallucination_risk_calculator/openai_planner.py,sha256=-yVQsGzM5rXsAVwolE6sp5W6q1yDw66SiIUuUbPk1ng,11413
50
50
  haystack_experimental/utils/hallucination_risk_calculator/skeletonization.py,sha256=qNdBUoFiBjQsI3ovrhd4RyTFmIbv51Goai1Z_l9lG28,5488
51
- haystack_experimental-0.14.0.dist-info/METADATA,sha256=p8xYGisk0cutaMtYxQXMlmXZvYrLFGpdK2aHJUBJhVY,18566
52
- haystack_experimental-0.14.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
53
- haystack_experimental-0.14.0.dist-info/licenses/LICENSE,sha256=93_5nS97uHxptHvK9E8BZgKxLGeIS-rBWT2swIv-X5Y,11368
54
- haystack_experimental-0.14.0.dist-info/licenses/LICENSE-MIT.txt,sha256=knmLkIKj_6tTrTSVRg9Tq88Kww4UCPLt2I1RGXJv9sQ,1037
55
- haystack_experimental-0.14.0.dist-info/RECORD,,
51
+ haystack_experimental-0.14.2.dist-info/METADATA,sha256=5wj3kC9aQ6B3TOrh9FNXmkbQMD1nEnF2eUoRc-B2yqA,18566
52
+ haystack_experimental-0.14.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
53
+ haystack_experimental-0.14.2.dist-info/licenses/LICENSE,sha256=93_5nS97uHxptHvK9E8BZgKxLGeIS-rBWT2swIv-X5Y,11368
54
+ haystack_experimental-0.14.2.dist-info/licenses/LICENSE-MIT.txt,sha256=knmLkIKj_6tTrTSVRg9Tq88Kww4UCPLt2I1RGXJv9sQ,1037
55
+ haystack_experimental-0.14.2.dist-info/RECORD,,