@@ -102,6 +102,7 @@ func (g *geminiClient) convertMessages(messages []message.Message) []*genai.Cont
104 case message.Tool:
104 case message.Tool:
105+ var toolParts []*genai.Part
105 for _, result := range msg.ToolResults() {
106 for _, result := range msg.ToolResults() {
106 response := map[string]any{"result": result.Content}
107 response := map[string]any{"result": result.Content}
107 parsed, err := parseJSONToMap(result.Content)
108 parsed, err := parseJSONToMap(result.Content)
@@ -121,16 +122,17 @@ func (g *geminiClient) convertMessages(messages []message.Message) []*genai.Cont
124− history = append(history, &genai.Content{
125+ toolParts = append(toolParts, &genai.Part{
125− Parts: []*genai.Part{
127− FunctionResponse: &genai.FunctionResponse{
126+ FunctionResponse: &genai.FunctionResponse{
128− Name: toolCall.Name,
127+ Name: toolCall.Name,
129− Response: response,
128+ Response: response,
132+ if len(toolParts) > 0 {
133+ history = append(history, &genai.Content{
133− Role: genai.RoleModel,
135+ Role: genai.RoleUser,
@@ -373,17 +375,7 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t
373 Finished: true,
375 Finished: true,
377− for _, existing := range toolCalls {
378− if existing.Name == newCall.Name && existing.Input == newCall.Input {
385− toolCalls = append(toolCalls, newCall)
378+ toolCalls = append(toolCalls, newCall)