spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

DefaultChatClient#autoRegisterToolCallingAdvisor fails to register the ToolCallingAdvisor for dynamically injected tools

Open tzolov opened this issue 5 months ago • 4 comments

Currently theDefaultChatClient#autoRegisterToolCallingAdvisor() will register the ToolCallingAdvisor only if there are existing ToolCallbacks defined by the time the .call()/.stream() is invoked.

There are use cases where tool can be defined dynamically at run-time by some advisor. If there are no other explicitly defined tools then the ToolCallingAdvisor won't be provisioned and there will be no support for the dynamically registered tools.

To prevent this we should consider always auto-registering the ToolCallingAdvisor unless the spring.ai.chat.client.tool-calling.enabled=false or (.advisors(AdvisorParams.toolCallingAdvisorAutoRegister(false))) are set.

WORKAROUND: At the moment, the workaround is to register the ToolCallingAdvisor explicitly or ensure that there is at least one (dummy) tool that will trigger the auto-registration.

tzolov avatar Jun 07 '26 13:06 tzolov

Hi @tzolov, this looks like a good issue to work on.

If the intended direction is to always auto-register ToolCallingAdvisor unless tool calling is explicitly disabled via spring.ai.chat.client.tool-calling.enabled=false or AdvisorParams.toolCallingAdvisorAutoRegister(false), I’d be happy to take this and add focused test coverage for the dynamic-tool case.

codingkiddo avatar Jun 07 '26 13:06 codingkiddo

I’d like to take this one. I’ve identified the likely fix in DefaultChatClient#autoRegisterToolCallingAdvisor()

Grandys avatar Jun 07 '26 17:06 Grandys

@codingkiddo , @Grandys, please don't rush with PRs.

As @codingkiddo suggested the obvious solution is to always register the ToolCallingAdvisor unless disabled. We have already a working draft for this approach but will be interesting to explore for side effects or different ideas.

tzolov avatar Jun 07 '26 17:06 tzolov

Thanks @tzolov, understood.

I won’t rush with a PR. I’ll wait for the team’s direction or draft.

Meanwhile, I can help by exploring possible side effects around always registering ToolCallingAdvisor, especially cases like:

  • tool calling explicitly disabled via spring.ai.chat.client.tool-calling.enabled=false
  • AdvisorParams.toolCallingAdvisorAutoRegister(false)
  • chat clients without static tools
  • dynamic tools added by another advisor
  • ensuring advisor ordering remains unchanged

Happy to add focused test coverage once the preferred approach is confirmed.

codingkiddo avatar Jun 08 '26 04:06 codingkiddo