Bug description When adding a MessageChatMemoryAdvisor to my chat client. I would expect it to persist all messages, including the tool calls that the model makes. However, when getting the final chatResponse, I can only see the user message and the final model response in the chat memory.

Environment Java 21, SpringAI M4, InMemoryChatMemory

Steps to reproduce 1. Create a chat client with at least one tool call and add a MessageChatMemoryAdvisor with an InMemoryChatMemory instance passed in to it. 2. Make a user query which invokes the tool call 3. Investigate the ChatMemory instance and see that only the user input and the model response are included in the history.

Expected behavior I expected to also be able to see the model tool calls in the ChatHistory

Comment From: leooooow

Yes, I've noticed that in the current code implementation, if the message type is 'tool', the process of calling the tool and sending the tool result to the ai model is done recursively internally, without being exposed externally.

//org.springframework.ai.openai.OpenAiChatModel#internalCall
if (!isProxyToolCalls(prompt, this.defaultOptions)
                && isToolCall(response, Set.of(OpenAiApi.ChatCompletionFinishReason.TOOL_CALLS.name(),
                        OpenAiApi.ChatCompletionFinishReason.STOP.name()))) {
    var toolCallConversation = handleToolCalls(prompt, response);
    // Recursively call the call method with the tool call message
    // conversation that contains the call responses.
    return this.internalCall(new Prompt(toolCallConversation, prompt.getOptions()), response);
        }

My current approach is to define a ToolWrapper and register it in the context, so that when a tool is called, it can persist messages of the 'tool' type.

@Override
    public String call(String functionInput, ToolContext toolContext) {

        String response = tool.call(functionInput, toolContext);
         saveToolResultMessage(toolContext, toolCallId, response);
        return response;
    }