llm

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package llm is the contract every core-models provider adapter implements. It mirrors ADK's model package field for field, so that an adapter module (adkv2 today) can adapt it to an ADK major with plain copies — and it imports no ADK, so the core module never puts an ADK major into a consumer's build.

Each ADK major's model.LLM is identical in shape to the others and distinct as a Go type; this package is the neutral spelling every major can reach (docs/design.md §4, decision D2).

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyResponse = errors.New("model returned no usable content")

ErrEmptyResponse is what an adapter's error wraps when the model answered with no usable content, no finish reason other than STOP, and no error: the silent turn an agent loop otherwise waits on forever (mast #220). Adapters wrap it with their own wording, so a caller can recognise "the model said nothing" with errors.Is without importing any adapter — a one-shot side question, for which an empty answer is the answer, needs exactly that (core-agent's models sentinel, generalised).

Functions

This section is empty.

Types

type LLM

type LLM interface {
	// Name reports the model this LLM serves.
	Name() string

	// GenerateContent sends req. With stream false it yields one
	// complete Response; with stream true it yields partial Responses
	// (Partial set) followed by a final complete one.
	GenerateContent(ctx context.Context, req *Request, stream bool) iter.Seq2[*Response, error]
}

LLM is a model a caller can send one request to. It is ADK's model.LLM over this package's Request and Response.

type Request

type Request struct {
	Model    string
	Contents []*genai.Content
	Config   *genai.GenerateContentConfig
}

Request mirrors ADK's model.LLMRequest without its Tools field. That field maps tool names to ADK tool objects for ADK's own flows to dispatch on; no adapter reads it, since the declarations a provider sends come from Config.Tools.

type Response

type Response struct {
	Content                 *genai.Content                              `json:"content,omitempty"`
	CitationMetadata        *genai.CitationMetadata                     `json:"citationMetadata,omitempty"`
	GroundingMetadata       *genai.GroundingMetadata                    `json:"groundingMetadata,omitempty"`
	UsageMetadata           *genai.GenerateContentResponseUsageMetadata `json:"usageMetadata,omitempty"`
	CustomMetadata          map[string]any                              `json:"customMetadata,omitempty"`
	LogprobsResult          *genai.LogprobsResult                       `json:"logprobsResult,omitempty"`
	InputTranscription      *genai.Transcription                        `json:"inputTranscription,omitempty"`
	OutputTranscription     *genai.Transcription                        `json:"outputTranscription,omitempty"`
	ModelVersion            string                                      `json:"modelVersion,omitempty"`
	Partial                 bool                                        `json:"partial,omitempty"`
	TurnComplete            bool                                        `json:"turnComplete,omitempty"`
	Interrupted             bool                                        `json:"interrupted,omitempty"`
	SessionResumptionHandle string                                      `json:"sessionResumptionHandle,omitempty"`
	ErrorCode               string                                      `json:"errorCode,omitempty"`
	ErrorMessage            string                                      `json:"errorMessage,omitempty"`
	FinishReason            genai.FinishReason                          `json:"finishReason,omitempty"`
	AvgLogprobs             float64                                     `json:"avgLogprobs,omitempty"`
}

Response mirrors ADK's model.LLMResponse, JSON tags included (ADK v2 spells them; v1 has none, and Go's decoder matches either).

CustomMetadata is where an adapter attaches what genai's usage struct cannot hold — see package usage.

Every dialect yields exactly one response with TurnComplete set per call: the single response of a unary call, or the aggregate that ends a stream. Streamed chunks are Partial and never TurnComplete, so a consumer that commits usage on TurnComplete counts each call once.

Jump to

Keyboard shortcuts

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