Documentation
¶
Overview ¶
Package agenttest provides a scripted model and in-memory fakes for the agent ports.
Index ¶
- Constants
- func AssignmentCopies(request providers.Request, assignment string) int
- func SplitBoundary(messages []transcript.Message) string
- func SplitToolPair(request providers.Request) string
- type Approvals
- type Fixture
- type Inbox
- type Journal
- func (j *Journal) Append(ctx context.Context, msg transcript.Message) (int64, error)
- func (j *Journal) BeginStreaming(ctx context.Context, msg transcript.Message) (int64, error)
- func (j *Journal) Checkpoint(ctx context.Context, state agent.State) error
- func (j *Journal) FinishStreaming(ctx context.Context, msg transcript.Message) error
- func (j *Journal) Load(ctx context.Context, _ string) (agent.Window, error)
- func (j *Journal) Message(id string) (transcript.Message, bool)
- func (j *Journal) RecordStep(_ context.Context, step agent.Step) error
- func (j *Journal) Result(callID string) (transcript.Message, bool)
- func (j *Journal) Seed(messages ...transcript.Message)
- func (j *Journal) Stream(ctx context.Context, msg transcript.Message) error
- type ModelFunc
- type Prompts
- type ScriptedModel
- type Sink
- type Todos
- type ToolFunc
- type Tools
- type Turn
Constants ¶
const ( RunID = "run_1" SessionID = "session_1" )
Variables ¶
This section is empty.
Functions ¶
func AssignmentCopies ¶
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 ¶
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.
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 ¶
Engine returns an engine over the fixture's fakes with a fixed clock and sequential IDs.
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 ¶
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.
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) BeginStreaming ¶
func (*Journal) Checkpoint ¶
func (*Journal) FinishStreaming ¶
func (*Journal) Message ¶
func (j *Journal) Message(id string) (transcript.Message, bool)
Message returns the stored message with the ID.
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.
type Prompts ¶
Prompts returns Text as the system prompt and ContextText as the changing context; SystemCalls counts system prompt builds.
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) Requests ¶
func (m *ScriptedModel) Requests() []providers.Request
Requests returns every request the model received.
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.