toolsearch

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 16 Imported by: ? 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 toolsearch finds tools by what they say of themselves, for an agent offered more tools than its requests should carry: a catalog of the tools kept out of the requests, searched with BM25 over Porter2 stems, a listing of it that fits a budget of tokens, the entries of a call made through the bridge and the arguments of such a call checked against the tool's schema

Index

Constants

View Source
const (
	SearchTool   = "tool_search"
	DescribeTool = "tool_describe"
	CallTool     = "tool_call"
)

Names of the three tools that reach the tools found by search, which no other tool may take

View Source
const (
	MostQueries = 7
	MostNames   = 10
)

Most queries one search takes and most names one describe takes

View Source
const (
	SourceMCP    = "mcp"
	SourcePlugin = "plugin"
)

Where a tool found by search comes from, as the results say it

View Source
const (
	Coverage   = 0.5
	MinCovered = 4
)

Share of the answerable terms of a query an entry must hold once the query has at least MinCovered of them, so a long query whose words are only scattered across tools finds nothing

View Source
const CharsPerToken = 4.0

Characters a token is taken to be where no counter counts them, which errs toward fewer tokens

View Source
const MostCalls = 10

Most entries one tool_call runs

View Source
const SummaryChars = 80

Longest summary of a tool a listing gives, its first sentence cut on a word

Variables

This section is empty.

Functions

func Bridge

func Bridge(name string) bool

Whether the name is one of the three tools that reach those found by search

func Estimate

func Estimate(text string) int

Tokens of the text estimated from its length

func Short

func Short(description string, most int) string

The first sentence of a description, its runs of space made one, cut on a word at most so many characters long with an ellipsis

func Stem

func Stem(token string) string

Porter2 stem of one lower case token, so "issues" finds create_issue: kept once worked out, the same for the index and the query

func Text

func Text(name, label, description string, parameters []string) string

What of a tool is searched: the words of its name, its label when the name does not hold it, its description and the names of its parameters

func Tokens

func Tokens(text string) []string

Lower case alphanumeric runs of the text, each stemmed, so what is indexed and what is asked meet

func Validate

func Validate(name string, parameters, args map[string]any) string

Why the arguments a tool_call gives the tool of the name do not fit its parameters, as the model reads it: the required ones it lacks, else the violation of the schema python-jsonschema's best_match would pick, with where it is and the parameters to retry with. Empty when they fit, and when the schema can't be checked here: one that refers to a schema elsewhere, which is never fetched, or one that does not compile, so a call is refused only for what is certainly wrong

Types

type Call

type Call struct {
	Name      string
	Arguments string
}

One tool a tool_call runs: its name and its arguments as a JSON object, every number as the model wrote it

func Calls

func Calls(raw string) ([]Call, string)

What the arguments of a tool_call run, in their order: its calls, a JSON text of them, or the single name and arguments of the shape before calls; a blank arguments is an object of none. Else why they can't run, as the model reads it

type Catalog

type Catalog struct {
	// contains filtered or unexported fields
}

Tools a search looks through, with what BM25 counts over all of them

func NewCatalog

func NewCatalog(entries []Entry) *Catalog

A catalog of the entries, each indexed by the stems of its searched text

func (*Catalog) Entries

func (c *Catalog) Entries() []Entry

What the catalog holds, in the order the entries were given

func (*Catalog) Len

func (c *Catalog) Len() int

How many entries the catalog holds

func (*Catalog) Search

func (c *Catalog) Search(query string, limit int) []Entry

The entries that best answer the query, at most limit: one named exactly by the query first, then by BM25 among those that hold the query's rarest token and enough of its terms

type Entry

type Entry struct {
	Name        string
	Description string
	// Where it comes from as the results say it, SourceMCP or SourcePlugin, and the toolset it is of
	Source, SourceName string
	// Word the listing groups it under, such as the name of its MCP server
	Label string
	// Names of its parameters at the top of its schema, in their order, and those every call must give
	Parameters, Required []string
	// contains filtered or unexported fields
}

One tool a search may find

type Form

type Form string

How much of the tools found by search a listing names, from the most to none

const (
	// Every tool by its name and the first sentence of its description
	Full Form = "full"
	// Every tool by its name alone
	Names Form = "names"
	// The larger groups by their size alone, the others by their tools
	Mixed Form = "mixed"
	// Every group by its size alone
	Groups Form = "groups"
	// Nothing
	None Form = "none"
)

func Listing

func Listing(groups []Group, hidden []Hidden, budget int, count func(text string) int, always bool) (string, Form)

The listing of the tools found by search that fits the budget of tokens as the count counts them: every tool with its summary, else every tool by name, else the largest groups summarized first, else every group summarized; empty when not even that fits, unless always is set, when every group is summarized whatever it takes. With the form it took

type Group

type Group struct {
	Label string
	Tools []Listed
}

A group of tools a listing names together, such as those of one MCP server

type Hidden

type Hidden struct {
	Name string
	// How many tools it has, and why they can't run, a sentence
	Tools  int
	Reason string
}

A server set up for the profile whose every tool can't run now, which the listing names so the model does not take its tools for missing

type Listed

type Listed struct {
	Name, Summary string
}

A tool a listing names, with the summary of its description

Jump to

Keyboard shortcuts

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