Skip to content

Commit f4b76a1

Browse files
authored
refactor!: Remove agent breakpoint and agent snapshot (#11202)
1 parent 18559c2 commit f4b76a1

17 files changed

Lines changed: 203 additions & 2867 deletions

MIGRATION.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,58 @@ from haystack.dataclasses import Document
7070

7171
doc = Document(content="col\n1\n2\n3")
7272
```
73+
74+
### Agent
75+
76+
**What changed:** The agent-specific breakpoint API has been removed. The `AgentBreakpoint`, `ToolBreakpoint`, and `AgentSnapshot` dataclasses are no longer exported from `haystack.dataclasses`, and the `break_point`, `snapshot`, and `snapshot_callback` parameters have been removed from `Agent.run` and `Agent.run_async`. `Pipeline.run` no longer accepts an `AgentBreakpoint` for its `break_point` argument, and the `agent_snapshot` field has been removed from `PipelineSnapshot`. Pausing and resuming execution inside an Agent (at the chat generator or tool invoker) is no longer supported.
77+
78+
**Why:** Simplifies the breakpoint and snapshot machinery and removes the special-cased agent-internal control flow. Pipeline-level breakpoints still cover the common debugging use cases.
79+
80+
**How to migrate:**
81+
82+
Before (v2.x):
83+
```python
84+
from haystack.components.agents import Agent
85+
from haystack.dataclasses import AgentBreakpoint, Breakpoint, ToolBreakpoint
86+
87+
agent = Agent(chat_generator=..., tools=[...])
88+
89+
# Pause before the chat generator runs
90+
chat_break_point = AgentBreakpoint(
91+
agent_name="agent",
92+
break_point=Breakpoint(component_name="chat_generator", visit_count=0),
93+
)
94+
95+
# Or pause before a specific tool is invoked
96+
tool_break_point = AgentBreakpoint(
97+
agent_name="agent",
98+
break_point=ToolBreakpoint(component_name="tool_invoker", tool_name="my_tool"),
99+
)
100+
101+
agent.run(messages=[...], break_point=chat_break_point)
102+
```
103+
104+
After (v3.0):
105+
```python
106+
# Pausing inside an Agent is no longer supported. To inspect an Agent's behavior,
107+
# use tracing instead (https://docs.haystack.deepset.ai/docs/tracing). For example,
108+
# you can wire up a Langfuse tracer for a standalone Agent by instantiating a
109+
# LangfuseConnector — its constructor registers the tracer globally, so any
110+
# subsequent Agent.run call will be traced.
111+
112+
# NOTE: install the langfuse integration first with `pip install langfuse-haystack` to run this example.
113+
import os
114+
115+
os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
116+
117+
from haystack.components.agents import Agent
118+
from haystack.components.generators.chat import OpenAIChatGenerator
119+
from haystack.dataclasses import ChatMessage
120+
from haystack_integrations.components.connectors.langfuse import LangfuseConnector
121+
122+
# Instantiating the connector enables tracing globally — no need to add it to a pipeline.
123+
LangfuseConnector("Standalone Agent example")
124+
125+
agent = Agent(chat_generator=OpenAIChatGenerator(model="gpt-4o-mini"), tools=[...])
126+
agent.run(messages=[ChatMessage.from_user("What's the weather in Berlin?")])
127+
```

haystack/components/agents/agent.py

Lines changed: 78 additions & 394 deletions
Large diffs are not rendered by default.

haystack/core/errors.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import Any
66

7-
from haystack.dataclasses.breakpoints import AgentBreakpoint, Breakpoint, PipelineSnapshot, ToolBreakpoint
7+
from haystack.dataclasses.breakpoints import Breakpoint, PipelineSnapshot
88

99

1010
class PipelineError(Exception):
@@ -115,7 +115,7 @@ def __init__(
115115
pipeline_snapshot: PipelineSnapshot | None = None,
116116
pipeline_snapshot_file_path: str | None = None,
117117
*,
118-
break_point: AgentBreakpoint | Breakpoint | ToolBreakpoint | None = None,
118+
break_point: Breakpoint | None = None,
119119
) -> None:
120120
super().__init__(message)
121121
self.component = component
@@ -127,7 +127,7 @@ def __init__(
127127
raise ValueError("Either pipeline_snapshot or break_point must be provided.")
128128

129129
@classmethod
130-
def from_triggered_breakpoint(cls, break_point: Breakpoint | ToolBreakpoint) -> "BreakpointException":
130+
def from_triggered_breakpoint(cls, break_point: Breakpoint) -> "BreakpointException":
131131
"""
132132
Create a BreakpointException from a triggered breakpoint.
133133
"""
@@ -137,37 +137,25 @@ def from_triggered_breakpoint(cls, break_point: Breakpoint | ToolBreakpoint) ->
137137
@property
138138
def inputs(self) -> dict[str, Any] | None:
139139
"""
140-
Returns the inputs of the pipeline or agent at the breakpoint.
141-
142-
If an AgentBreakpoint caused this exception, returns the inputs of the agent's internal components.
143-
Otherwise, returns the current inputs of the pipeline.
140+
Returns the current inputs of the pipeline at the breakpoint.
144141
"""
145142
if not self.pipeline_snapshot:
146143
return None
147-
148-
if self.pipeline_snapshot.agent_snapshot:
149-
return self.pipeline_snapshot.agent_snapshot.component_inputs
150144
return self.pipeline_snapshot.pipeline_state.inputs
151145

152146
@property
153147
def results(self) -> dict[str, Any] | None:
154148
"""
155-
Returns the results of the pipeline or agent at the breakpoint.
156-
157-
If an AgentBreakpoint caused this exception, returns the current results of the agent.
158-
Otherwise, returns the current outputs of the pipeline.
149+
Returns the current outputs of the pipeline at the breakpoint.
159150
"""
160151
if not self.pipeline_snapshot:
161152
return None
162-
163-
if self.pipeline_snapshot.agent_snapshot:
164-
return self.pipeline_snapshot.agent_snapshot.component_inputs["tool_invoker"]["serialized_data"]["state"]
165153
return self.pipeline_snapshot.pipeline_state.pipeline_outputs
166154

167155
@property
168-
def break_point(self) -> AgentBreakpoint | Breakpoint | ToolBreakpoint:
156+
def break_point(self) -> Breakpoint:
169157
"""
170-
Returns the Breakpoint or AgentBreakpoint that caused this exception, if available.
158+
Returns the Breakpoint that caused this exception.
171159
172160
If a specific break point was provided during initialization, it is returned.
173161
Otherwise, if the pipeline snapshot contains a break point, that is returned.

0 commit comments

Comments
 (0)