Documentation
¶
Overview ¶
Package virtual implements a agent.Provider that replays recorded responses from a dictionary. This enables deterministic testing without live LLM calls.
Ported from ddx cli/internal/agent/virtual.go with adaptation to the agent.Provider interface — responses are structured (content + tool calls + token usage) rather than raw text.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizePrompt ¶
func NormalizePrompt(prompt string, patterns []NormalizePattern) string
NormalizePrompt applies regex→replacement patterns before hashing. This allows prompts with dynamic content (temp paths, timestamps, IDs) to produce stable hashes across runs.
func PromptHash ¶
PromptHash computes a truncated SHA-256 hash of a prompt string. Returns 16 hex characters (64 bits).
func RecordEntry ¶
func RecordEntry(dictDir string, messages []agent.Message, response agent.Response, patterns []NormalizePattern) error
RecordEntry saves a message→response pair to the dictionary directory.
Types ¶
type Config ¶
type Config struct {
// DictDir is the directory containing recorded dictionary entries.
DictDir string
// InlineResponses are checked before file-based lookup.
InlineResponses []InlineResponse
// NormalizePatterns are applied to message content before hashing.
NormalizePatterns []NormalizePattern
}
Config configures the virtual provider.
type Entry ¶
type Entry struct {
PromptHash string `json:"prompt_hash"`
Messages []agent.Message `json:"messages,omitempty"`
Response agent.Response `json:"response"`
DelayMS int `json:"delay_ms,omitempty"`
RecordedAt string `json:"recorded_at,omitempty"`
}
Entry is a recorded message→response pair stored on disk.
type InlineResponse ¶
type InlineResponse struct {
PromptMatch string `json:"prompt_match"` // substring or /regex/
Response agent.Response `json:"response"`
DelayMS int `json:"delay_ms,omitempty"`
}
InlineResponse matches prompts by pattern and returns a fixed response.
type NormalizePattern ¶
type NormalizePattern struct {
Pattern string `json:"pattern" yaml:"pattern"`
Replace string `json:"replace" yaml:"replace"`
}
NormalizePattern is a regex→replacement pair for prompt normalization.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider replays recorded responses from a dictionary.
func (*Provider) Chat ¶
func (p *Provider) Chat(ctx context.Context, messages []agent.Message, tools []agent.ToolDef, opts agent.Options) (agent.Response, error)
Chat looks up a recorded response matching the messages. It checks inline responses first, then falls back to file-based dictionary lookup by hash.
func (*Provider) SessionStartMetadata ¶
SessionStartMetadata reports a stable identity for replay-driven runs.