How to expose the tools defined by ToolCalling in Springai to users? What tools are available?
`@Configuration(proxyBeanMethods = false) public class WeatherTools { public static final String CURRENT_WEATHER_TOOL = "currentWeather";
WeatherService weatherService = new WeatherService();
/**
* mock tools
* @return
*/
@Bean(CURRENT_WEATHER_TOOL)
@Description("get weather")
Function<WeatherRequest, WeatherResponse> currentWeather() {
return weatherService;
}
}` Just like this, how can I let users know that I have this current Weather tool and its function description, similar to MCP tools
'@Configuration(proxyBeanMethods = false) public class WeatherTools { public static final String CURRENT_WEATHER_TOOL = “currentWeather”;
WeatherService weatherService = new WeatherService(); /** * mock tools * @return */ @Bean(CURRENT_WEATHER_TOOL) @Description("get weather") Function<WeatherRequest, WeatherResponse> currentWeather() { return weatherService; }}`就这样,如何让用户知道我有这个当前的天气工具及其功能说明,类似于 MCP 工具
Isn't it necessary to encapsulate all the tool information for the request before sending the message? You can render it for the front end at this time(my English is not very good. This is the Chinese translation. If there are any unclear expressions, please let me know and I will supplement them in time.)
'@configuration(proxyBeanMethods = false) public class WeatherTools { public static final String CURRENT_WEATHER_TOOL = “currentWeather”;
WeatherService weatherService = new WeatherService(); /** * mock tools * @return */ @Bean(CURRENT_WEATHER_TOOL) @Description("get weather") Function<WeatherRequest, WeatherResponse> currentWeather() { return weatherService; }}`就这样,如何让用户知道我有这个当前的天气工具及其功能说明,类似于 MCP 工具
Isn't it necessary to encapsulate all the tool information for the request before sending the message? You can render it for the front end at this time(my English is not very good. This is the Chinese translation. If there are any unclear expressions, please let me know and I will supplement them in time.)
show me some code,thanks
'@configuration(proxyBeanMethods = false) public class WeatherTools { public static final String CURRENT_WEATHER_TOOL = “currentWeather”;
WeatherService weatherService = new WeatherService(); /** * mock tools * @return */ @Bean(CURRENT_WEATHER_TOOL) @Description("get weather") Function<WeatherRequest, WeatherResponse> currentWeather() { return weatherService; }}`就这样,如何让用户知道我有这个当前的天气工具及其功能说明,类似于 MCP 工具
在发送消息之前,难道不需要封装请求的所有工具信息吗?这个时候可以渲染给前端了(我的英语不太好。这是中文翻译。如有不清楚的表达方式,请告知,我会及时补充。
给我看一些代码,谢谢
// 获取最新的tools
ToolCallback[] currentTools = toolCallbackManager.getCurrentToolCallbacks();
SimpleLoggerAdvisor customLogger = new SimpleLoggerAdvisor(
request -> "自定义请求:" + request.userText(),
response -> "自定义响应:" + response.getResult(),
1
);
StringBuilder contentBuilder = new StringBuilder();
AtomicReference<String> currentTool = new AtomicReference<>("");
Flux<String> flux = chatClient.prompt(systemPromptManager.getSmexSystemPrompt(requestBody.getUserCode()))
.tools(currentTools)
.advisors(customLogger)
.toolContext(toolContext)
.messages(messages)
.stream()
.content();
Just like this, when sending messages to large models, we need to carry the message of the tool. Naturally, you should obtain all the tool information. In addition, I have set up an mcphub platform. It can manage the tool information of all systems and isolate it. The principle is that when the project starts, it will scan the methods containing specific annotations and register them on the platform. Then, mcphub will uniformly manage these methods and display them(my English is not very good. This is the Chinese translation. If there are any unclear expressions, please let me know and I will supplement them in time.)