Class MessageConverter
This converter handles the translation between ADK's Content/Part format (based on Google's genai.types) and Spring AI's Message/ChatResponse format. It supports:
- Text content in all message types
- Tool/function calls in assistant messages
- System instructions and configuration options
Note: Media attachments and tool responses are currently not supported due to Spring AI 1.1.0 API limitations (protected/private constructors). These will be added once Spring AI provides public APIs for these features.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetToolRegistry(LlmRequest llmRequest) Gets tool registry from ADK tools for internal tracking.org.springframework.ai.chat.prompt.PrompttoLlmPrompt(LlmRequest llmRequest) Converts an ADK LlmRequest to a Spring AI Prompt.org.springframework.ai.chat.prompt.PrompttoLlmPrompt(LlmRequest llmRequest, org.springframework.ai.chat.prompt.ChatOptions modelDefaultOptions) Converts an ADK LlmRequest to a Spring AI Prompt, using the target model's own default options as the base for the prompt options.toLlmResponse(org.springframework.ai.chat.model.ChatResponse chatResponse) Converts a Spring AI ChatResponse to an ADK LlmResponse.toLlmResponse(org.springframework.ai.chat.model.ChatResponse chatResponse, boolean isStreaming) Converts a Spring AI ChatResponse to an ADK LlmResponse with streaming context.
-
Constructor Details
-
MessageConverter
public MessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
-
-
Method Details
-
toLlmPrompt
Converts an ADK LlmRequest to a Spring AI Prompt.- Parameters:
llmRequest- The ADK request to convert- Returns:
- A Spring AI Prompt
-
toLlmPrompt
public org.springframework.ai.chat.prompt.Prompt toLlmPrompt(LlmRequest llmRequest, org.springframework.ai.chat.prompt.ChatOptions modelDefaultOptions) Converts an ADK LlmRequest to a Spring AI Prompt, using the target model's own default options as the base for the prompt options.Provider-specific chat models (for example Spring AI OpenAI
2.0.0) castPrompt.getOptions()directly to their own options type (e.g.OpenAiChatOptions) increateRequest(...). Passing provider-neutral options such asDefaultToolCallingChatOptionstherefore triggers aClassCastException. To stay compatible with any provider, the prompt options are built on top of the model's own default options (obtained viaChatModel.getOptions()) so the resulting options keep the concrete type the provider expects, while overlaying the ADK tools and generation config.- Parameters:
llmRequest- The ADK request to convertmodelDefaultOptions- The target model's default options, ornullif unavailable- Returns:
- A Spring AI Prompt
-
getToolRegistry
Gets tool registry from ADK tools for internal tracking.- Parameters:
llmRequest- The ADK request containing tools- Returns:
- Map of tool metadata for tracking available tools
-
toLlmResponse
Converts a Spring AI ChatResponse to an ADK LlmResponse.- Parameters:
chatResponse- The Spring AI response to convert- Returns:
- An ADK LlmResponse
-
toLlmResponse
public LlmResponse toLlmResponse(org.springframework.ai.chat.model.ChatResponse chatResponse, boolean isStreaming) Converts a Spring AI ChatResponse to an ADK LlmResponse with streaming context.- Parameters:
chatResponse- The Spring AI response to convertisStreaming- Whether this is part of a streaming response- Returns:
- An ADK LlmResponse
-