spring-projects / spring-projects/spring-ai

In Spring AI, if a functioncall's return value doesn't match its description, it can trigger an infinite loop by repeatedly accumulating and calling the large model interface with the incorrect return value

Open
#2,383 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

link:
https://github.com/spring-projects/spring-framework/issues/34534

Spring AI defines a "functioncall". When the return value is inconsistent with the description, for example, if it's defined to "get the current date" but returns "我是一串中文" (which means "I am a string of Chinese" in English), the framework will repeatedly accumulate "我是一串中文" in the request, causing the large model interface to trigger an infinite loop. It will keep calling the large model interface repeatedly.

request:
http://localhost:8080/chat5?userInput=what day is tomorrow

functioncall:
`public class FunctionCallToolUtil {
public static final String DATETIME_PATTERN_M2 = "yyyy/MM/dd HH:mm";
@tool(description = "get current date")
public String getCurrentDateTime() {
// Date date = new Date();
// DateFormat dateFormat = new SimpleDateFormat(DATETIME_PATTERN_M2);
// return dateFormat.format(date);

return "我是一串中文";

}
}
`

controller:
` @GetMapping("/chat5")
ChatDataDto functionCall(@RequestParam("userInput") String userInput) {

String content = chatClient.prompt("与用户沟通")
        .user(userInput)
        .tools(new FunctionCallToolUtil())
        .call()
        .content();

ChatDataDto chatDataDto = new ChatDataDto();
chatDataDto.setText(content);
return chatDataDto;

}
`

process:

Image

Image

Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.

Expected Behavior

Current Behavior

Context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue through the mentioned controller functionCall entry point at /chat5 with the FunctionCallToolUtil returning "我是一串中文". Then trace the Spring AI function-call handling and request accumulation path; done means the incorrect return value no longer causes repeated large-model calls, with a regression test covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
ai, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.