spring有多个对象时如何注入

java 复制代码
@Bean
	public ReactAgent chatbotReactAgent(ChatModel chatModel,
			ShellTool2 shellTool,
			ToolCallback executePythonCode,
			ToolCallback viewTextFile,
			MemorySaver memorySaver) {
		return xxx;

这个里面有两个ToolCallback,如何注入

java 复制代码
@Bean
	public ToolCallback executePythonCode() {
		return FunctionToolCallback.builder("execute_python_code", new PythonTool())
				.description(PythonTool.DESCRIPTION)
				.inputType(PythonTool.PythonRequest.class)
				.build();
	}

	// 把框架提供的 ReadFileTool 包装成名为 view_text_file 的读文件工具。
	@Bean
	public ToolCallback viewTextFile() {
		ReadFileTool readFileTool = new ReadFileTool();
		return FunctionToolCallback.builder("view_text_file", readFileTool)
				.description("View the contents of a text file. The file_path parameter must be an absolute path. " +
						"You can specify offset and limit to read specific portions of the file. " +
						"By default, reads up to 500 lines starting from the beginning of the file.")
				.inputType(ReadFileTool.ReadFileRequest.class)
				.build();
	}

spring对象注入

1.先按类型找;

2.如果同类型有多个,再按 Bean 名区分,默认函数名就是Bean的名字,也可以指定;

java 复制代码
@Bean("pythonToolCallback")
public ToolCallback executePythonCode() {
    return FunctionToolCallback.builder("execute_python_code", new PythonTool())
            .description(PythonTool.DESCRIPTION)
            .inputType(PythonTool.PythonRequest.class)
            .build();
}

3.如果还分不清,就用 @Qualifier 明确指定。

java 复制代码
@Qualifier("pythonToolCallback") ToolCallback executePythonCode
相关推荐
IT_陈寒12 分钟前
SpringBoot自动配置这个坑,我踩进去又爬出来了
前端·人工智能·后端
copyer_xyf1 小时前
Agent 流程编排
后端·python·agent
copyer_xyf1 小时前
Agent RAG
后端·python·agent
copyer_xyf1 小时前
【RAG】向量数据库:milvus
后端·python·agent
铁皮饭盒1 小时前
Bun 哪比 Node.js 快?
javascript·后端
copyer_xyf1 小时前
Agent 记忆管理
后端·python·agent
葫芦和十三8 小时前
图解 MongoDB 02|BSON:你以为存的是 JSON,其实是带类型的二进制
后端·mongodb·agent
葫芦和十三8 小时前
图解 MongoDB 01|文档数据库
后端·mongodb·agent
陈随易10 小时前
VSCode的Copilot扩展支持接入DeepSeek,Kimi了!
前端·后端·程序员
我不是外星人12 小时前
有了 Harness Engineering ,真的还需要研发工程师吗?
前端·后端·ai编程