agenttest

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package agenttest provides a scriptable agent.Provider for testing application code built on go-agent — agent wiring, tool registration, hooks, and run-loop behavior — without any network calls or API cost.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockProvider

type MockProvider struct {
	// Responses is consumed in order, one per Generate call; the last
	// entry repeats if Generate is called more times than there are
	// entries. Ignored when OnGenerate is set.
	Responses []*agent.Response

	// OnGenerate, if set, is called instead of consuming Responses.
	OnGenerate func(req *agent.Request) (*agent.Response, error)

	// NameValue overrides the provider name returned by Name(). Defaults
	// to "mock".
	NameValue string

	// CapabilitiesValue is returned by Capabilities(), so tests can
	// exercise capability-gated code paths (e.g. WithThinking validation).
	CapabilitiesValue agent.Capabilities
	// contains filtered or unexported fields
}

MockProvider is a scriptable agent.Provider. Set Responses for a fixed script, or OnGenerate for responses computed from the request (e.g. to assert on tool results from a previous turn before deciding what to return next).

func (*MockProvider) Calls

func (m *MockProvider) Calls() []*agent.Request

Calls returns every request Generate has received so far, in order.

func (*MockProvider) Capabilities

func (m *MockProvider) Capabilities() agent.Capabilities

Capabilities implements agent.Capable.

func (*MockProvider) Generate

func (m *MockProvider) Generate(_ context.Context, req *agent.Request) (*agent.Response, error)

Generate implements agent.Provider.

func (*MockProvider) Name

func (m *MockProvider) Name() string

type MockStreamingProvider

type MockStreamingProvider struct {
	MockProvider

	// StreamFunc builds the event stream for a Stream call. If nil, Stream
	// synthesizes one from Generate (via Responses/OnGenerate): a single
	// text_delta (if the response has text) and a tool_call_start per tool
	// use, followed by message_done — enough to exercise RunStream call
	// sites without hand-writing an EventStream.
	StreamFunc func(req *agent.Request) (agent.EventStream, error)
}

MockStreamingProvider extends MockProvider with a scriptable Stream method, for testing streaming call sites (Agent.RunStream) without a real StreamingProvider. It is a distinct type from MockProvider — rather than MockProvider always implementing Stream — so tests can also exercise Agent's non-streaming-provider fallback path (see agent.WithStreamingFallback) with a provider that genuinely has no Stream method, matching how a real minimal Provider looks.

func (*MockStreamingProvider) Stream

Stream implements agent.StreamingProvider.

Jump to

Keyboard shortcuts

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