agenttest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agenttest provides a scripted model and in-memory fakes for the agent ports.

Index

Constants

View Source
const (
	RunID     = "run_1"
	SessionID = "session_1"
)

Variables

This section is empty.

Functions

func AssignmentCopies

func AssignmentCopies(request providers.Request, assignment string) int

AssignmentCopies counts how often request carries the user's assignment verbatim: as its own message or kept verbatim in a summary.

func SplitBoundary

func SplitBoundary(messages []transcript.Message) string

SplitBoundary describes the first boundary of messages that covers a tool call without its result or a result without its call; "" when none does.

func SplitToolPair

func SplitToolPair(request providers.Request) string

SplitToolPair describes the first tool call of request not answered right after it, or the first result not answering a call just before it; "" when every call and result are paired.

Types

type Approvals

type Approvals struct {
	Requests  []agent.Pending
	Open      bool
	Grant     func(agent.Pending)
	OnRequest func(agent.Pending) error
}

Approvals records requests; Grant, when set, resolves each request at once. OnRequest runs first and fails the request with its error. Like the store, both methods fail on a stopped context.

func (*Approvals) Pending

func (a *Approvals) Pending(ctx context.Context, _ string) (bool, error)

func (*Approvals) Request

func (a *Approvals) Request(ctx context.Context, p agent.Pending) error

type Fixture

type Fixture struct {
	Journal   *Journal
	Tools     *Tools
	Approvals *Approvals
	Inbox     *Inbox
	Sink      *Sink
	Prompts   *Prompts
	Todos     *Todos
	Clock     time.Time
	// Now, when set, is the engine's clock instead of Clock, for tools that
	// move time from their own goroutines.
	Now func() time.Time
	// Window is the model window of the fixture's task; 0 means unknown.
	Window int
	// Slept records the engine's waits, which return at once unless RealSleep is set.
	Slept     []time.Duration
	RealSleep bool
	// ModelSlots and Locks are shared by the engines of fixtures that should
	// compete for model requests and concurrency keys.
	ModelSlots *toolsched.Semaphore
	Locks      *toolsched.Locks
	// contains filtered or unexported fields
}

Fixture wires an engine to fresh fakes around one seeded user message.

func NewFixture

func NewFixture() *Fixture

NewFixture returns fakes with the run's user message already journaled.

func (*Fixture) Engine

func (f *Fixture) Engine() *agent.Engine

Engine returns an engine over the fixture's fakes with a fixed clock and sequential IDs.

func (*Fixture) Task

func (f *Fixture) Task(model agent.Model) agent.Task

Task returns the fixture's run for model.

func (*Fixture) WithHistory

func (f *Fixture) WithHistory(messages ...transcript.Message)

WithHistory puts messages before the run's user message, as an earlier part of the session.

type Inbox

type Inbox struct {
	Steers  []string
	Decided []agent.Input
	Events  []agent.Input
	Ended   []string
}

Inbox hands out pending steers, whose IDs are their text, and events until they are consumed, and decided approvals on every peek; Ended lists tasks that finished without an event. Like the store, it fails on a stopped context.

func (*Inbox) Consume

func (in *Inbox) Consume(ctx context.Context, _ string, ids []string) error

func (*Inbox) Finished

func (in *Inbox) Finished(ctx context.Context, taskIDs []string) (bool, error)

func (*Inbox) Peek

func (in *Inbox) Peek(ctx context.Context, _ string, kind agent.InputKind) ([]agent.Input, error)

type Journal

type Journal struct {
	Messages     []transcript.Message
	States       []agent.State
	Steps        []agent.Step
	Begins       int
	Streams      int
	Finishes     int
	LoadErr      error
	OnAppend     func(transcript.Message) error
	OnCheckpoint func(agent.State) error
	// contains filtered or unexported fields
}

Journal keeps the transcript in memory, loads it like core — the newest boundary and the messages after it — and counts streaming writes. Like the store it rejects duplicate IDs and fails writes on a stopped context; RecordStep never fails, as core only logs a failed step write. OnAppend and OnCheckpoint run first and can fail a write.

