Documentation
¶
Overview ¶
Package gemini adapts the Gemini Live API (BidiGenerateContent) to agentkit.LiveLLM: a duplex audio session with native function calling and server-side voice activity detection. Beside it, Transcriber turns a recording into its words with one REST generateContent request (transcribe.go).
It speaks the protocol directly over an injected Transport instead of importing a vendor SDK. Gemini Live is JSON over a WebSocket — small enough that a client is cheaper than a dependency, and keeping this module dependency-free preserves agentkit's ability to move to its own repository. It also makes the whole protocol testable offline against a scripted fake transport.
Audio contract: input is raw little-endian 16-bit PCM, natively 16 kHz (the rate is declared in the MIME type, so the server resamples other rates). Output is ALWAYS 24 kHz — a consumer feeding a fixed-rate sink must resample.
Index ¶
Constants ¶
const OutputSampleRate = 24000
OutputSampleRate is the rate of every LiveAudio chunk this adapter emits. Fixed by the API, exported because a consumer must resample or configure its sink to match.
Variables ¶
var DefaultThinkingBudgets = map[agentkit.Effort]int{ agentkit.EffortLow: 1024, agentkit.EffortMedium: 8192, agentkit.EffortHigh: 24576, }
DefaultThinkingBudgets is how many tokens of thinking each reasoning effort buys, on the scale the 2.5 Flash models take (0 to 24576): a quick look, a real think, the ceiling.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a LiveLLM backed by the Gemini Live API. It holds no connection: each Open dials its own, so one Client serves many concurrent sessions.
func New ¶
New builds a Client that dials with d, authenticates with apiKey and runs model (the bare id, e.g. "gemini-live-2.5-flash-preview" — the "models/" prefix is added). The model is required rather than defaulted: live-capable model ids churn, and a stale built-in default would fail at connect time with a confusing error instead of at configuration time.
func (*Client) Open ¶
func (c *Client) Open(ctx context.Context, conv []agentkit.Message, tools []agentkit.ToolSpec) (agentkit.LiveSession, error)
Open dials a session, sends the setup frame, waits for setupComplete, seeds any prior transcript, and starts the reader. The returned session is live until Close or ctx cancellation.
type Dialer ¶
Dialer opens a Transport to url. nocturn supplies a coder/websocket-backed one; tests supply a scripted fake.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithEffort ¶
WithEffort sets the default reasoning effort, sent as a thinking budget. An effort carried on the ctx Open is called with (agentkit.EffortFrom) overrides it; none leaves the model's own default.
func WithLogger ¶
WithLogger sets the diagnostic logger (default: agentkit.NopLogger()). A nil logger is ignored.
func WithThinkingBudgets ¶
WithThinkingBudgets replaces DefaultThinkingBudgets, for a model whose scale is another. An effort the map does not name sends no budget.
type Transcriber ¶
type Transcriber struct {
// contains filtered or unexported fields
}
Transcriber turns a recording into the words spoken in it with one generateContent request: the audio as inline data, a strict instruction to transcribe verbatim in the language spoken. It holds no connection, so one Transcriber serves concurrent calls.
The key travels in the x-goog-api-key header, never in the URL, so it is not in a proxy's log or an error message.
func NewTranscriber ¶
func NewTranscriber(apiKey, model string, opts ...TranscriberOption) *Transcriber
NewTranscriber builds a Transcriber that authenticates with apiKey and runs model (the bare id, e.g. "gemini-3.5-flash"; a "models/" prefix is accepted).
func (*Transcriber) Transcribe ¶
Transcribe returns the words spoken in audio, of type mime ("audio/webm", "audio/ogg", …), trimmed; "" when nothing was said. A refusal by the API, a blocked prompt and an answer cut short are errors: a partial transcript would send half of what somebody said as all of it.
type TranscriberOption ¶
type TranscriberOption func(*Transcriber)
TranscriberOption configures a Transcriber.
func WithBaseURL ¶
func WithBaseURL(url string) TranscriberOption
WithBaseURL points the Transcriber at another REST root than Google's, such as a test server or a gateway that speaks the same API.
func WithHTTPClient ¶
func WithHTTPClient(c *http.Client) TranscriberOption
WithHTTPClient sets the client requests are sent with (default http.DefaultClient). A nil client is ignored.
type Transport ¶
type Transport interface {
// Send writes one complete text frame.
Send(ctx context.Context, frame []byte) error
// Recv blocks for the next complete text frame. It returns an error once the peer closes.
Recv(ctx context.Context) ([]byte, error)
// Close releases the connection. It must be safe to call more than once.
Close() error
}
Transport is the WebSocket this adapter speaks over, injected rather than imported. That keeps this module dependency-free (agentkit's rule: the engine and its siblings carry no third-party deps that would follow it into its own repository) and makes the whole protocol testable against a scripted fake — no network, no API key, no flakiness in `go test ./...`.
An implementation must be safe for one concurrent Send and one concurrent Recv, which is what the adapter does: a writer goroutine and a reader goroutine. It need NOT support concurrent Sends.