llmtest

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package llmtest provides a deterministic in-memory llm.Model for tests: a scripted backend that returns a fixed sequence of turns and records the requests it was given, so the conversation loop and the agent runtime can be driven end to end without a real provider or any network.

Index

Constants

This section is empty.

Variables

View Source
var ErrScriptExhausted = fault.New(fault.Terminal, "llmtest_script_exhausted", "scripted model: no turn left for this call")

ErrScriptExhausted is returned (terminal) when Generate is called more times than the script has turns.

Functions

func CallTool

func CallTool(id, name string, input json.RawMessage) llm.Response

CallTool returns an assistant turn that requests one tool call (StopToolUse).

func SayText

func SayText(text string) llm.Response

SayText returns a final assistant turn carrying text (StopEndTurn).

Types

type ScriptedModel

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

ScriptedModel is a deterministic llm.Model: each Generate call returns the next turn from a fixed script and records the request it was handed. It ignores the request when choosing what to return, so a test fixes the model's behaviour up front and then asserts, via Requests, that the loop fed the right history back. Running off the end of the script is a terminal error, surfacing a loop that took more turns than the test scripted.

func NewScripted

func NewScripted(turns ...llm.Response) *ScriptedModel

NewScripted builds a ScriptedModel that returns the given turns in order.

func (*ScriptedModel) Calls

func (m *ScriptedModel) Calls() int

Calls reports how many times Generate has been invoked.

func (*ScriptedModel) Generate

func (m *ScriptedModel) Generate(_ context.Context, req llm.Request) (llm.Response, error)

Generate implements llm.Model.

func (*ScriptedModel) Requests

func (m *ScriptedModel) Requests() []llm.Request

Requests returns a copy of the requests Generate has received, in order, so a test can assert the conversation the loop built (e.g. that tool results were appended before the next turn).

Jump to

Keyboard shortcuts

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