You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-website/reference/haystack-api/agents_api.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -219,6 +219,9 @@ Initialize the agent component.
219
219
-**hooks** (<code>dict\[HookPoint, list\[Hook\]\] | None</code>) – A dictionary mapping a hook point to a list of hooks the Agent runs at that point. Each hook
220
220
receives the live `State` and influences the run by mutating it in place; hooks for a hook point run in
221
221
list order. Valid hook points are:
222
+
- "before_run": Runs once per run, after the state is initialized and before the first chat-generator
223
+
call. Use it to rewrite the initial messages or seed state (e.g. turn the user query into a task
224
+
brief) without re-running on every step like "before_llm" does.
222
225
- "before_llm": Runs before each chat-generator call.
223
226
- "before_tool": Runs after the model requests tool calls, before any tools run. After these hooks run,
224
227
the Agent re-reads the current last message from `state.data["messages"]`. If that message contains tool
@@ -232,6 +235,11 @@ Initialize the agent component.
232
235
Agent running by setting the `continue_run` control flag (`state.set("continue_run", True)`), usually
233
236
alongside a message telling the model what to do next. "on_exit" hooks run when the Agent stops on an
234
237
exit condition, but not when it stops because `max_agent_steps` is reached.
238
+
- "after_run": Runs once per run, after the step loop has ended and before the Agent builds its return
239
+
value — regardless of whether the run stopped on an exit condition or because `max_agent_steps` was
240
+
reached (unlike "on_exit"). Mutations to the state (e.g. appending a final message) are reflected in
241
+
the returned `messages` / `last_message` and `state_schema` outputs. Setting `continue_run` here has
0 commit comments