Skip to content

Agent component has an Optional 'tools' init param, but fails if no tool is provided #9220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danielescaramuzzi opened this issue Apr 11, 2025 · 4 comments · Fixed by #9230
Closed
Assignees
Labels
P1 High priority, add to the next sprint type:bug Something isn't working

Comments

@danielescaramuzzi
Copy link
Contributor

Describe the bug
Hey there! Not sure it's a bug, but I need some clarifications.
If I simply do:

import os
os.environ["AZURE_OPENAI_API_KEY"] = "***"
os.environ["AZURE_OPENAI_ENDPOINT"] = "***"

from haystack.components.generators.chat import AzureOpenAIChatGenerator
from haystack.components.agents import Agent

agent = Agent(chat_generator=AzureOpenAIChatGenerator())

I obtain:

File "***/main.py", line 9, in <module>
    agent = Agent(chat_generator=AzureOpenAIChatGenerator())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***/.venv/lib/python3.12/site-packages/haystack/core/component/component.py", line 268, in __call__
    instance = super().__call__(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***/.venv/lib/python3.12/site-packages/haystack/components/agents/agent.py", line 131, in __init__
    self._tool_invoker = ToolInvoker(tools=self.tools, raise_on_failure=self.raise_on_tool_invocation_failure)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***/.venv/lib/python3.12/site-packages/haystack/core/component/component.py", line 268, in __call__
    instance = super().__call__(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***/.venv/lib/python3.12/site-packages/haystack/components/tools/tool_invoker.py", line 132, in __init__
    raise ValueError("ToolInvoker requires at least one tool.")
ValueError: ToolInvoker requires at least one tool.

Expected behavior
If tools are Optional, I should be able to create an Agent without tools.

System:

  • Haystack version (commit or version number): 2.12.1
@sjrl sjrl added type:bug Something isn't working P1 High priority, add to the next sprint labels Apr 11, 2025
@sjrl
Copy link
Contributor

sjrl commented Apr 11, 2025

Hey @danielescaramuzzi thanks for catching this! You're right this is a bug, just trying to think if it makes sense to allow Tools to be optional or not. My impression is that if you are running an agent with no Tools then probably it's best to use a ChatGenerator directly at that point.

But it could easily be set up so that Agent acts like a ChatGenerator if no tools are supplied as well.

@LastRemote
Copy link
Contributor

My impression is that if you are running an agent with no Tools then probably it's best to use a ChatGenerator directly at that point.

Want to drop my two cents here from my previous experience. In some cases an agent can actually have no tool call capabilities while still benefit from a state/loop mechanism. For example, you can set up an agent where it reads a webpage chunk by chunk, while maintaining a "reading note" in the loop. Depending on the setup, we can make the agent call an early stop if it feels like these is nothing else to learn, and of course the natural exit is when the agent has gone through all the content.

@sjrl
Copy link
Contributor

sjrl commented Apr 15, 2025

Sounds good! We opted to allow the behavior of no tools. You can check it out in the PR #9230

@LastRemote
Copy link
Contributor

@sjrl Thanks for the ping. I left a comment there as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 High priority, add to the next sprint type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants