Skip to content

fix: Allow Agent to run with no tools #9230

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

fix: Allow Agent to run with no tools #9230

wants to merge 7 commits into from

Conversation

sjrl
Copy link
Contributor

@sjrl sjrl commented Apr 14, 2025

Related Issues

Proposed Changes:

Updates the init and run logic of Agent to truly allow Tools to be optional. This means an Agent can be run with no Tools now which makes it act like a normal ChatGenerator.

How did you test it?

Added a test

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I documented my code
  • I ran pre-commit hooks and fixed any issue

@sjrl sjrl requested review from a team as code owners April 14, 2025 09:47
@sjrl sjrl requested review from dfokina and Amnah199 and removed request for a team April 14, 2025 09:47
@coveralls
Copy link
Collaborator

coveralls commented Apr 14, 2025

Pull Request Test Coverage Report for Build 14472404591

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 11 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.003%) to 90.317%

Files with Coverage Reduction New Missed Lines %
components/agents/agent.py 11 90.63%
Totals Coverage Status
Change from base Build 14471323317: 0.003%
Covered Lines: 10661
Relevant Lines: 11804

💛 - Coveralls

---
fixes:
- |
Now when you call an Agent with no tools it acts like a ChatGenerator which means it returns a ChatMessage based on a user input.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can update the Agent's docstring to also highlight this update.

Copy link
Contributor

@Amnah199 Amnah199 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG! Just a small comment.

@LastRemote
Copy link
Contributor

LastRemote commented Apr 15, 2025

Sorry, one general question for the current behavior:

So the current tool_invoker would ignore the embedded tools inside of the chat generator? Not sure if this is intended but the chat generator might include some tools upon initialization (e.g. https://github.com/deepset-ai/haystack/blob/main/haystack/components/generators/chat/openai.py#L90). Not sure how we should handle this in the agent loop.

So even self.tools appear to be empty, there could still be tool_calls according to self.chat_generator.tools.

@sjrl
Copy link
Contributor Author

sjrl commented Apr 15, 2025

Sorry, one general question for the current behavior:

So the current tool_invoker would ignore the embedded tools inside of the chat generator? Not sure if this is intended but the chat generator might include some tools upon initialization (e.g. https://github.com/deepset-ai/haystack/blob/main/haystack/components/generators/chat/openai.py#L90). Not sure how we should handle this in the agent loop.

So even self.tools appear to be empty, there could still be tool_calls according to self.chat_generator.tools.

Good catch. That is the intended behavior. The Agent component was set up in a way that the Tools should be provided to the Agent's init params and not the ChatGenerators.

But you're right we should make that more explicit that the tools defined in the underlying ChatGenerator will be ignored.

@github-actions github-actions bot added the type:documentation Improvements on the docs label Apr 15, 2025
Comment on lines 33 to 34
When you call an Agent without any tools it acts like a ChatGenerator. It will exit after generating a text
response.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dfokina Could you give this docstring a review?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to order it a bit: "When you call an Agent without tools, it acts as a ChatGenerator, produces one response, then exits."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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