diff --git a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatClient.java b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatClient.java index 98a25025d..9b7e19de0 100644 --- a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatClient.java +++ b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/MistralAiChatClient.java @@ -250,7 +250,8 @@ public class MistralAiChatClient extends // message. for (ToolCall toolCall : responseMessage.toolCalls()) { - var functionName = toolCall.function().name(); + String id = toolCall.id(); + String functionName = toolCall.function().name(); String functionArguments = toolCall.function().arguments(); if (!this.functionCallbackRegister.containsKey(functionName)) { @@ -260,8 +261,8 @@ public class MistralAiChatClient extends String functionResponse = this.functionCallbackRegister.get(functionName).call(functionArguments); // Add the function response to the conversation. - conversationHistory - .add(new ChatCompletionMessage(functionResponse, ChatCompletionMessage.Role.TOOL, functionName, null)); + conversationHistory.add(new ChatCompletionMessage(functionResponse, ChatCompletionMessage.Role.TOOL, + functionName, null, id)); } // Recursively call chatCompletionWithTools until the model doesn't call a diff --git a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java index 5732c871a..16f2465c5 100644 --- a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java +++ b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java @@ -452,6 +452,8 @@ public class MistralAiApi { * types. * @param toolCalls The tool calls generated by the model, such as function calls. * Applicable only for {@link Role#ASSISTANT} role and null otherwise. + * @param toolCallId Tool call that this message is responding to. Only applicable for + * the {@link Role#TOOL} role and null otherwise. */ @JsonInclude(Include.NON_NULL) public record ChatCompletionMessage( @@ -459,9 +461,22 @@ public class MistralAiApi { @JsonProperty("content") String content, @JsonProperty("role") Role role, @JsonProperty("name") String name, - @JsonProperty("tool_calls") List toolCalls) { + @JsonProperty("tool_calls") List toolCalls, + @JsonProperty("tool_call_id") String toolCallId) { // @formatter:on + /** + * Message comprising the conversation. + * @param content The contents of the message. + * @param role The role of the messages author. Could be one of the {@link Role} + * types. + * @param toolCalls The tool calls generated by the model, such as function calls. + * Applicable only for {@link Role#ASSISTANT} role and null otherwise. + */ + public ChatCompletionMessage(String content, Role role, String name, List toolCalls) { + this(content, role, name, toolCalls, null); + } + /** * Create a chat completion message with the given content and role. All other * fields are null. @@ -469,7 +484,7 @@ public class MistralAiApi { * @param role The role of the author of this message. */ public ChatCompletionMessage(String content, Role role) { - this(content, role, null, null); + this(content, role, null, null, null); } /**