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