Skip to content

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 #2383

@leizhonghao

Description

@leizhonghao

link:
spring-projects/spring-framework#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions