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

replay

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package replay provides Model implementations that need no provider: a scripted model for unit tests, and a recorder and replayer pair so that a real model's responses can be captured once and served deterministically afterwards. Tests and CI never call a provider.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotRecorded = errors.New("replay: no recorded response for this request")

ErrNotRecorded means the replayer has no response for the request, or the request has been made more times than it was recorded.

Functions

func Key

func Key(model string, req agentrt.ModelRequest) (string, error)

Key is the replay key of a request: the SHA-256 of its canonical JSON with the model name. Numbers keep their literal text, so two requests that differ only in an integer beyond float64 precision have different keys; for every number float64 represents exactly, which is every number in the recordings written before this, the key is unchanged.

Types

type Recorder

type Recorder struct {
	Inner agentrt.Model
	Dir   string
	// contains filtered or unexported fields
}

Recorder wraps a model and stores every successful exchange in Dir.

Exchanges with identical requests are stored in sequence: the first at <key>.json, the second at <key>.2.json, and so on, so a replay serves them in the order they were recorded rather than the last one for every call. The first exchange for a key in a Recorder's lifetime replaces whatever an earlier session recorded under that key, including any higher-numbered files, so re-recording a run leaves nothing stale.

func (*Recorder) Generate

Generate implements agentrt.Model.

func (*Recorder) Name

func (r *Recorder) Name() string

Name implements agentrt.Model.

type Replayer

type Replayer struct {
	ModelName string
	Dir       string
	// contains filtered or unexported fields
}

Replayer serves recorded responses and fails on anything unrecorded. Identical requests are served in the order they were recorded; a request made more times than it was recorded is unrecorded, because the replayed session has diverged from the recorded one.

func (*Replayer) Generate

Generate implements agentrt.Model.

func (*Replayer) Name

func (p *Replayer) Name() string

Name implements agentrt.Model.

type Scripted

type Scripted struct {
	ModelName string
	Responses []agentrt.ModelResponse
	// Errors, when set, is consulted first: a non-nil entry is returned
	// instead of the response at that index.
	Errors []error

	// Requests records every request received.
	Requests []agentrt.ModelRequest
	// contains filtered or unexported fields
}

Scripted returns canned responses in order.

func (*Scripted) Generate

Generate implements agentrt.Model.

func (*Scripted) Name

func (s *Scripted) Name() string

Name implements agentrt.Model.

Jump to

Keyboard shortcuts

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