Expected Behavior

It would be good to be able to easily connect function calls with user prompts that trigger them or with assistant responses that were generated based on these function calls. It would be especially beneficial for chats with memory.

Current Behavior

Currently some implementations deep down use history of function calls (a.k.a. tool calls) that were used in process of answering user's question, but it is hard to get these with IDs of messages they are connected to.

Context

Use-case for this feature: Often it would be beneficial if end-users of chat tools that are using Spring AI in the backend could validate what function calls (and with what parameters) were used in order to answer their questions instead of accepting answers blindly as if they were coming from some black box.

I believe that currently this is not easy to implement this feature in Spring AI (in case of integration with OpenAI I had to use AOP, which I consider kind of last resort solution).

Comment From: tzolov

@kkolago this is a good suggestion. With the introduction of the ToolContext we can insert the current function calling conversation history with a special key. Then you can define your BiFunction and obtain the conversation history from the toolContext. What do yo thing?

Comment From: kkolago-discovery

@tzolov It sounds like a really nice and generic way of doing this thing, that would be easy to customize (much better than my current "hack" using AOP). I really like this idea!

Comment From: tzolov

@tzolov It sounds like a really nice and generic way of doing this thing, that would be easy to customize (much better than my current "hack" using AOP). I really like this idea!

Great! Here is the draft: https://github.com/spring-projects/spring-ai/pull/1752 Would it help for your use cases? We still need to decide if the conversation would aways be part of the context of will be optional.