Documentation
¶
Overview ¶
Package toolsfake provides a configurable tools.Tool fake for agent tests. It records every invocation (args, count) and returns a scripted result or error, so tests can assert the loop drove the tool with the expected arguments without hand-rolling a stub each time.
Typical use:
fakeTool := toolsfake.NewTool("echo").
WithResult(`"echo result"`).
WithConfirmation(false)
reg := tools.NewRegistry()
reg.Register(fakeTool)
// ... run the loop ...
if fakeTool.Calls() != 1 {
t.Fatalf("expected 1 call, got %d", fakeTool.Calls())
}
if got := fakeTool.LastArgs(); got != expected {
t.Errorf("unexpected args: %s", got)
}
Index ¶
- type Tool
- func (t *Tool) AllArgs() []string
- func (t *Tool) Calls() int64
- func (t *Tool) Descriptor() tools.ToolDescriptor
- func (t *Tool) Execute(_ context.Context, argsJSON string) (tools.Result, error)
- func (t *Tool) LastArgs() string
- func (t *Tool) WithConfirmation(b bool) *Tool
- func (t *Tool) WithDescription(desc string) *Tool
- func (t *Tool) WithError(err error) *Tool
- func (t *Tool) WithResult(r string) *Tool
- func (t *Tool) WithSchema(s tools.ToolSchema) *Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tool ¶
type Tool struct {
// ResultFn, when non-nil, produces the Execute return value per-call.
// When nil, the tool returns Result / Err unchanged every call.
ResultFn func(argsJSON string) (string, error)
Result string
Err error
// contains filtered or unexported fields
}
Tool is a fake tools.Tool suitable for tests. Safe for concurrent use.
func NewTool ¶
NewTool returns a new fake tool with the given Name. Description defaults to "fake tool", schema defaults to an empty object. Chain the With* methods to configure further.
func (*Tool) AllArgs ¶
AllArgs returns every argsJSON passed across every Execute call, in invocation order. The returned slice is a copy.
func (*Tool) Descriptor ¶
func (t *Tool) Descriptor() tools.ToolDescriptor
Descriptor implements tools.Tool. Returns the configured metadata block (name, description, schema, RequiresConfirmation flag, display).
func (*Tool) Execute ¶
Execute implements tools.Tool. Records the args, returns the configured Result/Err (or ResultFn's output when set) wrapped in a tools.Result.
func (*Tool) LastArgs ¶
LastArgs returns the argsJSON passed to the most recent Execute call, or "" if Execute was never called.
func (*Tool) WithConfirmation ¶
WithConfirmation flips RequiresConfirmation. Default false.
func (*Tool) WithDescription ¶
WithDescription sets the Description returned by the tool.
func (*Tool) WithResult ¶
WithResult sets a fixed result returned from every Execute call.
func (*Tool) WithSchema ¶
func (t *Tool) WithSchema(s tools.ToolSchema) *Tool
WithSchema sets the ToolSchema returned by ParametersSchema.