toolsfake

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 4 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 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()
if err := reg.Register(fakeTool); err != nil {
    t.Fatal(err)
}
// ... 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

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

func NewTool(name string) *Tool

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

func (t *Tool) AllArgs() []string

AllArgs returns every argsJSON passed across every Execute call, in invocation order. The returned slice is a copy.

func (*Tool) Calls

func (t *Tool) Calls() int64

Calls returns how many times Execute has been invoked so far.

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

func (t *Tool) Execute(_ context.Context, argsJSON string) (tools.Result, error)

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

func (t *Tool) LastArgs() string

LastArgs returns the argsJSON passed to the most recent Execute call, or "" if Execute was never called.

func (*Tool) WithConfirmation

func (t *Tool) WithConfirmation(b bool) *Tool

WithConfirmation flips RequiresConfirmation. Default false.

func (*Tool) WithDescription

func (t *Tool) WithDescription(desc string) *Tool

WithDescription sets the Description returned by the tool.

func (*Tool) WithError

func (t *Tool) WithError(err error) *Tool

WithError sets a fixed error returned from every Execute call.

func (*Tool) WithResult

func (t *Tool) WithResult(r string) *Tool

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.

Jump to

Keyboard shortcuts

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