Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/CI_check_api_ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ jobs:
python-version: "3.13"

- name: Install Hatch
uses: pypa/hatch@install
with:
version: "${{ env.HATCH_VERSION }}"
run: pip install hatch

- name: Generate API references
run: hatch run docs
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/docusaurus_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
workflow_dispatch:

env:
HATCH_VERSION: "1.14.2"
HATCH_VERSION: "1.16.5"
PYTHON_VERSION: "3.11"
jobs:
generate-api-reference:
Expand All @@ -28,9 +28,7 @@ jobs:
python-version: "${{ env.PYTHON_VERSION }}"

- name: Install Hatch
uses: pypa/hatch@install
with:
version: "${{ env.HATCH_VERSION }}"
run: pip install hatch==${{ env.HATCH_VERSION }}

- name: Generate API reference
run: hatch run docs
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/pypi_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "v[0-9]+.[0-9]+.[0-9]+*"

env:
HATCH_VERSION: "1.14.2"
HATCH_VERSION: "1.16.5"

jobs:
release-on-pypi:
Expand All @@ -22,9 +22,7 @@ jobs:
python-version: "3.12"

- name: Install Hatch
uses: pypa/hatch@install
with:
version: "${{ env.HATCH_VERSION }}"
run: pip install hatch==${{ env.HATCH_VERSION }}

- name: Build Haystack Experimental
run: hatch build
Expand Down
14 changes: 4 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ permissions:

env:
PYTHON_VERSION: "3.10"
HATCH_VERSION: "1.14.2"
HATCH_VERSION: "1.16.5"
PYTHONUNBUFFERED: "1"
FORCE_COLOR: "1"
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Expand Down Expand Up @@ -59,9 +59,7 @@ jobs:
python-version: "${{ env.PYTHON_VERSION }}"

- name: Install Hatch
uses: pypa/hatch@install
with:
version: "${{ env.HATCH_VERSION }}"
run: pip install hatch==${{ env.HATCH_VERSION }}

- name: Ruff - check format and linting
run: hatch run fmt-check
Expand Down Expand Up @@ -90,9 +88,7 @@ jobs:
python-version: "${{ env.PYTHON_VERSION }}"

- name: Install Hatch
uses: pypa/hatch@install
with:
version: "${{ env.HATCH_VERSION }}"
run: pip install hatch==${{ env.HATCH_VERSION }}

- name: Run
run: hatch run test:unit
Expand Down Expand Up @@ -133,9 +129,7 @@ jobs:
python-version: "${{ env.PYTHON_VERSION }}"

- name: Install Hatch
uses: pypa/hatch@install
with:
version: "${{ env.HATCH_VERSION }}"
run: pip install hatch==${{ env.HATCH_VERSION }}

# Do not authenticate on PRs from forks and on PRs created by dependabot
- name: AWS authentication
Expand Down
25 changes: 23 additions & 2 deletions haystack_experimental/components/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ruff: noqa: I001

import inspect
from typing import Any
from typing import Any, Literal