func (*Journal) Append

func (j *Journal) Append(ctx context.Context, msg transcript.Message) (int64, error)

func (*Journal) BeginStreaming

func (j *Journal) BeginStreaming(ctx context.Context, msg transcript.Message) (int64, error)

func (*Journal) Checkpoint

func (j *Journal) Checkpoint(ctx context.Context, state agent.State) error

func (*Journal) FinishStreaming

func (j *Journal) FinishStreaming(ctx context.Context, msg transcript.Message) error

func (*Journal) Load

func (j *Journal) Load(ctx context.Context, _ string) (agent.Window, error)

func (*Journal) Message

func (j *Journal) Message(id string) (transcript.Message, bool)

Message returns the stored message with the ID.

func (*Journal) RecordStep

func (j *Journal) RecordStep(_ context.Context, step agent.Step) error

func (*Journal) Result

func (j *Journal) Result(callID string) (transcript.Message, bool)

Result returns the stored result message of a tool call.

func (*Journal) Seed

func (j *Journal) Seed(messages ...transcript.Message)

Seed stores messages as if they were written before the run.

func (*Journal) Stream

func (j *Journal) Stream(ctx context.Context, msg transcript.Message) error

type ModelFunc

type ModelFunc func(ctx context.Context, req providers.Request) (providers.Response, error)

ModelFunc adapts a function to agent.Model.

func (ModelFunc) Generate

type Prompts

type Prompts struct {
	Text        string
	Custom      string
	ContextText string
	SystemCalls int
}

Prompts returns Text as the system prompt and ContextText as the changing context; SystemCalls counts system prompt builds.

func (*Prompts) Context

func (p *Prompts) Context(context.Context) string

func (*Prompts) System

type ScriptedModel

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

ScriptedModel answers requests with its turns in order and records every request.

func NewScriptedModel

func NewScriptedModel(turns ...Turn) *ScriptedModel

NewScriptedModel returns a model that plays turns in order.

func (*ScriptedModel) Generate

func (*ScriptedModel) Requests

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

Requests returns every request the model received.

type Sink

type Sink struct {
	Events []agent.Event
}

Sink records every event.

func (*Sink) Emit

func (s *Sink) Emit(event agent.Event)

func (*Sink) Kinds

func (s *Sink) Kinds() []agent.EventKind

Kinds lists the recorded event kinds in order.

type Todos

type Todos struct {
	Items  []todo.Item
	Chains [][]string
}

it was asked about. Like the store, it fails on a stopped context.

func (*Todos) Open

func (t *Todos) Open(ctx context.Context, _ string, chain []string) ([]todo.Item, error)

type ToolFunc

type ToolFunc func(call tools.Call) tools.Result

ToolFunc executes one fake tool call.

type Tools

type Tools struct {
	Funcs     map[string]ToolFunc
	Mutating  map[string]bool
	Asks      map[string]bool
	Keys      map[string]string
	Delegated map[string]bool
	Inbox     *Inbox
	Calls     []tools.Call
	OnExecute func(ctx context.Context, name string, call tools.Call) error
	// SpecReads counts tool listings.
	SpecReads int
	// contains filtered or unexported fields
}

Tools authorizes registered names only (Mutating ones are barriers until granted, Keys and Delegated fill the decision) and records executed calls in start order (read Calls after Run returns). A call of an Asks tool returns an approval request until Inbox holds its grant, as core does. OnExecute runs first, on the call's goroutine, and fails the call with its error.

func (*Tools) Authorize

func (t *Tools) Authorize(_ context.Context, name string, call tools.Call) (agent.Decision, error)

func (*Tools) Execute

func (t *Tools) Execute(ctx context.Context, name string, call tools.Call) (tools.Result, *tools.ApprovalRequest, error)

func (*Tools) Specs

func (t *Tools) Specs(context.Context) []tools.Spec

type Turn

type Turn struct {
	Stream   []string
	Response providers.Response
	Err      error
}

Turn is one scripted answer; Stream deltas are streamed before Response is returned.

Jump to

Keyboard shortcuts

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