How to force the assistant to use a tool?

Describe the problem/error/question

I would like to know if there is any way to force the execution of a tool by the Agent.

similar to the documentation below

  1. To force the model to always call one or more functions, you can set tool_choice: "required". The model will then always select one or more function(s) to call. This is useful for example if you want the model to pick between multiple actions to perform next.
  2. To force the model to call a specific function, you can set tool_choice: {"type": "function", "function": {"name": "my_function"}}.
  3. To disable function calling and force the model to only generate a user-facing message, you can either provide no tools, or set tool_choice: "none".

https://platform.openai.com/docs/guides/function-calling

Please share your workflow

Information on your n8n setup

  • n8n version: 1.55.3
  • Database (default: SQLite): Postgress
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu

@felippelima126 Why not use a tools agent? Its much easier to do that

2 Likes

I’m using this method now…

However, sometimes the agent doesn’t execute the tool to fetch “context” from my vector storage, especially for generic questions like “How to open our webmail?”

When the agent already has a (generic) answer, it doesn’t execute the tool. For now, I’m retrieving the context beforehand and sending everything to the agent.

With AI a lot matters. A slight change in prompt can result in a totally different answer. Am pretty sure in your case you will get the generic response. Why? You have not instructed your AI not to give you generic responses

That is a generic question and so a general answer will be given

Try this in the prompt

Always respond with data from our database. If you dont know the answer, never make one up,instead, respond back to the user asking for more context

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.