@@ -58,6 +58,9 @@ type ToolResultHandler func(toolName, toolArgs, result string, isError bool)
5858// ResponseHandler is a function type for handling LLM responses
5959type ResponseHandler func (content string )
6060
61+ // ToolCallContentHandler is a function type for handling content that accompanies tool calls
62+ type ToolCallContentHandler func (content string )
63+
6164func firstChunkStreamToolCallChecker (_ context.Context , sr * schema.StreamReader [* schema.Message ]) (bool , error ) {
6265 defer sr .Close ()
6366
@@ -345,7 +348,7 @@ func (a *Agent) Stream(ctx context.Context, input []*schema.Message, opts ...com
345348
346349// GenerateWithLoop processes messages with a custom loop that displays tool calls in real-time
347350func (a * Agent ) GenerateWithLoop (ctx context.Context , messages []* schema.Message ,
348- onToolCall ToolCallHandler , onToolResult ToolResultHandler , onResponse ResponseHandler ) (* schema.Message , error ) {
351+ onToolCall ToolCallHandler , onToolResult ToolResultHandler , onResponse ResponseHandler , onToolCallContent ToolCallContentHandler ) (* schema.Message , error ) {
349352
350353 // Create a copy of messages to avoid modifying the original
351354 workingMessages := make ([]* schema.Message , len (messages ))
@@ -391,6 +394,11 @@ func (a *Agent) GenerateWithLoop(ctx context.Context, messages []*schema.Message
391394
392395 // Check if this is a tool call or final response
393396 if len (response .ToolCalls ) > 0 {
397+ // Display any content that accompanies the tool calls
398+ if response .Content != "" && onToolCallContent != nil {
399+ onToolCallContent (response .Content )
400+ }
401+
394402 // Handle tool calls
395403 for _ , toolCall := range response .ToolCalls {
396404 // Notify about tool call
0 commit comments