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
If the prompt itself must still be assembled per run, build `ChatMessage` objects before the `Agent` (e.g. with a `ChatPromptBuilder`) and pass them through the `messages` input.
478
478
For a runtime system prompt, construct an `Agent` without `system_prompt` or `user_prompt` and include a system message at the start of `messages`.
479
479
480
+
#### Prompt template variables are required by default
481
+
482
+
**What changed:**`Agent` now treats every Jinja2 template variable in `user_prompt` and `system_prompt` as required by default. The `required_variables` parameter's default has been changed from `None` (all optional) to `"*"` (all required). Previously, missing variables were silently rendered as empty strings. Passing `required_variables=None` explicitly still opts into the old "all optional" behavior.
483
+
484
+
**Why:** Avoids silent rendering bugs where a missing variable produces an unexpectedly empty section of the prompt. Aligns `Agent` with `LLM`, `PromptBuilder`, and `ChatPromptBuilder`, which already require all variables by default in v3.0.
485
+
486
+
**How to migrate:**
487
+
488
+
Before (v2.x):
489
+
```python
490
+
from haystack.components.agents import Agent
491
+
492
+
# All variables were optional by default; missing values rendered as "".
493
+
agent = Agent(
494
+
chat_generator=...,
495
+
tools=[...],
496
+
user_prompt="Answer {{query}} in {{language}}.",
497
+
)
498
+
agent.run(messages=[], query="What is NLP?") # language silently becomes ""
499
+
```
500
+
501
+
After (v3.0):
502
+
```python
503
+
from haystack.components.agents import Agent
504
+
505
+
# Option 1: provide every variable (matches the new safe default).
506
+
agent = Agent(
507
+
chat_generator=...,
508
+
tools=[...],
509
+
user_prompt="Answer {{query}} in {{language}}.",
510
+
)
511
+
agent.run(messages=[], query="What is NLP?", language="English")
512
+
513
+
# Option 2: declare which variables are required; everything else stays optional.
514
+
agent = Agent(
515
+
chat_generator=...,
516
+
tools=[...],
517
+
user_prompt="Answer {{query}} in {{language}}.",
518
+
required_variables=["query"],
519
+
)
520
+
agent.run(messages=[], query="What is NLP?") # language renders as ""
521
+
522
+
# Option 3: restore the old "all optional" behavior.
523
+
agent = Agent(
524
+
chat_generator=...,
525
+
tools=[...],
526
+
user_prompt="Answer {{query}} in {{language}}.",
527
+
required_variables=None,
528
+
)
529
+
agent.run(messages=[], query="What is NLP?") # language renders as ""
530
+
```
531
+
480
532
#### Tools must declare `inputs_from_state` to read from `State` by name
481
533
482
534
**What changed:** A tool now reads a value from the Agent's `State` by name only when it declares an explicit `inputs_from_state` mapping. Previously, a tool without `inputs_from_state` had every parameter implicitly treated as a potential `State` key: any parameter whose name matched a `State` key (and that the LLM did not supply) was silently filled from `State`. This implicit name-matching has been removed. It applies to every tool type, since `ComponentTool`, `PipelineTool`, `MCPTool`, and others all derive from the base `Tool` class.
Copy file name to clipboardExpand all lines: docs-website/docs/overview/migration.mdx
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -251,6 +251,10 @@ The agent-specific breakpoint API (`AgentBreakpoint`, `ToolBreakpoint`, `AgentSn
251
251
252
252
`Agent.run` and `Agent.run_async` no longer accept `system_prompt` or `user_prompt`; both must be set at initialization time. If a prompt must still be assembled per run, build `ChatMessage` objects before the Agent (for example, with a `ChatPromptBuilder`) and pass them through the `messages` input — a system message at the start of `messages` acts as a runtime system prompt. The same change applies to the `LLM` component.
253
253
254
+
### Prompt template variables are required by default
255
+
256
+
`Agent` now treats every Jinja2 template variable in `user_prompt` and `system_prompt` as required, in line with the [prompt builders](#prompt-builders-template-variables-are-required-by-default): the `required_variables` parameter's default changed from `None` (all optional) to `"*"` (all required). Previously, missing variables were silently rendered as empty strings. Pass `required_variables=["var1", "var2"]` to require only a subset, or `required_variables=None` to restore the old "all optional" behavior.
257
+
254
258
### Tools must declare `inputs_from_state` to read from `State` by name
255
259
256
260
A tool now reads a value from the Agent's [`State`](../pipeline-components/agents-1/state.mdx) by name only when it declares an explicit `inputs_from_state` mapping. The old implicit behavior — any tool parameter whose name matched a `State` key was silently filled from `State` — has been removed. Add `inputs_from_state={"state_key": "parameter_name"}` to any tool that should read from `State`. Tools that take the full `State` object via a `State`-annotated parameter are unaffected.
0 commit comments