-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
我们以一个小小的例子(就以官网的示例代码)演示一下,这里是阻塞式调用
@SpringBootTest
public class TestAgent {
@Autowired
// ChatModel chatModel;
DashScopeChatModel chatModel;
@Test
public void test() throws GraphRunnerException, InterruptedException {
ToolCallback toolCallback = FunctionToolCallback
.builder("currentWeather", new WeatherService())
.description("Get the weather in location")
.inputType(WeatherRequest.class)
.build();
ReactAgent agent = ReactAgent
.builder()
.name("my_agent")
.model(chatModel)
.tools(toolCallback)
.saver(new MemorySaver())
.build();
AssistantMessage message = agent.call("成都市今天天气怎么样");
System.out.println(message.getText());
}
他的结果根据当前天气信息,成都市今天的温度是30°C。这是一个比较温暖的天气,建议穿着轻薄透气的衣物,注意防晒和补充水分。
这是流式调用
@SpringBootTest
public class TestAgent {
@Autowired
// ChatModel chatModel;
DashScopeChatModel chatModel;
@Test
public void test() throws GraphRunnerException, InterruptedException {
ToolCallback toolCallback = FunctionToolCallback
.builder("currentWeather", new WeatherService())
.description("Get the weather in location")
.inputType(WeatherRequest.class)
.build();
ReactAgent agent = ReactAgent
.builder()
.name("my_agent")
.model(chatModel)
.tools(toolCallback)
.saver(new MemorySaver())
.build();
// AssistantMessage message = agent.call("成都市今天天气怎么样");
// System.out.println(message.getText());
Flux<NodeOutput> stream = agent.stream("成都市今天天气怎么样,单位用摄氏度");
stream.subscribe(System.out::println);
Thread.sleep(200000);
}
他的结果(太冗长了我直接截取最后一段)
NodeOutput{node=__END__, agent=my_agent, tokenUsage=null, state={"OverAllState":{"data":{"input":"成都市今天天气怎么样","messages":[{"messageType":"USER","metadata":{"messageType":"USER"},"media":[],"text":"成都市今天天气怎么样"},{"messageType":"ASSISTANT","metadata":{"finishReason":"STOP","search_info":"","role":"ASSISTANT","id":"64087ac9-647f-4876-8c13-85ad06a5b018","messageType":"ASSISTANT","reasoningContent":""},"toolCalls":[],"media":[],"text":"我需要知道您希望使用哪种温度单位来查看成都市的天气信息。请问您希望使用摄氏度(C)还是华氏度(F)?"}]}}}, subGraph=false}
这里AI被强行降智来回避这个问题,而当你在生产环境(使用redissaver不断地追问的时候)几乎包括deepseek也好,qwen也好,那个什么qlm也好,都会在正在为您(tool calling的函数描述)这一句话停止(是stream就断在这一步了)
就像这样
NodeOutput{node=__END__, agent=my_agent, tokenUsage=null, state={"OverAllState":{"data":{"input":"成都市今天天气怎么样,使用摄氏度","messages":[{"messageType":"USER","metadata":{"messageType":"USER"},"media":[],"text":"成都市今天天气怎么样,使用摄氏度"},{"messageType":"ASSISTANT","metadata":{"finishReason":"","search_info":"","role":"ASSISTANT","id":"e67ecbfa-6499-415e-a61f-e78516bea93a","messageType":"ASSISTANT","reasoningContent":""},"toolCalls":[],"media":[],"text":"我来帮您查询成都市今天的天气情况。\n\n\n"}]}}}, subGraph=false}
就在这个我来帮您查询这句中断了,没有下文了,当你在有上下文存储的场景下使用他只会装傻说“我刚才忘记调用工具了”(其实真实原因看起来更像流在调用工具的这一瞬间被掐死了)
Expected Behavior
希望开发者大大们能早日解决这个bug
Steps To Reproduce
这种情况下只能牺牲用户体验来阻塞式调用(拿到结果之后给前端流式也行吧)
Environment
Spring AI Alibaba version(s):1.1.0.0-M5Debug logs
No response
Anything else?
No response