Documentation
¶
Overview ¶
Package expect checks tool calls against typed expectations.
Index ¶
- func Require(t testing.TB, s Subject, expectations ...Expectation)
- type Check
- type Expectation
- func AllAttemptsSuccessful(tool tools.Named) Expectation
- func Await(kind planner.AwaitItemKind, predicate func(planner.AwaitItem) error) Expectation
- func Bounds(tool tools.Named, predicate func(*agent.Bounds) error) Expectation
- func Call[P, R any](tool tools.TypedTool[P, R], args func(P) error, result func(R) error) Expectation
- func Completed() Expectation
- func Decoded[T any](tool tools.Named, codec tools.JSONCodec[T], args func(T) error) Expectation
- func Exact(expectations ...Expectation) Expectation
- func Failed[P, R any](tool tools.TypedTool[P, R], args func(P) error, ...) Expectation
- func Forbid(names ...tools.Named) Expectation
- func Func(name string, predicate func(Subject) error) Expectation
- func MaxModelCalls(n int) Expectation
- func MaxTokens(n int) Expectation
- func RawCall(tool tools.Named, args func(rawjson.Message) error, ...) Expectation
- func RawFailed(tool tools.Named, args func(rawjson.Message) error, ...) Expectation
- type ExpectedTool
- type ExpectedTools
- type Score
- type Subject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Check ¶
Check is the result of one expectation. Passed checks have no diagnostic; failed checks always have a diagnostic.
func Evaluate ¶
func Evaluate(s Subject, expectations ...Expectation) []Check
Evaluate returns one check per expectation in declaration order. Call expectations share a greedy, forward-only cursor. Check names are unique; repeated names receive #2, #3 and so on, avoiding existing suffixes.
type Expectation ¶
type Expectation interface {
// contains filtered or unexported methods
}
Expectation is a sealed check constructed by this package.
func AllAttemptsSuccessful ¶
func AllAttemptsSuccessful(tool tools.Named) Expectation
AllAttemptsSuccessful checks every selected execution of tool, including earlier failed calls before a later successful call. No calls fails the check. It is not applicable to Calls.
func Await ¶
func Await(kind planner.AwaitItemKind, predicate func(planner.AwaitItem) error) Expectation
Await checks any observed prompt of the requested planner await kind without consuming the tool-call cursor. Unverified prompts fail before decoding or invoking predicates. It is not applicable to Calls.
func Bounds ¶
Bounds checks recorded bounds on any execution of tool. It does not consume the call-matching cursor. It is not applicable to Calls.
func Call ¶
func Call[P, R any](tool tools.TypedTool[P, R], args func(P) error, result func(R) error) Expectation
Call matches the first later call satisfying the typed predicates. Either predicate may be nil. Nil predicates skip decoding that value. A result predicate is not applicable to a Calls subject.
func Completed ¶
func Completed() Expectation
Completed checks that every selected run has observed successful completion. Missing or unverified completion evidence fails. It is not applicable to Calls.
func Decoded ¶
Decoded matches the first later named call whose arguments decode with codec and satisfy args. A nil predicate still requires successful decoding.
func Exact ¶
func Exact(expectations ...Expectation) Expectation
Exact requires its expectations to match the remaining calls one-to-one in order. It panics at construction if any nested expectation is Forbid.
func Failed ¶
func Failed[P, R any](tool tools.TypedTool[P, R], args func(P) error, failure func(*planner.ToolError) error) Expectation
Failed matches the first later failed call satisfying optional argument and error predicates. It is not applicable to Calls.
func Forbid ¶
func Forbid(names ...tools.Named) Expectation
Forbid rejects calls to any of the named tools anywhere in the subject.
func Func ¶
func Func(name string, predicate func(Subject) error) Expectation
Func creates an expectation from a named predicate. A nil error passes.
func MaxModelCalls ¶
func MaxModelCalls(n int) Expectation
MaxModelCalls limits adopted model calls across every selected run. Abandoned and incomplete calls do not count. It is not applicable to Calls.
func MaxTokens ¶
func MaxTokens(n int) Expectation
MaxTokens limits input, output and cache tokens from all recorded model calls, including abandoned calls, across selected runs. It is not applicable to Calls.
func RawCall ¶
func RawCall(tool tools.Named, args func(rawjson.Message) error, result func(rawjson.Message) error) Expectation
RawCall matches the first later named call satisfying raw JSON predicates. Arguments must be valid JSON even when args is nil. A non-nil result predicate requires a verified successful execution with a recorded JSON result; it is not applicable to Calls. A nil result predicate checks arguments only and does not assert execution success. Predicates receive independent copies of the bytes. Prefer Call when a generated typed descriptor is available.
func RawFailed ¶
func RawFailed(tool tools.Named, args func(rawjson.Message) error, failure func(*planner.ToolError) error) Expectation
RawFailed matches the first later verified failed execution of a named tool. Arguments must be valid JSON even when args is nil. A nil failure predicate accepts any recorded tool error. RawFailed is not applicable to Calls. The argument predicate receives an independent copy of the JSON bytes. Prefer Failed when a generated typed descriptor is available.
type ExpectedTool ¶
type ExpectedTool struct {
Name tools.Ident `json:"name"`
Args json.RawMessage `json:"args,omitzero"`
}
ExpectedTool is a tool identifier with optional JSON-subset arguments. Omitted Args matches any arguments, while JSON null requires an actual null.
type ExpectedTools ¶
type ExpectedTools struct {
Tools []ExpectedTool `json:"tools"`
Ordered bool `json:"ordered"`
Exact bool `json:"exact"`
}
ExpectedTools describes data-driven tool correctness. Ordered uses greedy subsequence matching; otherwise matching is unordered and one-to-one. Exact additionally requires every actual call to match an expected call.
func (ExpectedTools) Evaluate ¶
func (e ExpectedTools) Evaluate(s Subject) (Check, Score)
Evaluate returns the tool check and its tool_correctness score: matching calls divided by calls made. With no calls, the score is one if none were expected, otherwise zero. The score has no threshold. Objects match recursively as subsets, arrays match exactly, and numbers compare by exact decimal value. Malformed actual arguments are non-matches reported in a failed check's diagnostic, while valid calls still contribute to the score.
type Subject ¶
type Subject interface {
// contains filtered or unexported methods
}
Subject is a sealed input built by a subject constructor, such as Calls. Constructors normalize their inputs inside this package.
func Calls ¶
Calls constructs a subject from the ordered calls chosen by a model. Calls provide arguments but no execution results, errors, or run-level evidence.
func Session ¶
func Session(runs trajectory.Session) Subject
Session constructs a subject in caller-supplied run order, including children. Listing a child separately from its parent selects that child twice.
func TopLevel ¶
TopLevel excludes descendants from calls, events, completion and budgets. Explicit session members remain roots even if they were another run's child.
func Trajectory ¶
func Trajectory(run *trajectory.Trajectory) Subject
Trajectory constructs a subject from one recorded run. Descendant calls follow their parent call in the trajectory's canonical child-link order.