replay

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Overview

Package replay provides a provider that replays recorded sessions deterministically.

Package replay provides a provider that replays recorded sessions deterministically.

Index

Constants

This section is empty.

Variables

View Source
var ErrSessionClosed = errors.New("session is closed")

ErrSessionClosed is returned when attempting to use a closed session.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Timing controls response delivery timing.
	// Default: TimingInstant
	Timing TimingMode

	// Speed is the multiplier for TimingAccelerated mode.
	// Default: 2.0 (2x speed)
	Speed float64

	// MatchMode controls how requests are matched to recorded responses.
	// Default: MatchByTurn (sequential order)
	MatchMode MatchMode

	// Metadata contains additional information about the recording.
	// This can include judge targets, tags, and provider information
	// that should flow through to evaluation contexts.
	Metadata map[string]interface{}
}

Config configures the replay provider.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for replay.

type MatchMode

type MatchMode int

MatchMode controls how incoming requests are matched to recorded responses.

const (
	// MatchByTurn matches responses in sequential order (turn 1, 2, 3, ...).
	MatchByTurn MatchMode = iota

	// MatchByContent matches by comparing the last user message content.
	MatchByContent
)

type Provider

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

Provider replays recorded session responses without making LLM calls.

func NewProvider

func NewProvider(rec *recording.SessionRecording, cfg *Config) (*Provider, error)

NewProvider creates a replay provider from a session recording.

func NewProviderFromFile

func NewProviderFromFile(path string, cfg *Config) (*Provider, error)

NewProviderFromFile loads a recording file and creates a replay provider.

func (*Provider) CalculateCost

func (p *Provider) CalculateCost(inputTokens, outputTokens, cachedTokens int) types.CostInfo

CalculateCost returns zero cost as replays don't incur real costs.

func (*Provider) Close

func (p *Provider) Close() error

Close is a no-op for replay provider.

func (*Provider) CurrentTurn

func (p *Provider) CurrentTurn() int

CurrentTurn returns the current turn index (0-based).

func (*Provider) GetMetadata added in v1.1.9

func (p *Provider) GetMetadata() map[string]interface{}

GetMetadata returns metadata about the recording. This includes judge targets, tags, and provider information that can be used by evaluation frameworks and assertions.

func (*Provider) ID

func (p *Provider) ID() string

ID returns the provider identifier.

func (*Provider) Model added in v1.1.8

func (p *Provider) Model() string

Model returns the model name. For replay provider, this returns "replay".

func (*Provider) Predict

Predict returns the next recorded response.

func (*Provider) PredictStream

func (p *Provider) PredictStream(
	ctx context.Context,
	req providers.PredictionRequest,
) (<-chan providers.StreamChunk, error)

PredictStream returns the recorded response as a single stream chunk.

func (*Provider) Reset

func (p *Provider) Reset()

Reset resets the provider to replay from the beginning.

func (*Provider) ShouldIncludeRawOutput

func (p *Provider) ShouldIncludeRawOutput() bool

ShouldIncludeRawOutput returns false as replays don't have raw output.

func (*Provider) SupportsStreaming

func (p *Provider) SupportsStreaming() bool

SupportsStreaming returns true as replay supports streaming.

func (*Provider) TurnCount

func (p *Provider) TurnCount() int

TurnCount returns the number of recorded turns available.

type StreamSession

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

StreamSession implements StreamInputSession for replaying recorded sessions.

func (*StreamSession) Close

func (s *StreamSession) Close() error

Close ends the streaming session.

func (*StreamSession) Done

func (s *StreamSession) Done() <-chan struct{}

Done returns a channel that closes when the session ends.

func (*StreamSession) EndInput

func (s *StreamSession) EndInput()

EndInput signals the end of input and triggers the next response. This implements the EndInputter interface expected by DuplexProviderStage.

func (*StreamSession) Error

func (s *StreamSession) Error() error

Error returns any session error.

func (*StreamSession) RemainingTurns

func (s *StreamSession) RemainingTurns() int

RemainingTurns returns the number of responses left to replay.

func (*StreamSession) Response

func (s *StreamSession) Response() <-chan providers.StreamChunk

Response returns the response channel.

func (*StreamSession) SendChunk

func (s *StreamSession) SendChunk(ctx context.Context, chunk *types.MediaChunk) error

SendChunk receives input chunks and triggers replay of the next response.

func (*StreamSession) SendSystemContext

func (s *StreamSession) SendSystemContext(ctx context.Context, text string) error

SendSystemContext sends system context (ignored for replay).

func (*StreamSession) SendText

func (s *StreamSession) SendText(ctx context.Context, text string) error

SendText receives text input and triggers replay of the next response.

func (*StreamSession) TriggerNextResponse

func (s *StreamSession) TriggerNextResponse(ctx context.Context) error

TriggerNextResponse manually triggers the next response (for testing).

type StreamingProvider

type StreamingProvider struct {
	*Provider
	// contains filtered or unexported fields
}

StreamingProvider extends Provider with streaming support for duplex replay.

func NewStreamingProviderFromArenaOutput

func NewStreamingProviderFromArenaOutput(path string, cfg *Config) (*StreamingProvider, error)

NewStreamingProviderFromArenaOutput creates a streaming replay provider from an arena output file.

func (*StreamingProvider) CreateStreamSession

CreateStreamSession creates a new bidirectional streaming session for replay.

func (*StreamingProvider) GetStreamingCapabilities

func (p *StreamingProvider) GetStreamingCapabilities() providers.StreamingCapabilities

GetStreamingCapabilities returns detailed information about streaming support.

func (*StreamingProvider) SupportsStreamInput

func (p *StreamingProvider) SupportsStreamInput() []string

SupportsStreamInput returns the media types supported for streaming input.

type TimingMode

type TimingMode int

TimingMode controls how response timing is handled during replay.

const (
	// TimingInstant delivers responses immediately without delay.
	TimingInstant TimingMode = iota

	// TimingRealTime delivers responses with original timing preserved.
	TimingRealTime

	// TimingAccelerated delivers responses with accelerated timing.
	TimingAccelerated
)

Jump to

Keyboard shortcuts

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