Help us shape the future of Go! Take the 2026 Go Developer Survey

testagent

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package testagent is a scripted ADK agent for tests, Docker Compose and the evaluator's self-test. It runs the real ADK REST server around a model that answers from a script, so the wire format is genuine and the output is deterministic. No LLM is involved.

Index

Constants

View Source
const (
	DefaultWordDelay  = 10 * time.Millisecond
	DefaultSlowDelay  = 100 * time.Millisecond
	DefaultSlowChunks = 50
)

Defaults of the scripted model's timing.

View Source
const AppName = "ui_agent"

AppName is the ADK app name clients put in URLs. It matches the default of the Web UI's AGENT_APP_NAME.

View Source
const DefaultSSEWriteTimeout = 2 * time.Minute

DefaultSSEWriteTimeout is how long the ADK server lets one event stream run, as its launcher does (the flag is --sse-write-timeout).

View Source
const FixtureVersion = 1

FixtureVersion is the version of the fixture file format.

Variables

This section is empty.

Functions

func BuildAgent

func BuildAgent(llm model.LLM) (agent.Agent, error)

BuildAgent wraps llm in an ADK agent named AppName with one tool, "lookup".

func NewHandler

func NewHandler(llm model.LLM, opts ...HandlerOption) (http.Handler, error)

NewHandler serves the real ADK REST API under /api for llm, with in-memory sessions, the same routes the ADK launcher exposes.

Types

type Fixture

type Fixture struct {
	Version int                     `json:"version"`
	Replies map[string]FixtureReply `json:"replies"`
	// contains filtered or unexported fields
}

Fixture scripts the agent for the evaluator's self-test: what it answers to each problem. A problem is recognized by an id written in its question, so the same fixture works with whatever prompt is wrapped around the question. No two ids may contain one another, so that an id in a question means one problem.

func LoadFixture

func LoadFixture(path string) (*Fixture, error)

LoadFixture reads a fixture file.

func ParseFixture

func ParseFixture(data []byte) (*Fixture, error)

ParseFixture reads and checks a fixture. A member it does not know is an error, so that a misspelled setting is not quietly ignored.

type FixtureReply

type FixtureReply struct {
	// Text is the reply, streamed word by word.
	Text string `json:"text,omitempty"`
	// Error fails the run with this message instead of replying.
	Error string `json:"error,omitempty"`
	// WordDelayMs is the pause between words; absent means the model's own pace.
	WordDelayMs *int `json:"word_delay_ms,omitempty"`
	// FirstDelayMs is the pause before the first word, for a reply that takes
	// its time to start.
	FirstDelayMs int `json:"first_delay_ms,omitempty"`
	// Tool names a tool to call before answering, so that the reply carries
	// tool-call telemetry.
	Tool string `json:"tool,omitempty"`
	// FailFirst makes the first that many runs fail with Error (a default
	// message when it is empty) before Text is given: an agent that is down for
	// a moment, for testing Retry. The runs are counted for each distinct
	// question, so a question with something new in it (a number made up for the
	// occasion) fails afresh, however long the agent has been up.
	FailFirst int `json:"fail_first,omitempty"`
}

FixtureReply is how the agent answers one problem.

type HandlerOption

type HandlerOption func(*handlerSettings)

HandlerOption changes how NewHandler serves.

func WithSSEWriteTimeout

func WithSSEWriteTimeout(d time.Duration) HandlerOption

WithSSEWriteTimeout sets how long one reply may take to stream before the server cuts it off, as an agent whose answer outlasts that limit is.

type LookupArgs

type LookupArgs struct {
	Query string `json:"query" jsonschema:"what to look up"`
}

LookupArgs is the input of the lookup tool.

type LookupResult

type LookupResult struct {
	Result string `json:"result"`
}

LookupResult is what the lookup tool returns.

type Model

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

Model is a model.LLM that answers from a script chosen by keywords in the last user message:

#error     fail with an error
#slow      stream numbered chunks slowly; stops when the context is canceled
#tool      call the "lookup" tool, then report its result
#think     send a reasoning part before the answer
#markdown  reply with headings, a list, a table and a code block
#html      reply with hostile HTML and links, for sanitizer tests

Anything else is echoed back.

Pattern: Scripted Model

func NewModel

func NewModel(opts ...Option) *Model

NewModel returns a scripted model.

func (*Model) GenerateContent

func (m *Model) GenerateContent(ctx context.Context, req *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error]

GenerateContent implements model.LLM. When streaming it yields one partial response per chunk and then the aggregated, non-partial response, which is what the ADK runner and the Gemini model do.

func (*Model) Name

func (*Model) Name() string

Name implements model.LLM.

func (*Model) Probe

func (m *Model) Probe() *Probe

Probe returns the model's counters.

type Option

type Option func(*Model)

Option customizes a Model.

func WithFixture

func WithFixture(f *Fixture) Option

WithFixture makes the model answer the problems a fixture names as it says, ahead of the keyword scripts. See Fixture.

func WithSlow

func WithSlow(delay time.Duration, chunks int) Option

WithSlow sets the chunk delay and chunk count of the #slow script.

func WithWordDelay

func WithWordDelay(d time.Duration) Option

WithWordDelay sets the pause between streamed words of ordinary replies.

type Probe

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

Probe counts what the model saw, so tests can assert on the agent side (for example "the upstream run was canceled").

Pattern: Probe Counters

func (*Probe) Cancelled

func (p *Probe) Cancelled() int64

Cancelled is the number of runs that stopped early because the caller went away.

func (*Probe) Runs

func (p *Probe) Runs() int64

Runs is the number of GenerateContent calls so far.

Jump to

Keyboard shortcuts

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