spring-projects / spring-ai

An Application Framework for AI Engineering
https://docs.spring.io/spring-ai/reference/1.0-SNAPSHOT/index.html
Apache License 2.0
3.03k stars 752 forks source link

Concurrent Function/Tool Invocation #941

Open Grogdunn opened 3 months ago

Grogdunn commented 3 months ago

I admit, need to triage better.

In a multithread application with multiple Function call Invocation the GPT can lead to share information between threads.

In a my application I've the same function with different lambda inside it, and if GPT make the funciton call "at same time" sometimes the lambdas are "swapped" or data are "wrong".

To resolve that I've, at the moment, called each function with different lambda with a combination of thread name, function name, lambda scope. So in this manner the "function registry" has a different copy of a funciton for each thread/invocation.

Need more testing and reasoning about it.

tzolov commented 2 months ago

Hey @Grogdunn , were you able to reproduce this potential issue?

Grogdunn commented 2 months ago

I've missing to update this issue. But it's my design error on function call for a project. I use Function to extract data and add to thread bound Lists. But when I create that functions I pass the reference to lists, but the "last" thread ovverride the reference to previous one, so the data are mixed.

The only improvements to spring-ai project are to explicit says in documentation/javadoc that function are resused by name so pay attention to mulithread envirionment.

@tzolov If no more information are needed feel free to close this issue :wink:

csterwa commented 1 month ago

@tzolov needs to follow up on how we can support the use case of getting the arguments of function to invoke but don't invoke or have control over invocation.