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 ¶
const ( DefaultWordDelay = 10 * time.Millisecond DefaultSlowDelay = 100 * time.Millisecond DefaultSlowChunks = 50 )
Defaults of the scripted model's timing.
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.
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).
const FixtureVersion = 1
FixtureVersion is the version of the fixture file format.
Variables ¶
This section is empty.
Functions ¶
func BuildAgent ¶
BuildAgent wraps llm in an ADK agent named AppName with one tool, "lookup".
func NewHandler ¶
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 ¶
LoadFixture reads a fixture file.
func ParseFixture ¶
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 (*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.
type Option ¶
type Option func(*Model)
Option customizes a Model.
func WithFixture ¶
WithFixture makes the model answer the problems a fixture names as it says, ahead of the keyword scripts. See Fixture.
func WithWordDelay ¶
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