Bug description When using in #stream() mode along with tools, the Anthropic Chat Model outputs that it "needs to use XYZ tool" before actually calling the tool and giving the final result. The result of the call is the response to the two prompts, the first one before passing tool results, and the second one with the tool results.

Environment Running on Spring AI 1.1.0-SNAPSHOT JDK 17 Using Anthropic model ; only passing the API key as a property

Steps to reproduce

  • Set up a project with Spring AI and Anthropic model
  • Add a simple tool
  • Call the in streaming mode with your tool:
ChatClient.create(chatModel).prompt(question)
        .tools(new WeatherTool())
        .stream()
        // ... consume response

The output contains too much info, for example:

I'd be happy to check the temperature in Paris for you. To do this, I need the specific latitude and longitude coordinates for Paris, France.The current temperature in Paris is 14.17°C (approximately 57.5°F). This is a mild temperature, typical of a cool evening in Paris. The weather is neither too hot nor too cold, making it comfortable for outdoor activities with a light jacket.

Expected behavior The final output of the console should read something like:

The current temperature in Paris is 14.17°C (approximately 57.5°F). This is a mild temperature, typical of a cool evening in Paris. The weather is neither too hot nor too cold, making it comfortable for outdoor activities with a light jacket.

Minimal Complete Reproducible example

Here's a repro project: https://github.com/Kehrlann/spring-ai-streamingtools-repro

  • Set your Anthropic key in the application.properties or in an env var ANTHROPIC_API_KEY
  • Run the project. It asks "What's the weather like in Paris?", and has fake tool that returns a random temperature
  • Observe the results in the console