Documentation
¶
Index ¶
- Constants
- Variables
- func New(ctx context.Context, settings chat.Settings, opts ...Option) (chat.ChatClient, error)
- func NewAgyLocal(ctx context.Context, settings chat.Settings, opts ...AgyLocalOption) (chat.ChatClient, error)
- type AgyLocal
- func (a *AgyLocal) Add(_ context.Context, prompt string, media ...chat.Media) error
- func (a *AgyLocal) Ask(ctx context.Context, question string, target any, media ...chat.Media) error
- func (a *AgyLocal) Chat(ctx context.Context, prompt string, media ...chat.Media) (string, error)
- func (a *AgyLocal) History() chat.History
- func (a *AgyLocal) SetTools(tools []chat.Tool) error
- func (a *AgyLocal) SupportsEffort()
- func (a *AgyLocal) SupportsStateless()
- type AgyLocalOption
- type Gemini
- func (g *Gemini) Add(ctx context.Context, prompt string, media ...chat.Media) error
- func (g *Gemini) AddCached(ctx context.Context, prompt string, media ...chat.Media) error
- func (g *Gemini) ApplyPolicyNow(ctx context.Context, policy chat.HistoryPolicy) (int, error)
- func (g *Gemini) Ask(ctx context.Context, question string, target any, media ...chat.Media) error
- func (g *Gemini) Chat(ctx context.Context, prompt string, media ...chat.Media) (string, error)
- func (g *Gemini) History() chat.History
- func (g *Gemini) Model() string
- func (g *Gemini) Provider() chat.Provider
- func (g *Gemini) Restore(snapshot *chat.Snapshot) error
- func (g *Gemini) Save() (*chat.Snapshot, error)
- func (g *Gemini) SetTools(tools []chat.Tool) error
- func (g *Gemini) StreamChat(ctx context.Context, prompt string, callback chat.StreamCallback, ...) (string, error)
- func (g *Gemini) SupportsEffort()
- func (g *Gemini) SupportsSampling()
- func (g *Gemini) SupportsStateless()
- type Option
Constants ¶
const ( EnvCloudProject = "GOOGLE_CLOUD_PROJECT" EnvCloudLocation = "GOOGLE_CLOUD_LOCATION" )
EnvCloudProject and EnvCloudLocation are the standard Google Cloud variables this module falls back to when Config.Project or Config.Location is empty. Explicit configuration wins; these exist so a developer with a working gcloud environment does not have to restate it. See spec 0017 D7.
const EnvGeminiKey = "GEMINI_API_KEY"
EnvGeminiKey is the well-known unprefixed environment variable used as the ecosystem fallback when no explicit credential is configured.
const EnvUseVertex = "GOOGLE_GENAI_USE_VERTEXAI"
EnvUseVertex is the SDK's own backend switch. This module does not honour it, and refuses to construct when it is set without Vertex having been asked for. See spec 0017 D1 and D6.
Variables ¶
var DefaultAgyEnvironment = []string{"PATH", "HOME"}
DefaultAgyEnvironment is what the subprocess inherits unless a caller adds to it with WithAgyEnvironment.
An allowlist rather than a denylist, for the reason spec 0021 D5 records: a CLI reads its own authentication from the environment, and naming the variables to remove is a denylist against a third party's binary that fails open.
Functions ¶
func New ¶ added in v0.9.0
New builds a Gemini client, accepting options this provider owns. Reach for it when you need one; otherwise chat.New with the provider name does the same job through the registry.
It goes through chat.NewWithFactory rather than calling build directly, so it gets every guard chat.New applies: the endpoint is validated before credentials reach it, the logger this package logs through is resolved, provider defaults are applied, unapplicable settings are dropped and reported, and the built client is asserted able to carry what survived.
Calling build directly is what this used to do, which accepted an insecure endpoint that chat.New refuses and panicked when no Logger was set. See https://gitlab.com/phpboyscout/go/chat-openai/-/issues/2, which reports the same defect in the sibling module, and spec 0015.
func NewAgyLocal ¶ added in v0.15.0
func NewAgyLocal(ctx context.Context, settings chat.Settings, opts ...AgyLocalOption) (chat.ChatClient, error)
NewAgyLocal builds a client backed by a locally installed, signed-in agy CLI.
It is the one provider in this family that cannot carry tools: agy has no per-invocation MCP route. SetTools returns an error naming the reason, and Capabilities reports CapTools as SupportNo so a caller can ask first.
Types ¶
type AgyLocal ¶ added in v0.15.0
type AgyLocal struct {
chat.UsageTracker
// contains filtered or unexported fields
}
AgyLocal implements chat.ChatClient by driving a locally installed agy CLI, which serves Gemini models.
func (*AgyLocal) Add ¶ added in v0.15.0
Add buffers a user message to be prepended to the next Chat or Ask call.
func (*AgyLocal) Ask ¶ added in v0.15.0
Ask sends a question and unmarshals the structured response into target, using --json-schema when the config carries one.
func (*AgyLocal) Chat ¶ added in v0.15.0
Chat sends a message to the local agy binary and returns the text response.
func (*AgyLocal) History ¶ added in v0.15.0
History reports what this client is carrying. Known is false: the conversation lives in agy's own session, resumed by id.
func (*AgyLocal) SetTools ¶ added in v0.15.0
SetTools is not supported, and this is the one provider in the family for which that is permanent rather than pending.
agy has no per-invocation MCP route: `agy mcp add` writes persistent user configuration, so publishing a caller's tools would mean rewriting the user's own config around every call. That is not concurrency-safe, is visible outside the process, and leaves debris if the process dies.
Capabilities reports CapTools as SupportNo, so a caller can ask before building rather than discovering it here. Spec 0022 D4. Clearing tools asks for nothing, so an empty set succeeds.
func (*AgyLocal) SupportsEffort ¶ added in v0.15.0
func (a *AgyLocal) SupportsEffort()
SupportsEffort marks AgyLocal as carrying Config.Effort. agy's ladder has three rungs against the neutral five, so the top three clamp onto its highest, the way the API path clamps onto Gemini's four.
func (*AgyLocal) SupportsStateless ¶ added in v0.15.0
func (a *AgyLocal) SupportsStateless()
SupportsStateless marks AgyLocal as honouring Config.Stateless: a stateless call omits --conversation and discards the id.
type AgyLocalOption ¶ added in v0.15.0
type AgyLocalOption func(*agyLocalOptions)
AgyLocalOption configures a chat.ProviderAgyLocal client at construction.
func WithAgyBinaryLookup ¶ added in v0.15.0
func WithAgyBinaryLookup(lookPath func(string) (string, error)) AgyLocalOption
WithAgyBinaryLookup overrides how the agy binary is located, replacing exec.LookPath.
func WithAgyCommand ¶ added in v0.15.0
WithAgyCommand overrides how the agy subprocess is built, replacing exec.CommandContext.
func WithAgyEnvironment ¶ added in v0.15.0
func WithAgyEnvironment(names ...string) AgyLocalOption
WithAgyEnvironment names further environment variables to pass to the subprocess, on top of DefaultAgyEnvironment.
func WithUnrestrictedAgy ¶ added in v0.15.0
func WithUnrestrictedAgy() AgyLocalOption
WithUnrestrictedAgy drops the sandbox and lets the prompt expand slash commands and skills.
Off by default because agy is an agentic tool and a chat client's prompt is frequently not trusted. Two things are passed without it: --sandbox, which agy documents as terminal restrictions, and --disable-slash-commands, so text that happens to begin with a slash is a message rather than an instruction. The second mirrors the core's own rule that only caller-supplied input is parsed as a command.
Note what --sandbox does not do. Measured against agy 1.1.23, a prompt still ran a shell command as the calling user with it set. Only claude's --restricted removes execution outright; codex and agy both narrow rather than close. Do not read the default as a guarantee that a prompt cannot act. See spec 0022 D5.
type Gemini ¶
type Gemini struct {
chat.UsageTracker
// contains filtered or unexported fields
}
Gemini implements the chat.ChatClient interface using Google's Generative AI SDK.
func (*Gemini) AddCached ¶ added in v0.5.0
AddCached appends a user turn and arranges for it to be served from a provider-side cache on this and subsequent calls.
The cache is created lazily on first use, keyed by a hash of the content, and left to expire rather than deleted — so there is no lifecycle for a caller to manage and no cleanup path to get wrong.
func (*Gemini) ApplyPolicyNow ¶ added in v0.11.0
ApplyPolicyNow bounds the retained conversation immediately, rather than waiting for the next request to do it.
It is the sequence this client runs before every request — describe the turns, ask the policy, rewrite from the result — without the pending turn, because nothing is about to be answered. Unlike the other providers there is no system turn to hold out: Gemini keeps the system instruction in its generation config rather than in the conversation, so the transcript is conversation throughout.
A nil policy means the configured one. With none configured there is nothing to apply and it returns zero rather than an error. When the edit runs is the rule chat.WhenBusy attached: it waits, refuses or merges (spec 0026 D3).
func (*Gemini) Chat ¶
Chat sends a message and returns the response content, handling tool calls internally.
func (*Gemini) History ¶ added in v0.9.0
History reports the conversation this client will re-send, counting the retained turns and anything buffered by Add and not yet sent.
Known is true — this provider owns its transcript. A Gemini session is created per call from this history, so what is counted here is exactly what the next call will carry.
func (*Gemini) Model ¶ added in v0.6.0
Model implements chat.ModelIdentifier, reporting the model this client will actually use — the configured one, or the default it fell back to.
func (*Gemini) Restore ¶
Restore replaces the current conversation state with a previously saved snapshot.
func (*Gemini) StreamChat ¶
func (g *Gemini) StreamChat(ctx context.Context, prompt string, callback chat.StreamCallback, media ...chat.Media) (string, error)
StreamChat implements StreamingChatClient.
func (*Gemini) SupportsEffort ¶ added in v0.3.0
func (g *Gemini) SupportsEffort()
SupportsEffort marks Gemini as able to carry Config.Effort, via thinkingConfig.thinkingLevel.
Gemini's ladder has four rungs against the neutral five, so EffortXHigh and EffortMax clamp to its highest. The clamp is documented rather than silent: asking for more effort than a provider offers should give you its most, not an error.
func (*Gemini) SupportsSampling ¶ added in v0.3.0
func (g *Gemini) SupportsSampling()
SupportsSampling marks Gemini as able to carry Config.Temperature and TopP. Measured accepted across 0-2 and 0-1 respectively, with server-side range validation.
func (*Gemini) SupportsStateless ¶ added in v0.2.0
func (g *Gemini) SupportsStateless()
SupportsStateless marks Gemini as honouring chat.Config.Stateless.
type Option ¶ added in v0.9.0
type Option func(*options)
newGemini initializes a new Gemini chat client. Option configures a Gemini client at construction.
These are knobs only this provider understands. The core's Config carries what every provider means the same way; anything one provider owns belongs to that provider's own constructor, where the compiler can see it. See https://gitlab.com/phpboyscout/go/chat/-/wikis/specs/0011-chat-provider-conformance D10.
func WithClientConstructor ¶ added in v0.9.0
func WithClientConstructor( newClient func(context.Context, *genai.ClientConfig) (*genai.Client, error), ) Option
WithClientConstructor replaces genai.NewClient, so a test can substitute the SDK client without reaching a real endpoint.
It replaces chat.Config.GenaiNewClient, removed from the core in v0.10.0. That field was an `any` this module type-asserted at runtime, so a caller who passed the wrong shape learned about it from an error at construction. This signature is checked by the compiler, and the error path it needed is gone.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
detectmodels
command
Command detectmodels reports when Google has shipped something the module's default model does not reflect.
|
Command detectmodels reports when Google has shipped something the module's default model does not reflect. |
|
genmodels
command
Command genmodels regenerates the per-model capability table.
|
Command genmodels regenerates the per-model capability table. |