# Monkey patch Haystack's AgentSnapshot with our extended version
import haystack.dataclasses.breakpoints as hdb
Expand Down Expand Up @@ -107,12 +107,14 @@ class Agent(HaystackAgent):
```
"""

def __init__(
def __init__( # noqa: PLR0913
self,
*,
chat_generator: ChatGenerator,
tools: ToolsType | None = None,
system_prompt: str | None = None,
user_prompt: str | None = None,
required_variables: list[str] | Literal["*"] | None = None,
exit_conditions: list[str] | None = None,
state_schema: dict[str, Any] | None = None,
max_agent_steps: int = 100,
Expand All @@ -129,6 +131,11 @@ def __init__(
:param chat_generator: An instance of the chat generator that your agent should use. It must support tools.
:param tools: List of Tool objects or a Toolset that the agent can use.
:param system_prompt: System prompt for the agent.
:param user_prompt: User prompt for the agent. If provided this is appended to the messages provided at runtime.
:param required_variables:
List variables that must be provided as input to user_prompt.
If a variable listed as required is not provided, an exception is raised.
If set to `"*"`, all variables found in the prompt are required. Optional.
:param exit_conditions: List of conditions that will cause the agent to return.
Can include "text" if the agent should return when it generates a message without tool calls,
or tool names that will cause the agent to return once the tool was executed. Defaults to ["text"].
Expand All @@ -150,6 +157,8 @@ def __init__(
chat_generator=chat_generator,
tools=tools,
system_prompt=system_prompt,
user_prompt=user_prompt,
required_variables=required_variables,
exit_conditions=exit_conditions,
state_schema=state_schema,
max_agent_steps=max_agent_steps,
Expand All @@ -174,6 +183,7 @@ def _initialize_fresh_execution(
requires_async: bool,
*,
system_prompt: str | None = None,
user_prompt: str | None = None,
generation_kwargs: dict[str, Any] | None = None,
tools: ToolsType | list[str] | None = None,
confirmation_strategy_context: dict[str, Any] | None = None,
Expand All @@ -188,6 +198,8 @@ def _initialize_fresh_execution(
:param streaming_callback: Optional callback for streaming responses.
:param requires_async: Whether the agent run requires asynchronous execution.
:param system_prompt: System prompt for the agent. If provided, it overrides the default system prompt.
:param user_prompt: User prompt for the agent. If provided, it overrides the default user prompt and is
appended to the messages provided at runtime.
:param tools: Optional list of Tool objects, a Toolset, or list of tool names to use for this run.
When passing tool names, tools are selected from the Agent's originally configured tools.

Expand All @@ -205,6 +217,7 @@ def _initialize_fresh_execution(
streaming_callback=streaming_callback,
requires_async=requires_async,
system_prompt=system_prompt,
user_prompt=user_prompt,
generation_kwargs=generation_kwargs,
tools=tools,
confirmation_strategy_context=confirmation_strategy_context,
Expand Down Expand Up @@ -304,6 +317,7 @@ def run( # type: ignore[override] # noqa: PLR0915 PLR0912
break_point: AgentBreakpoint | None = None,
snapshot: AgentSnapshot | None = None,
system_prompt: str | None = None,
user_prompt: str | None = None,
tools: ToolsType | list[str] | None = None,
confirmation_strategy_context: dict[str, Any] | None = None,
chat_message_store_kwargs: dict[str, Any] | None = None,
Expand All @@ -323,6 +337,8 @@ def run( # type: ignore[override] # noqa: PLR0915 PLR0912
:param snapshot: A dictionary containing a snapshot of a previously saved agent execution. The snapshot contains
the relevant information to restart the Agent execution from where it left off.
:param system_prompt: System prompt for the agent. If provided, it overrides the default system prompt.
:param user_prompt: User prompt for the agent. If provided, it overrides the default user prompt and is
appended to the messages provided at runtime.
:param tools: Optional list of Tool objects, a Toolset, or list of tool names to use for this run.
When passing tool names, tools are selected from the Agent's originally configured tools.
:param confirmation_strategy_context: Optional dictionary for passing request-scoped resources
Expand Down Expand Up @@ -382,6 +398,7 @@ def run( # type: ignore[override] # noqa: PLR0915 PLR0912
streaming_callback=streaming_callback,
requires_async=False,
system_prompt=system_prompt,
user_prompt=user_prompt,
generation_kwargs=generation_kwargs,
tools=tools,
confirmation_strategy_context=confirmation_strategy_context,
Expand Down Expand Up @@ -565,6 +582,7 @@ async def run_async( # type: ignore[override] # noqa: PLR0915
break_point: AgentBreakpoint | None = None,
snapshot: AgentSnapshot | None = None,
system_prompt: str | None = None,
user_prompt: str | None = None,
tools: ToolsType | list[str] | None = None,
confirmation_strategy_context: dict[str, Any] | None = None,
chat_message_store_kwargs: dict[str, Any] | None = None,
Expand All @@ -588,6 +606,8 @@ async def run_async( # type: ignore[override] # noqa: PLR0915
:param snapshot: A dictionary containing a snapshot of a previously saved agent execution. The snapshot contains
the relevant information to restart the Agent execution from where it left off.
:param system_prompt: System prompt for the agent. If provided, it overrides the default system prompt.
:param user_prompt: User prompt for the agent. If provided, it overrides the default user prompt and is
appended to the messages provided at runtime.
:param tools: Optional list of Tool objects, a Toolset, or list of tool names to use for this run.
:param confirmation_strategy_context: Optional dictionary for passing request-scoped resources
to confirmation strategies. Useful in web/server environments to provide per-request
Expand Down Expand Up @@ -644,6 +664,7 @@ async def run_async( # type: ignore[override] # noqa: PLR0915
streaming_callback=streaming_callback,
requires_async=True,
system_prompt=system_prompt,
user_prompt=user_prompt,
generation_kwargs=generation_kwargs,
tools=tools,
confirmation_strategy_context=confirmation_strategy_context,
Expand Down
2 changes: 2 additions & 0 deletions test/components/agents/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def test_to_dict(self, tools, monkeypatch, mock_mem0_memory_client):
}
],
"system_prompt": None,
"user_prompt": None,
"required_variables": None,
"exit_conditions": ["text"],
"state_schema": {},
"max_agent_steps": 100,
Expand Down