gemini

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package gemini implements models.Provider for the Gemini family, covering both the public Gemini API (API-key auth) and Vertex AI (Application Default Credentials + GCP project).

The two are exposed as distinct provider names ("gemini" and "vertex") so users and automation can pin to a backend explicitly. Both delegate to google.golang.org/adk/model/gemini under the hood.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuiltinTools

type BuiltinTools struct {
	GoogleSearch  bool // Public web search grounding (default: on)
	URLContext    bool // Fetch + ground on URLs the model decides to visit (default: on)
	CodeExecution bool // Sandboxed Python execution on Google's servers (default: off)
}

BuiltinTools toggles Gemini's server-side built-in tools surfaced by core-agent. Each enabled flag becomes its own *genai.Tool entry injected into the request's Config.Tools alongside any user-defined function declarations.

Defaults:

  • GoogleSearch + URLContext are on (universally useful, no setup)
  • CodeExecution is off (useful but a real action surface — opt in when you've decided sandboxed Python on Google's servers is acceptable for your security and cost posture)

To turn one off:

provider, _ := gemini.NewAPIKey(key, gemini.WithURLContext(false))

To turn CodeExecution on:

provider, _ := gemini.NewAPIKey(key, gemini.WithCodeExecution(true))

To replace the whole set:

provider, _ := gemini.NewAPIKey(key, gemini.WithBuiltinTools(gemini.BuiltinTools{
    GoogleSearch: true, // URL context + CodeExecution off
}))

Other genai built-ins (FileSearch, GoogleMaps, ComputerUse, EnterpriseWebSearch, GoogleSearchRetrieval, Retrieval) aren't surfaced here. They require upstream setup (a corpus, a Maps API key, a hosted environment) or are Vertex-only — flipping them on without configuring the upstream resource yields an API error, not a working tool. Add them when an actual consumer needs them.

func DefaultBuiltinTools

func DefaultBuiltinTools() BuiltinTools

DefaultBuiltinTools returns the on-by-default baseline applied to every Provider unless overridden via WithBuiltinTools or one of the per-tool helpers.

type Option

type Option func(*Provider)

Option configures a Gemini Provider at construction time.

func WithBuiltinTools

func WithBuiltinTools(b BuiltinTools) Option

WithBuiltinTools replaces the Provider's whole BuiltinTools set.

func WithCodeExecution

func WithCodeExecution(on bool) Option

WithCodeExecution toggles the CodeExecution built-in (sandboxed Python on Google's servers). Off by default.

func WithGoogleSearch

func WithGoogleSearch(on bool) Option

WithGoogleSearch toggles the Google Search built-in.

func WithURLContext

func WithURLContext(on bool) Option

WithURLContext toggles the URL Context built-in.

type Provider

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

Provider is the Gemini-family implementation of models.Provider.

func NewAPIKey

func NewAPIKey(key string, opts ...Option) (*Provider, error)

NewAPIKey returns a Provider authenticated against the public Gemini API using key. Empty key is rejected so the failure mode is clear at startup.

Built-in tools (Google Search + URL Context) are enabled by default; pass WithBuiltinTools / WithGoogleSearch / WithURLContext to override.

func NewVertex

func NewVertex(project, location string, opts ...Option) (*Provider, error)

NewVertex returns a Provider authenticated against Vertex AI for the given GCP project and location, using Application Default Credentials.

Built-in tools (Google Search + URL Context) are enabled by default; pass WithBuiltinTools / WithGoogleSearch / WithURLContext to override.

func (*Provider) Model

func (p *Provider) Model(ctx context.Context, modelID string) (adkmodel.LLM, error)

Model constructs a model.LLM for the given model ID. When the Provider has any built-in tools enabled, the returned LLM is wrapped to inject them into Config.Tools on every request.

func (*Provider) Name

func (p *Provider) Name() string

Name reports the provider identity (e.g. "gemini" or "vertex").

Jump to

Keyboard shortcuts

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