Class ToolConverter
This converter handles the translation between ADK's BaseTool/FunctionDeclaration format and Spring AI ToolCallback representations, including schema
conversion and ToolContext propagation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSimple metadata holder for tool information. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey for passing an ADKToolContextthrough Spring AI's tool context map. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.google.genai.types.SchemaconvertSchemaFromSpringAi(@Nullable String jsonSchema) Parses a Spring AI JSON Schema string into an ADKSchema.com.google.genai.types.SchemaconvertSchemaFromSpringAi(Map<String, Object> springAiSchema) Converts a Spring AI parameter schema map to an ADKSchema.convertSchemaToSpringAi(com.google.genai.types.Schema schema) Converts ADK Schema to Spring AI compatible parameter schema.convertToAdkTool(org.springframework.ai.tool.ToolCallback toolCallback) Converts a Spring AIToolCallbackto an ADKBaseTool.convertToAdkTools(Collection<? extends org.springframework.ai.tool.ToolCallback> toolCallbacks) Converts a collection of Spring AIToolCallbacks to a list of ADKBaseTools.convertToAdkToolset(org.springframework.ai.tool.ToolCallbackProvider toolCallbackProvider) Converts a Spring AIToolCallbackProviderto an ADKBaseToolsetthat queries the provider each time an agent lists its tools, so the toolset follows a provider whose tools change.Optional<org.springframework.ai.tool.ToolCallback>Converts a single ADKBaseToolto a Spring AIToolCallback.List<org.springframework.ai.tool.ToolCallback>convertToSpringAiTools(Map<String, BaseTool> tools) Converts ADK tools to Spring AI ToolCallback format for tool calling, skipping tools without a declaration.createToolRegistry(Map<String, BaseTool> tools) Creates a tool registry from ADK tools for internal tracking.
-
Field Details
-
ADK_TOOL_CONTEXT_KEY
Key for passing an ADKToolContextthrough Spring AI's tool context map.- See Also:
-
-
Constructor Details
-
ToolConverter
public ToolConverter()
-
-
Method Details
-
createToolRegistry
Creates a tool registry from ADK tools for internal tracking.This method provides a way to track available tools, though Spring AI tool calling integration will be enhanced in subsequent iterations.
- Parameters:
tools- Map of ADK tools to process- Returns:
- Map of tool names to their metadata
-
convertSchemaToSpringAi
Converts ADK Schema to Spring AI compatible parameter schema.Maps the
type,description,properties,required,enumanditemskeywords (propertiesvalues anditemsrecursively). Other JSON-Schema keywords (e.g.nullable,anyOf,format) are not carried over yet.- Parameters:
schema- The ADK schema to convert- Returns:
- A Map representing the Spring AI compatible schema
-
convertSchemaFromSpringAi
Converts a Spring AI parameter schema map to an ADKSchema.Maps
type,description,properties,required,enum, anditemsrecursively, defaulting missing arrayitemstoSTRINGand narrowingrequiredto declaredproperties. As in Python ADK, a$refis resolved as a JSON pointer into the root schema, or else by its last segment in the root$defsordefinitions; keys next to the$refoverride the referenced schema's, and a circular reference becomes an object schema.- Parameters:
springAiSchema- The Spring AI schema map to convert- Returns:
- The converted ADK
Schema
-
convertSchemaFromSpringAi
Parses a Spring AI JSON Schema string into an ADKSchema.- Parameters:
jsonSchema- The JSON Schema string (e.g. fromToolDefinition.inputSchema())- Returns:
- The converted ADK
Schema, or an empty object schema ifjsonSchemais null or blank - Throws:
IllegalArgumentException- ifjsonSchemais not valid JSON
-
convertToSpringAiTool
Converts a single ADKBaseToolto a Spring AIToolCallback.- 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) Converts ADK tools to Spring AI ToolCallback format for tool calling, skipping tools without a declaration.- Parameters:
tools- Map of ADK tools to convert- Returns:
- List of Spring AI ToolCallback objects
-
convertToAdkTool
Converts a Spring AIToolCallbackto an ADKBaseTool.- Parameters:
toolCallback- The Spring AI tool callback to convert- Returns:
- A
SpringAiToolwrapping the callback
-
convertToAdkTools
public List<BaseTool> convertToAdkTools(Collection<? extends org.springframework.ai.tool.ToolCallback> toolCallbacks) Converts a collection of Spring AIToolCallbacks to a list of ADKBaseTools.- Parameters:
toolCallbacks- Collection of Spring AI tool callbacks to convert- Returns:
- List of ADK
BaseToolinstances
-
convertToAdkToolset
public SpringAiToolset convertToAdkToolset(org.springframework.ai.tool.ToolCallbackProvider toolCallbackProvider) Converts a Spring AIToolCallbackProviderto an ADKBaseToolsetthat queries the provider each time an agent lists its tools, so the toolset follows a provider whose tools change.- Parameters:
toolCallbackProvider- Provider of Spring AI tool callbacks- Returns:
- A
SpringAiToolsetbacked bytoolCallbackProvider
-