# Class MessageConverter

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

public class MessageConverter extends Object
Converts between ADK and Spring AI message formats.

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
  Constructor
  Description
  `MessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Map<String, ToolConverter.ToolMetadata>`
  `getToolRegistry(LlmRequest llmRequest)`
  Gets tool registry from ADK tools for internal tracking.
  `org.springframework.ai.chat.prompt.Prompt`
  `toLlmPrompt(LlmRequest llmRequest)`
  Converts an ADK LlmRequest to a Spring AI Prompt.
  `LlmResponse`
  `toLlmResponse(org.springframework.ai.chat.model.ChatResponse chatResponse)`
  Converts a Spring AI ChatResponse to an ADK LlmResponse.
  `LlmResponse`
  `toLlmResponse(org.springframework.ai.chat.model.ChatResponse chatResponse, boolean isStreaming)`
  Converts a Spring AI ChatResponse to an ADK LlmResponse with streaming context.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### MessageConverter

    public MessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper)

- ## Method Details

  - ### toLlmPrompt

    public org.springframework.ai.chat.prompt.Prompt toLlmPrompt(LlmRequest llmRequest)
    Converts an ADK LlmRequest to a Spring AI Prompt.
    Parameters:
      `llmRequest` - The ADK request to convert
    Returns:
      A Spring AI Prompt

  - ### getToolRegistry

    public Map<String, ToolConverter.ToolMetadata> getToolRegistry(LlmRequest llmRequest)
    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

    public LlmResponse toLlmResponse(org.springframework.ai.chat.model.ChatResponse chatResponse)
    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 convert
      `isStreaming` - Whether this is part of a streaming response
    Returns:
      An ADK LlmResponse