Class GeminiChatModel
java.lang.Object
io.agentscope.core.model.ChatModelBase
io.agentscope.extensions.model.gemini.GeminiChatModel
- All Implemented Interfaces:
io.agentscope.core.model.Model
public class GeminiChatModel
extends io.agentscope.core.model.ChatModelBase
Gemini Chat Model implementation using the official Google GenAI Java SDK.
This implementation provides complete integration with Gemini's Content Generation API, including tool calling and multi-agent conversation support.
Supported Features:
- Text generation with streaming and non-streaming modes
- Tool/function calling support
- Multi-agent conversation with history merging
- Vision capabilities (images, audio, video)
- Thinking mode (extended reasoning)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for creating GeminiChatModel instances. -
Constructor Summary
ConstructorsConstructorDescriptionGeminiChatModel(String apiKey, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, com.google.genai.types.HttpOptions httpOptions, com.google.auth.oauth2.GoogleCredentials credentials, com.google.genai.types.ClientOptions clientOptions, io.agentscope.core.model.GenerateOptions defaultOptions, io.agentscope.core.formatter.Formatter<com.google.genai.types.Content, com.google.genai.types.GenerateContentResponse, com.google.genai.types.GenerateContentConfig.Builder> formatter) Creates a new Gemini chat model instance using the default endpoint configuration.GeminiChatModel(String apiKey, String baseUrl, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, com.google.genai.types.HttpOptions httpOptions, com.google.auth.oauth2.GoogleCredentials credentials, com.google.genai.types.ClientOptions clientOptions, io.agentscope.core.model.GenerateOptions defaultOptions, io.agentscope.core.formatter.Formatter<com.google.genai.types.Content, com.google.genai.types.GenerateContentResponse, com.google.genai.types.GenerateContentConfig.Builder> formatter) Creates a new Gemini chat model instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic GeminiChatModel.Builderbuilder()Creates a new builder for GeminiChatModel.voidclose()Close the Gemini client.protected reactor.core.publisher.Flux<io.agentscope.core.model.ChatResponse>doStream(List<io.agentscope.core.message.Msg> messages, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.GenerateOptions options) Stream chat completion responses from Gemini's API.protected reactor.core.publisher.Flux<io.agentscope.core.model.ChatResponse>doStream0(List<io.agentscope.core.message.Msg> messages, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.GenerateOptions options) Methods inherited from class io.agentscope.core.model.ChatModelBase
getContextWindowSize, setContextWindowSize, setNativeStructuredOutput, setNativeStructuredOutputWithTools, stream, supportsNativeStructuredOutput, supportsNativeStructuredOutputWithTools
-
Constructor Details
-
GeminiChatModel
public GeminiChatModel(String apiKey, String baseUrl, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, com.google.genai.types.HttpOptions httpOptions, com.google.auth.oauth2.GoogleCredentials credentials, com.google.genai.types.ClientOptions clientOptions, io.agentscope.core.model.GenerateOptions defaultOptions, io.agentscope.core.formatter.Formatter<com.google.genai.types.Content, com.google.genai.types.GenerateContentResponse, com.google.genai.types.GenerateContentConfig.Builder> formatter) Creates a new Gemini chat model instance.- Parameters:
apiKey- the API key for authentication (for Gemini API)baseUrl- the custom base URL for Gemini API (null for default)modelName- the model name to use (e.g., "gemini-2.0-flash", "gemini-1.5-pro")streamEnabled- whether streaming should be enabledproject- the Google Cloud project ID (for Vertex AI)location- the Google Cloud location (for Vertex AI, e.g., "us-central1")vertexAI- whether to use Vertex AI APIs (null for auto-detection)httpOptions- HTTP options for the clientcredentials- Google credentials (for Vertex AI)clientOptions- client options for the API clientdefaultOptions- default generation optionsformatter- the message formatter to use (null for default Gemini formatter)
-
GeminiChatModel
public GeminiChatModel(String apiKey, String modelName, boolean streamEnabled, String project, String location, Boolean vertexAI, com.google.genai.types.HttpOptions httpOptions, com.google.auth.oauth2.GoogleCredentials credentials, com.google.genai.types.ClientOptions clientOptions, io.agentscope.core.model.GenerateOptions defaultOptions, io.agentscope.core.formatter.Formatter<com.google.genai.types.Content, com.google.genai.types.GenerateContentResponse, com.google.genai.types.GenerateContentConfig.Builder> formatter) Creates a new Gemini chat model instance using the default endpoint configuration.This overload passes
nullforbaseUrl, allowing the SDK to use its default endpoint behavior for either Gemini API or Vertex AI, depending on the provided configuration.- Parameters:
apiKey- the API key for authentication (for Gemini API)modelName- the model name to use (e.g., "gemini-2.0-flash", "gemini-1.5-pro")streamEnabled- whether streaming should be enabledproject- the Google Cloud project ID (for Vertex AI)location- the Google Cloud location (for Vertex AI, e.g., "us-central1")vertexAI- whether to use Vertex AI APIs (null for auto-detection)httpOptions- HTTP options for the clientcredentials- Google credentials (for Vertex AI)clientOptions- client options for the API clientdefaultOptions- default generation optionsformatter- the message formatter to use (null for default Gemini formatter)
-
-
Method Details
-
doStream
protected reactor.core.publisher.Flux<io.agentscope.core.model.ChatResponse> doStream(List<io.agentscope.core.message.Msg> messages, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.GenerateOptions options) Stream chat completion responses from Gemini's API.This method internally handles message formatting using the configured formatter. When streaming is enabled, it returns incremental responses as they arrive. When streaming is disabled, it returns a single complete response.
- Specified by:
doStreamin classio.agentscope.core.model.ChatModelBase- Parameters:
messages- AgentScope messages to send to the modeltools- Optional list of tool schemas (null or empty if no tools)options- Optional generation options (null to use defaults)- Returns:
- Flux stream of chat responses
-
doStream0
-
getModelName
-
close
public void close()Close the Gemini client. -
builder
Creates a new builder for GeminiChatModel.- Returns:
- a new Builder instance
-