From c9c2d54963f9ba7803dc58a02d24d4c27d8972c3 Mon Sep 17 00:00:00 2001 From: agnieszka-m Date: Wed, 12 Nov 2025 13:15:54 +0100 Subject: [PATCH 1/3] Update Agent's docstrings --- haystack/components/agents/agent.py | 87 +++++++++++++++++++++++++---- 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/haystack/components/agents/agent.py b/haystack/components/agents/agent.py index b5e5b1a1e4..b52e401737 100644 --- a/haystack/components/agents/agent.py +++ b/haystack/components/agents/agent.py @@ -68,15 +68,21 @@ class _ExecutionContext: @component class Agent: """ - A Haystack component that implements a tool-using agent with provider-agnostic chat model support. + A tool-using Agent powered by a large language model. - The component processes messages and executes tools until an exit condition is met. - The exit condition can be triggered either by a direct text response or by invoking a specific designated tool. - Multiple exit conditions can be specified. + The Agent processes messages and calls tools until it meets an exit condition. + You can set one or more exit conditions to control when it stops. For example, it can stop after generating a response or after calling a tool. - When you call an Agent without tools, it acts as a ChatGenerator, produces one response, then exits. + Without tools, the Agent works like a standard LLM that generates text. It produces one response and then stops. - ### Usage example + ### Usage examples + + This is an example agent that: + 1. Searches for tipping customs in France. + 2. Uses a calculator to compute tips based on its findings. + 3. Returns the final answer with its context. + + ```python from haystack.components.agents import Agent from haystack.components.generators.chat import OpenAIChatGenerator @@ -137,13 +143,74 @@ def calculator(operation: str, a: float, b: float) -> float: messages=[ChatMessage.from_user("Calculate the appropriate tip for an €85 meal in France")] ) - # The agent will: - # 1. Search for tipping customs in France - # 2. Use calculator to compute tip based on findings - # 3. Return the final answer with context print(result["messages"][-1].text) ``` + This is a minimal Agent that has deepwiki's MCP server configured as its tool: + + ```yaml + components: + Agent: + type: haystack.components.agents.agent.Agent + init_parameters: + chat_generator: + init_parameters: + model: gpt-5 + type: haystack.components.generators.chat.openai.OpenAIChatGenerator + tools: + - type: haystack_integrations.tools.mcp.MCPToolset + data: + server_info: + type: haystack_integrations.tools.mcp.mcp_tool.StreamableHttpServerInfo + url: https://mcp.deepwiki.com/mcp + timeout: 900 + token: + tool_names: + - read_wiki_structure + - read_wiki_contents + - ask_question + eager_connect: false + _meta: + name: deepwiki + description: + tool_id: + system_prompt: "You are a deep research assistant. You create comprehensive research reports to answer to user's questions. You have deepwiki at your disposal. Use deepwiki to undersand, navigate, and explore software projects. " + exit_conditions: + state_schema: {} + max_agent_steps: 100 + streaming_callback: + raise_on_tool_invocation_failure: false + tool_invoker_kwargs: + DeepsetChatHistoryParser: + type: deepset_cloud_custom_nodes.parsers.chat_history_parser.DeepsetChatHistoryParser + init_parameters: {} + AnswerBuilder: + type: haystack.components.builders.answer_builder.AnswerBuilder + init_parameters: + pattern: + reference_pattern: + last_message_only: false + + connections: + - sender: DeepsetChatHistoryParser.messages + receiver: Agent.messages + - sender: Agent.messages + receiver: AnswerBuilder.replies + + max_runs_per_component: 100 + + metadata: {} + + inputs: + query: + - DeepsetChatHistoryParser.history_and_query + - AnswerBuilder.query + + outputs: + answers: AnswerBuilder.answers + + ``` + """ def __init__( From 91f6d6114856d87af46109028141f0137cc7a785 Mon Sep 17 00:00:00 2001 From: agnieszka-m Date: Wed, 12 Nov 2025 13:20:19 +0100 Subject: [PATCH 2/3] fix formatting --- haystack/components/agents/agent.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/haystack/components/agents/agent.py b/haystack/components/agents/agent.py index b52e401737..595828b3cb 100644 --- a/haystack/components/agents/agent.py +++ b/haystack/components/agents/agent.py @@ -70,8 +70,9 @@ class Agent: """ A tool-using Agent powered by a large language model. - The Agent processes messages and calls tools until it meets an exit condition. - You can set one or more exit conditions to control when it stops. For example, it can stop after generating a response or after calling a tool. + The Agent processes messages and calls tools until it meets an exit condition. + You can set one or more exit conditions to control when it stops. + For example, it can stop after generating a response or after calling a tool. Without tools, the Agent works like a standard LLM that generates text. It produces one response and then stops. @@ -82,7 +83,6 @@ class Agent: 2. Uses a calculator to compute tips based on its findings. 3. Returns the final answer with its context. - ```python from haystack.components.agents import Agent from haystack.components.generators.chat import OpenAIChatGenerator @@ -174,7 +174,10 @@ def calculator(operation: str, a: float, b: float) -> float: name: deepwiki description: tool_id: - system_prompt: "You are a deep research assistant. You create comprehensive research reports to answer to user's questions. You have deepwiki at your disposal. Use deepwiki to undersand, navigate, and explore software projects. " + system_prompt: "You are a deep research assistant. + You create comprehensive research reports to answer to user's questions. + You have deepwiki at your disposal. + Use deepwiki to undersand, navigate, and explore software projects. " exit_conditions: state_schema: {} max_agent_steps: 100 From 648f3c81308075dab67671b2223b52450feefd09 Mon Sep 17 00:00:00 2001 From: Darja Fokina Date: Wed, 12 Nov 2025 13:38:00 +0100 Subject: [PATCH 3/3] formatting upd --- haystack/components/agents/agent.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/haystack/components/agents/agent.py b/haystack/components/agents/agent.py index 595828b3cb..c2030114e4 100644 --- a/haystack/components/agents/agent.py +++ b/haystack/components/agents/agent.py @@ -71,7 +71,7 @@ class Agent: A tool-using Agent powered by a large language model. The Agent processes messages and calls tools until it meets an exit condition. - You can set one or more exit conditions to control when it stops. + You can set one or more exit conditions to control when it stops. For example, it can stop after generating a response or after calling a tool. Without tools, the Agent works like a standard LLM that generates text. It produces one response and then stops. @@ -174,10 +174,10 @@ def calculator(operation: str, a: float, b: float) -> float: name: deepwiki description: tool_id: - system_prompt: "You are a deep research assistant. - You create comprehensive research reports to answer to user's questions. - You have deepwiki at your disposal. - Use deepwiki to undersand, navigate, and explore software projects. " + system_prompt: "You are a deep research assistant. + You create comprehensive research reports to answer to user's questions. + You have deepwiki at your disposal. + Use deepwiki to understand, navigate, and explore software projects. " exit_conditions: state_schema: {} max_agent_steps: 100