@@ -632,13 +632,18 @@ func toolSelection(llm LLM, f Fragment, tools Tools, guidelines Guidelines, tool
632632 // No tool was selected, reasoning contains the response
633633 xlog .Debug ("[toolSelection] No tool selected" , "reasoning" , reasoning )
634634 o .statusCallback (reasoning )
635+ o .reasoningCallback ("No tool selected" )
635636 // TODO: reasoning in this case would be the LLM's response to the user, not the tool selection
636637 // But, ExecuteTools doesn't return ther response, but just executes the tools and returns the result of the tools.
637638 // In this way, we are wasting computation as the user will ask again the LLM for computing the response
638639 // (again, while we could have used the reasoning as it is actually a response if no tools were selected)
639640 return f , nil , true , nil
640641 }
641642
643+ if reasoning != "" {
644+ o .reasoningCallback (reasoning )
645+ }
646+
642647 xlog .Debug ("[toolSelection] Tool selected" , "tool" , selectedTool .Name , "reasoning" , reasoning )
643648 o .statusCallback (fmt .Sprintf ("Selected tool: %s" , selectedTool .Name ))
644649
@@ -701,22 +706,21 @@ func ExecuteTools(llm LLM, f Fragment, opts ...Option) (Fragment, error) {
701706 // If the tool reasoner is enabled, we first try to figure out if we need to call a tool or not
702707 // We ask to the LLM, and then we extract a boolean from the answer
703708 if o .toolReasoner {
704-
705709 // ToolReasoner will call guidelines and tools for the initial fragment
706710 toolReason , err := ToolReasoner (llm , f , opts ... )
707711 if err != nil {
708712 return f , fmt .Errorf ("failed to extract boolean: %w" , err )
709713 }
710714
711- o .statusCallback (f .LastMessage ().Content )
712-
713715 boolean , err := ExtractBoolean (llm , toolReason , opts ... )
714716 if err != nil {
715717 return f , fmt .Errorf ("failed extracting boolean: %w" , err )
716718 }
717719 xlog .Debug ("Tool reasoning" , "wants_tool" , boolean .Boolean )
718720 if ! boolean .Boolean {
719721 xlog .Debug ("LLM decided to not use any tool" )
722+ o .statusCallback ("Ended reasoning without using any tool" )
723+ o .reasoningCallback ("Ended reasoning without using any tool" )
720724 return f , ErrNoToolSelected
721725 }
722726 }
0 commit comments