"Monitor tool execution behaviors, such as invoking a method before tool execution, invoking a method after tool execution, and invoking a method when an error occurs during execution. Will this feature be considered for future implementation?"
Comment From: zb-super
I want to do something before and after the tool is executed.
Comment From: zb-super
like this
/*
* @param prompt
* @param chatResponse
* @param pre 执行前
* @param after 执行后
* @return
/
ToolExecutionResult executeToolCalls(Prompt prompt, ChatResponse chatResponse,
Consumer
Comment From: tzolov
@zb-super as of RC1 spring ai provides observability support for the tool calling: https://docs.spring.io/spring-ai/reference/observability/index.html#_tool_calling The #3231 PR will update the toolcallign docs.
Comment From: zb-super
"My requirement is to manually manage the execution of function calls. After each function call is executed, I want to retrieve its name and provide feedback to the user. Will the new feature support this?"
Comment From: ThomasVitale
There are currently two options for achieving that:
- You can get full control over the tool execution using the User-Controlled Tool Execution strategy.
- You can define an
ObservationHandler
that listens to theToolCallingObservationContext
, giving you the necessary hooks to define callbacks to execute custom logic before and after each tool call. See Micrometer docs for more information.