类 GeminiChatFormatter

java.lang.Object
io.agentscope.core.formatter.AbstractBaseFormatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder>
io.agentscope.core.formatter.gemini.GeminiChatFormatter
所有已实现的接口:
Formatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder>

public class GeminiChatFormatter extends AbstractBaseFormatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder>
Formatter for Gemini Content Generation API.

Converts between AgentScope Msg objects and Gemini SDK types:

  • Msg → Content (request format)
  • GenerateContentResponse → ChatResponse (response parsing)
  • ToolSchema → Tool (tool definitions)

Important Gemini API Behaviors:

  • System messages are converted to "user" role (Gemini doesn't support system role in contents)
  • Tool results are independent "user" role Content objects
  • Thinking content uses the "thought" flag on Part objects
  • 构造器详细资料

    • GeminiChatFormatter

      public GeminiChatFormatter()
      Creates a new GeminiChatFormatter with default converters and parsers.
  • 方法详细资料

    • doFormat

      protected List<com.google.genai.types.Content> doFormat(List<Msg> msgs)
      指定者:
      doFormat 在类中 AbstractBaseFormatter<com.google.genai.types.Content,com.google.genai.types.GenerateContentResponse,com.google.genai.types.GenerateContentConfig.Builder>
    • parseResponse

      public ChatResponse parseResponse(com.google.genai.types.GenerateContentResponse response, Instant startTime)
      从接口复制的说明: Formatter
      Parse provider-specific response to AgentScope ChatResponse.
      参数:
      response - Provider-specific response object
      startTime - Request start time for calculating duration
      返回:
      AgentScope ChatResponse
    • applyOptions

      public void applyOptions(com.google.genai.types.GenerateContentConfig.Builder configBuilder, GenerateOptions options, GenerateOptions defaultOptions)
      从接口复制的说明: Formatter
      Apply generation options to provider-specific request parameters.
      参数:
      configBuilder - Provider-specific request parameters builder
      options - Generation options to apply
      defaultOptions - Default options to use if options parameter is null
    • applyTools

      public void applyTools(com.google.genai.types.GenerateContentConfig.Builder configBuilder, List<ToolSchema> tools)
      从接口复制的说明: Formatter
      Apply tool schemas to provider-specific request parameters.
      参数:
      configBuilder - Provider-specific request parameters builder
      tools - List of tool schemas to apply (may be null or empty)
    • applyToolChoice

      public void applyToolChoice(com.google.genai.types.GenerateContentConfig.Builder configBuilder, ToolChoice toolChoice)
      从接口复制的说明: Formatter
      Apply tool choice configuration to provider-specific request parameters.

      This method controls how the model uses tools. The default implementation does nothing, allowing formatters to override for providers that support tool choice configuration.

      参数:
      configBuilder - Provider-specific request parameters builder
      toolChoice - Tool choice configuration (null means provider default)