@@ -102,6 +102,7 @@ func (g *geminiClient) convertMessages(messages []message.Message) []*genai.Cont
102102 }
103103
104104 case message.Tool:
105+ var toolParts []*genai.Part
105106 for _, result := range msg.ToolResults() {
106107 response := map[string]any{"result": result.Content}
107108 parsed, err := parseJSONToMap(result.Content)
@@ -121,16 +122,17 @@ func (g *geminiClient) convertMessages(messages []message.Message) []*genai.Cont
121122 }
122123 }
123124
124− history = append(history, &genai.Content{
125− Parts: []*genai.Part{
126− {
127− FunctionResponse: &genai.FunctionResponse{
128− Name: toolCall.Name,
129− Response: response,
130− },
131− },
125+ toolParts = append(toolParts, &genai.Part{
126+ FunctionResponse: &genai.FunctionResponse{
127+ Name: toolCall.Name,
128+ Response: response,
132129 },
133− Role: genai.RoleModel,
130+ })
131+ }
132+ if len(toolParts) > 0 {
133+ history = append(history, &genai.Content{
134+ Parts: toolParts,
135+ Role: genai.RoleUser,
134136 })
135137 }
136138 }
@@ -373,17 +375,7 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t
373375 Finished: true,
374376 }
375377
376− isNew := true
377− for _, existing := range toolCalls {
378− if existing.Name == newCall.Name && existing.Input == newCall.Input {
379− isNew = false
380− break
381− }
382− }
383−
384− if isNew {
385− toolCalls = append(toolCalls, newCall)
386− }
378+ toolCalls = append(toolCalls, newCall)
387379 }
388380 }
389381 } else {