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
- func (in *Inbox) ConsumeEvents(ctx context.Context, taskIDs []string) error
- func (in *Inbox) ConsumeSteers(ctx context.Context, ids []string) error
- func (in *Inbox) Decisions(ctx context.Context) ([]agent.Decision, error)
- func (in *Inbox) Deny(callID string, reason string)
- func (in *Inbox) Events(ctx context.Context) ([]agent.TaskEvent, error)
- func (in *Inbox) Finished(ctx context.Context, taskIDs []string) (bool, error)
- func (in *Inbox) Grant(callID string)
- func (in *Inbox) Steers(ctx context.Context) ([]agent.Steer, error)
- 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)
- 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
- func (t *Tools) Authorize(_ context.Context, name string, call tools.Call) (agent.Admission, error)
- func (t *Tools) Execute(ctx context.Context, g agent.Grant) (tools.Result, *tools.ApprovalRequest, error)
- func (t *Tools) Recovery(ctx context.Context, _ string, call tools.Call) (agent.Recovery, error)
- func (t *Tools) Specs(context.Context) []tools.Spec
- 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
AutoGrant bool
OnRequest func(agent.Pending) error
Inbox *Inbox
}
Approvals records requests, each a pending decision in Inbox, which AutoGrant grants at once. OnRequest runs first and fails the request with its error. Like the store, it fails 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
// Hooks, when set, runs the run's hooks.
Hooks agent.Hooks
// Verifier, when set, checks the session goal.
Verifier agent.Verifier
// 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 ¶
type Inbox struct {
SteerTexts []string
Decided []agent.Decision
TaskEvents []agent.TaskEvent
Ended []string
}
Inbox hands out pending steers, whose IDs are their text, and events until they are consumed, and the newest decision of each call (Grant and Deny decide one); Ended lists tasks that finished without an event. Like the store, it fails on a stopped context.
func (*Inbox) ConsumeEvents ¶ added in v0.2.1
func (*Inbox) ConsumeSteers ¶ added in v0.2.1
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. 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
Recoveries map[string]agent.Recovery
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 admission) 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. Recoveries settles interrupted calls by ID; a call it does not name reruns.