gemini

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gemini adapts Google's Gemini API to Glue's provider interface using the google.golang.org/genai SDK.

It streams text and thinking deltas, converts Glue tools to Gemini function declarations, and maps function calls and results across the normalized loop types. The model comes from AgentOptions.Model, a per-call WithModel, or the provider default. The API key is taken from Options.APIKey or the GEMINI_API_KEY environment variable.

Index

Constants

View Source
const DefaultModel = "gemini-2.5-flash"

DefaultModel is the registry-level default model for this provider.

View Source
const EnvKey = "GEMINI_API_KEY"

EnvKey is the environment variable the provider reads when Options.APIKey is empty. Exposed so the providers registry and downstream agents can probe key availability without hard-coding the name.

Variables

This section is empty.

Functions

func ConvertMessages

func ConvertMessages(messages []loop.Message) ([]*genai.Content, error)

ConvertMessages converts Glue messages to Gemini contents.

Consecutive tool-role messages are grouped into a single Gemini content with role "user" and one FunctionResponse part per message, matching how the genai SDK expects multi-tool turns to be expressed.

func ConvertTools

func ConvertTools(tools []loop.ToolSpec) ([]*genai.Tool, error)

ConvertTools converts Glue tool specs to Gemini function declarations. All declarations are bundled into a single Gemini Tool, which is how genai expects multiple tools to be exposed to the model.

Types

type Options

type Options struct {
	APIKey       string
	DefaultModel string
	Client       *genai.Client
}

Options configures the Gemini provider.

APIKey is consulted first; when empty the GEMINI_API_KEY environment variable is used. DefaultModel applies when loop.ProviderRequest.Model is empty. Client, when non-nil, is used as-is and APIKey is ignored.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider streams Gemini responses into Glue's normalized provider events.

func New

func New(options Options) *Provider

New creates a Gemini provider. The genai client is created lazily on the first Provider.Stream call so that constructing a provider does not require credentials.

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req loop.ProviderRequest) (<-chan loop.ProviderEvent, error)

Stream implements loop.Provider. It supports text-only conversations and Gemini function calling: tool specs in loop.ProviderRequest.Tools are converted to function declarations, inbound function calls become loop.ProviderEventToolCall events, and tool-role messages in the transcript are converted to function responses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL