96SEO 2026-09-06 17:07 17
视频讲解请参考: 从源码请参考来看,
AI 模型调用的实例类接口。

/**
* 表示一个工具的执行能被一个 AI 模型触发。*/
public interface ToolCallback {
/** AI 模型用工具的描述来决定什么时候和如何调用这个 Tool */
ToolDefinition getToolDefinition;/** 提供关于如何处理该工具的附加信息的元数据 */
default ToolMetadata getToolMetadata {
return ToolMetadata.builder.build;}
/** 使用给定的参数一起执行工具并返回结果并发送给 AI 模型。话说回来,*/
String call;/** 使用给定的参数一起执行工具并返回结果并发送给 AI 模型。*/
default String call {
if .isEmpty) {
logger.info("By default tool context is not used。"
+ "override method 'call' to support use of tool context."
+ "Review ToolCallback implementation for {}",getToolDefinition.name);}
return call;怎么说呢,}
}
Spring AI 有 FunctionToolCallback 和 MethodToolCallback 两个实现。
ToolDefinition 接口提供了 AI model 所需的信息,包括 tool 名称、描述和输入 schema。ToolCallback 实现必须提供 ToolDefinition 实例来定义 tool。
public interface ToolDefinition {
/**
* The tool name. Unique within tool set provided to a model.
* 工具名称,在提供给一个模型的集合中是唯一的
*/
String name;/**
* The tool description,used by AI model to determine what tool does.
* 工具描述。给模型用于决定这个工具是做什么的
*/
String description;不过,/**
* The schema of parameters used to call tool.
* 用来调用tool 的参数的结构
*/
String inputSchema;/** Create a default {@link ToolDefinition} builder. */
static DefaultToolDefinition.Builder builder { return DefaultToolDefinition.builder;}
}
Schema 用于理解如何调用 tool,并准备调用 tool 的参数。Spring AI schema 的支持。JSONSchema 是作为 ToolDefinition 的一部分进行提供的。
格式、允许什么值等。这对于帮助 model 理解输入 schema 还有如何使用它很有用。Spring AI 使用以下注解之一为输入参数生成描述提供内置支持:
Tool call 的结果使用 ToolCallResultConverter 序列化,接下来发给 AI model。
/**
* A functional interface to convert tool call results to a String that can be sent back
* to AI model.
*
* @author Thomas Vitale
* @since .
*/
@FunctionalInterface
public interface ToolCallResultConverter {
/**
* Given an Object returned by a tool,convert it to a String compatible with
* given class type.
*/
String convert;}
将tool 的结果转换成 String 类型返回。默认使用的是 DefaultToolCallResultConverter 序列化 JSON,但你也可以通过实现 ToolCallResultConverter 接口自定义自己的结果转换器。
可以通过注解 @Tool .resultConverter 属性为某个方法指定自定义转换器。
不过,
public class CustomerTools {
@Tool(
description = "获取客户信息,输入参数是使用者 id,类型是 long,必须输入"。resultConverter = CustomToolCallResultConverter.class
)
public Customer getCustomerInfo{
//模拟通过数据库查询
Customer customer = new Customer;customer.setId;customer.setAge;customer.setUserName;return customer;}
}
import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jackson.databind.ObjectMapper;import org.jetbrains.annotations.Nullable;import org.springframework.ai.tool.execution.ToolCallResultConverter;import java.lang.reflect.Type;public class CustomToolCallResultConverter implements ToolCallResultConverter {
private final ObjectMapper objectMapper = new ObjectMapper;@Override
public String convert {
if {
return "No customer found";}
if {
try {
// 推荐方式:JSON 格式
return objectMapper.writeValueAsString;} catch {
return "Error converting customer data: " + e.getMessage;}
}
// 默认处理其他类型
return result.toString;}
}
通过设置 `MethodToolCallback.Builder.toolCallResultConverter` - 为特定方法指定自定义转换器。
Method method = ReflectionUtils.findMethod(CustomerTools.class。"getCustomerInfo",Long.class);MethodToolCallback customerToolCallback =
MethodToolCallback.builder
.toolDefinition(
ToolDefinition.builder
.description
.inputSchema)
.name
.build)
.toolMethod
.toolObject)
.toolCallResultConverter)
.build;
注解方式这方面,
public class CustomerTools {
@Tool( description = "获取客户信息。输入参数是使用者 id",resultConverter = Custom...,returnDirect = true // 设置直接返回 ) public Customer getCustomerInfo{ ... } } ';
This answer was generated by ChatGPT
Please let me know if re's anything else I can help you with!
Sorry for confusion earlier!
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback