Class ToolConverter

java.lang.Object
com.google.adk.models.springai.ToolConverter

public class ToolConverter extends Object
能够在 ADK 格式和 Spring AI 工具/函数格式之间进行双向转换。

这个转换器可以处理 ADK 之间的文本翻译。 BaseTool/FunctionDeclaration “Format and Spring AI” ToolCallback 表示方法(包括数据模式),以及转换过程。 ToolContext propagation.

  • 嵌套类概述

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    一个用于存储工具信息的简单元数据容器。
  • 字段摘要

    Fields
    Modifier and Type
    Field
    Description
    static final String
    用于传递 ADK 的键(key) ToolContext 通过 Spring AI 的工具上下文(tool context)映射来实现。
  • 构造函数概述

    Constructors
    Constructor
    Description
     
  • 方法概述

    Modifier and Type
    Method
    Description
    com.google.genai.types.Schema
    convertSchemaFromSpringAi(@Nullable String jsonSchema)
    将 Spring AI 的 JSON 方案字符串解析为 ADK 格式的数据。 Schema.
    com.google.genai.types.Schema
    将 Spring AI 的参数模式映射转换为 ADK 格式。 Schema.
    convertSchemaToSpringAi(com.google.genai.types.Schema schema)
    将 ADK 数据结构转换为与 Spring AI 兼容的参数结构。
    convertToAdkTool(org.springframework.ai.tool.ToolCallback toolCallback)
    将一个 Spring AI 对象转换为另一种格式或结构。 ToolCallback 发送到一个 ADK(Application Development Kit,应用程序开发工具包) BaseTool.
    convertToAdkTools(Collection<? extends org.springframework.ai.tool.ToolCallback> toolCallbacks)
    将一组 Spring AI 对象进行转换(即对它们进行处理或操作)。 ToolCallback将 `s` 添加到 ADK 的列表中 BaseTools.
    convertToAdkToolset(org.springframework.ai.tool.ToolCallbackProvider toolCallbackProvider)
    将一个 Spring AI 对象转换为另一种格式或结构。 ToolCallbackProvider 发送到一个 ADK(Application Development Kit,应用程序开发工具包) BaseToolset 每当代理(agent)列出其使用的工具时,系统都会向相应的工具提供商(provider)发送查询请求;因此,所使用的工具集(toolset)会自动更新为使用那些工具提供商提供的最新工具。
    Optional<org.springframework.ai.tool.ToolCallback>
    将一个单独的 ADK 文件转换为其他格式或用途。 BaseTool 发送到 Spring AI ToolCallback.
    List<org.springframework.ai.tool.ToolCallback>
    将 ADK 工具转换为 Spring AI ToolCallback 格式,以便进行工具调用;同时会跳过那些没有相应声明(即没有相应配置或定义)的工具。
    使用 ADK 工具创建一个工具注册表,用于内部跟踪。

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详情

    • ADK_TOOL_CONTEXT_KEY

      public static final String ADK_TOOL_CONTEXT_KEY
      用于传递 ADK 的键(key) ToolContext 通过 Spring AI 的工具上下文(tool context)映射来实现。
      See Also:
  • 构造函数详细信息

    • ToolConverter

      public ToolConverter()
  • 方法详细信息(Method Details)

    • createToolRegistry

      public Map<String, ToolConverter.ToolMetadata> createToolRegistry(Map<String,BaseTool> tools)
      使用 ADK 工具创建一个工具注册表,用于内部跟踪。

      该方法提供了一种跟踪可用工具的方式;不过,Spring AI工具的调用集成功能将在后续版本中得到进一步优化/增强。

      Parameters:
      tools - Map of ADK tools to process
      Returns:
      Map of tool names to their metadata
    • convertSchemaToSpringAi

      public Map<String,Object> convertSchemaToSpringAi(com.google.genai.types.Schema schema)
      将 ADK 数据结构转换为与 Spring AI 兼容的参数结构。

      将……映射到……;将……对应到…… type, description, properties, required, enum 和 items `keywords`(关键词)properties 值与…… items (以递归的方式)。 其他 JSON-Schema 关键字(例如……) nullable, anyOf, format这些内容尚未被转移(或:这些内容还没有被继承/延续)。

      Parameters:
      schema - The ADK schema to convert
      Returns:
      A Map representing the Spring AI compatible schema
    • convertSchemaFromSpringAi

      public com.google.genai.types.Schema convertSchemaFromSpringAi(Map<String,Object> springAiSchema)
      将 Spring AI 的参数模式映射转换为 ADK 格式。 Schema.

      地图 type, description, properties, required, enum以及 items 以递归的方式处理缺失的数组(即当某个数组元素缺失时,系统会自动使用默认值来填充该位置)。 items 给……;发送到…… STRING “and” “narrowing” required 与声明的内容一致(或:与预先定义的内容相匹配)。 properties与 Python ADK 一样, $ref 该值会被解析为一个指向根模式的 JSON 指针;如果无法解析为 JSON 指针,则会被视为根模式中的最后一个部分(即根模式中的最后一个字符串或数据元素)。 $defs 或者 definitions; 那些标有“keys”字样的选项…… $ref 覆盖所引用的模式(schema)后,原本的循环引用(circular reference)就会变成一个独立的对象模式(object schema)。

      Parameters:
      springAiSchema - The Spring AI schema map to convert
      Returns:
      The converted ADK Schema
    • convertSchemaFromSpringAi

      public com.google.genai.types.Schema convertSchemaFromSpringAi(@Nullable String jsonSchema)
      将 Spring AI 的 JSON 方案字符串解析为 ADK 格式的数据。 Schema.
      Parameters:
      jsonSchema - The JSON Schema string (e.g. from ToolDefinition.inputSchema())
      Returns:
      The converted ADK Schema, or an empty object schema if jsonSchema is null or blank
      Throws:
      IllegalArgumentException - if jsonSchema is not valid JSON
    • convertToSpringAiTool

      public Optional<org.springframework.ai.tool.ToolCallback> convertToSpringAiTool(BaseTool tool)
      将一个单独的 ADK 文件转换为其他格式或用途。 BaseTool 发送到 Spring AI ToolCallback.
      Parameters:
      tool - The ADK tool to convert
      Returns:
      An Optional containing the converted ToolCallback, or empty if the tool has no declaration
    • convertToSpringAiTools

      public List<org.springframework.ai.tool.ToolCallback> convertToSpringAiTools(Map<String,BaseTool> tools)
      将 ADK 工具转换为 Spring AI ToolCallback 格式,以便进行工具调用;同时会跳过那些没有相应声明(即没有相应配置或定义)的工具。
      Parameters:
      tools - Map of ADK tools to convert
      Returns:
      List of Spring AI ToolCallback objects
    • convertToAdkTool

      public BaseTool convertToAdkTool(org.springframework.ai.tool.ToolCallback toolCallback)
      将一个 Spring AI 对象转换为另一种格式或结构。 ToolCallback 发送到一个 ADK(Application Development Kit,应用程序开发工具包) BaseTool.
      Parameters:
      toolCallback - The Spring AI tool callback to convert
      Returns:
      A SpringAiTool wrapping the callback
    • convertToAdkTools

      public List<BaseTool> convertToAdkTools(Collection<? extends org.springframework.ai.tool.ToolCallback> toolCallbacks)
      将一组 Spring AI 对象进行转换(即对它们进行处理或操作)。 ToolCallback将 `s` 添加到 ADK 的列表中 BaseTools.
      Parameters:
      toolCallbacks - Collection of Spring AI tool callbacks to convert
      Returns:
      List of ADK BaseTool instances
    • convertToAdkToolset

      public SpringAiToolset convertToAdkToolset(org.springframework.ai.tool.ToolCallbackProvider toolCallbackProvider)
      将一个 Spring AI 对象转换为另一种格式或结构。 ToolCallbackProvider 发送到一个 ADK(Application Development Kit,应用程序开发工具包) BaseToolset 每当代理(agent)列出其使用的工具时,系统都会向相应的工具提供商(provider)发送查询请求;因此,所使用的工具集(toolset)会自动更新为使用那些工具提供商提供的最新工具。
      Parameters:
      toolCallbackProvider - Provider of Spring AI tool callbacks
      Returns:
      A SpringAiToolset backed by toolCallbackProvider