AS AgentScopeAPI 手册 / API Reference

GeminiChatFormatter

public class GeminiChatFormatter extends AbstractBaseFormatter< Content, GenerateContentResponse, GenerateContentConfig.Builder>
源码Source io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:52–208

Gemini 聊天格式化器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.gemini.formatter 包,继承自 AbstractBaseFormatter<Content, GenerateContentResponse, GenerateContentConfig.Builder>。核心成员包括 doFormat、parseResponse、applyOptions、applyTools、applyToolChoice、GeminiChatFormatter。

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

构造器摘要Constructor Summary

构造器Constructor说明Description
public GeminiChatFormatter()
初始化 `GeminiChatFormatter` 实例。
Creates a new GeminiChatFormatter with default converters and parsers.

方法摘要Method Summary

方法Method说明Description
protected List<Content> doFormat(List<Msg> msgs)
执行格式操作。
Performs the do format operation.
public ChatResponse parseResponse(GenerateContentResponse response, Instant startTime)
解析响应。
Parses the response.
public void applyOptions(GenerateContentConfig.Builder configBuilder, GenerateOptions options, GenerateOptions defaultOptions)
应用选项。
Performs the apply options operation.
public void applyTools(GenerateContentConfig.Builder configBuilder, List<ToolSchema> tools)
应用工具。
Performs the apply tools operation.
public void applyToolChoice(GenerateContentConfig.Builder configBuilder, ToolChoice toolChoice)
应用工具选项。
Performs the apply tool choice operation.

构造器详情Constructor Detail

GeminiChatFormatter

public GeminiChatFormatter()

初始化 GeminiChatFormatter 实例。

Creates a new GeminiChatFormatter with default converters and parsers.

源码Source io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:63–67

方法详情Method Detail

doFormat

protected List<Content> doFormat(List<Msg> msgs)

执行格式操作。

Performs the do format operation.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
返回Returns List<Content>
返回列出。Returns list.
源码Source io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:69–72

parseResponse

public ChatResponse parseResponse(GenerateContentResponse response, Instant startTime)

解析响应。

Parses the response.

参数Parameters
名称Name类型Type说明Description
responseGenerateContentResponse响应(类型 `GenerateContentResponse`)。The response.
startTimeInstant启动时间(类型 `Instant`)。The start time.
返回Returns ChatResponse
返回ChatResponse。Returns chat response.
源码Source io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:74–77

applyOptions

public void applyOptions(GenerateContentConfig.Builder configBuilder, GenerateOptions options, GenerateOptions defaultOptions)

应用选项。

Performs the apply options operation.

参数Parameters
名称Name类型Type说明Description
configBuilderGenerateContentConfig.Builder配置构建器(类型 `GenerateContentConfig.Builder`)。The config builder.
optionsGenerateOptions选项(类型 `GenerateOptions`)。The options.
defaultOptionsGenerateOptions默认选项(类型 `GenerateOptions`)。The default options.
源码Source io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:79–130

applyTools

public void applyTools(GenerateContentConfig.Builder configBuilder, List<ToolSchema> tools)

应用工具。

Performs the apply tools operation.

参数Parameters
名称Name类型Type说明Description
configBuilderGenerateContentConfig.Builder配置构建器(类型 `GenerateContentConfig.Builder`)。The config builder.
toolsList<ToolSchema>工具列表(类型 `List`)。The tools.
源码Source io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:192–198

applyToolChoice

public void applyToolChoice(GenerateContentConfig.Builder configBuilder, ToolChoice toolChoice)

应用工具选项。

Performs the apply tool choice operation.

参数Parameters
名称Name类型Type说明Description
configBuilderGenerateContentConfig.Builder配置构建器(类型 `GenerateContentConfig.Builder`)。The config builder.
toolChoiceToolChoice工具选项(类型 `ToolChoice`)。The tool choice.
源码Source io/agentscope/extensions/model/gemini/formatter/GeminiChatFormatter.java:200–207
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.