spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

1.0.0-M8 PRE Using ChatClient.Builder to build the client does not correctly identify the tools after adding defaultTools

Open hbsjz-swl opened this issue 1 year ago • 9 comments

Bug description 1.0.0-M8 PRE Using ChatClient.Builder to build the client does not correctly identify the tools after adding defaultTools. Use the defaultToolCallbacks method to add the default tool to take effect

Environment jdk 17, SpringBoot3.4.2, SpringAI 1.0.0-M8 PRE

Steps to reproduce ` @Bean public ChatClient createChatClient(ChatClient.Builder builder, ToolCallbackProvider tools, ChatMemory chatMemory) {

    ChatClient.Builder chatClientBuilder = builder.defaultTools(tools.getToolCallbacks())
            .defaultSystem("""
                    You are an AI assistant integrated into the system. Your task is to help users complete various tasks. Please call the registered tools to complete the tasks according to the different questions asked by the users. You can use the tools to obtain information, perform operations or provide suggestions. Please make sure to use the most appropriate tools to meet the needs of users when answering their questions.
                    """)
            .defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build()
            );
    return chatClientBuilder.build();
}`

hbsjz-swl avatar May 07 '25 03:05 hbsjz-swl

我是同样的配置,遇到了别的问题, Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT) at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 689] (through reference chain: org.springframework.ai.openai.api.OpenAiApi$ChatCompletion["choices"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletion$Choice["message"]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage["tool_calls"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage$ToolCall["function"]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage$ChatCompletionFunction["arguments"])

liu-zhen-wei avatar May 07 '25 06:05 liu-zhen-wei

It used to work, but now it's behaving differently than expected as the version goes up?

Since getToolCallbacks is called in ToolCallbackProvider, it feels natural to use defaultToolCallbacks. Is there a particular aspect that seems problematic to you?

dev-jonghoonpark avatar May 07 '25 06:05 dev-jonghoonpark

String content = chatClient.prompt(query).call().content(); 使用这个方式调用mcp工具报错

liu-zhen-wei avatar May 07 '25 06:05 liu-zhen-wei

@liu-zhen-wei The issue seems to be different from the issue you are experiencing. If so, please create a separate issue.

dev-jonghoonpark avatar May 07 '25 06:05 dev-jonghoonpark

该问题似乎与您遇到的问题不同。如果是这样,请创建一个单独的 issue。

Has already been created

liu-zhen-wei avatar May 07 '25 06:05 liu-zhen-wei

It used to work, but now it's behaving differently than expected as the version goes up?

Since getToolCallbacks is called in ToolCallbackProvider, it feels natural to use defaultToolCallbacks. Is there a particular aspect that seems problematic to you?

@dev-jonghoonpark
This change is not stated in the official documentation, so can I assume that the defaultTools method should be marked as deprecated?

hbsjz-swl avatar May 07 '25 06:05 hbsjz-swl

我是同样的配置,遇到了别的问题, Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT) at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 689] (through reference chain: org.springframework.ai.openai.api.OpenAiApi$ChatCompletion["choices"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletion$Choice["message"]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage["tool_calls"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage$ToolCall["function"]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage$ChatCompletionFunction["arguments"])

嘿,朋友! 你是在手动触发mcp server吗 现在它最新版本好像 直接配置好默认的chatclient客户端以后 自动会调用函数

hbsjz-swl avatar May 07 '25 06:05 hbsjz-swl

我是同样的配置,遇到了别的问题, Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT) at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 689] (through reference chain: org.springframework.ai.openai.api.OpenAiApi$ChatCompletion["choices"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletion$Choice["message"]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage["tool_calls"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage$ToolCall["function"]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage$ChatCompletionFunction["arguments"])

嘿,朋友! 你是在手动触发mcp server吗 现在它最新版本好像 直接配置好默认的chatclient客户端以后 自动会调用函数

我是在同一个工程里面编写了mcp服务,然后在同一个功能里面用智能体调用的,之前M6版本通的,到M7和M8版本就开始报错了,前辈有经验的话给指导一下

liu-zhen-wei avatar May 07 '25 07:05 liu-zhen-wei

我是同样的配置,遇到了别的问题, Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type java.lang.String from Object value (token JsonToken.START_OBJECT) at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 689] (through reference chain: org.springframework.ai.openai.api.OpenAiApi$ChatCompletion["choices"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletion$Choice["message"]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage["tool_calls"]->java.util.ArrayList[0]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage$ToolCall["function"]->org.springframework.ai.openai.api.OpenAiApi$ChatCompletionMessage$ChatCompletionFunction["arguments"])

嘿,朋友! 你是在手动触发mcp server吗 现在它最新版本好像 直接配置好默认的chatclient客户端以后 自动会调用函数

我是在同一个工程里面编写了mcp服务,然后在同一个功能里面用智能体调用的,之前M6版本通的,到M7和M8版本就开始报错了,前辈有经验的话给指导一下

mcp server和 client应该是两个端点,互相调用 并且要有固定的端点配置的 ,如果只用FunctionCalling的话一个服务里边就可以实现,直接在chatClient.prompt().user(String question).tools(YouToolMethodClass).call(); 就可以实现 参阅下官方文档 https://docs.spring.io/spring-ai/reference/1.0/api/mcp/mcp-overview.html

hbsjz-swl avatar May 07 '25 07:05 hbsjz-swl