toolsearch

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultAutoThresholdPercent = 10
View Source
const DefaultMaxResults = 8

DefaultMaxResults mirrors Codex's TOOL_SEARCH_DEFAULT_LIMIT = 8.

View Source
const ToolSearchDescription = `# Tool discovery

Searches over deferred tool metadata with BM25 and returns matching tools for the next call.

Some tools are not loaded upfront to keep the context window small. Use this tool to find them by keyword before calling them.

## Query forms
- ` + "`select:Name1,Name2`" + ` — fetch these exact tools by name (bypass BM25)
- ` + "`read file`" + ` — free-text BM25 search, returns up to ` + "`max_results`" + ` ranked matches
- ` + "`+slack send`" + ` — ` + "`+`" + `-prefixed terms are required; remaining terms are used for ranking

## When to use
- Before calling a tool that is not visible in your current tool list
- When you need an MCP tool and are unsure of its exact name
- To discover tools by capability ("image generation", "calendar", "git diff")`

ToolSearchDescription is the model-facing description of the tool_search tool. Mirrors Codex's create_tool_search_tool() description mentioning BM25 explicitly.

View Source
const ToolSearchEnvVar = "ENABLE_TOOL_SEARCH"
View Source
const ToolSearchToolName = "tool_search"

Variables

This section is empty.

Functions

func ExtractDiscoveredToolNames

func ExtractDiscoveredToolNames(messages []any) map[string]bool

func GetAutoThresholdPercent

func GetAutoThresholdPercent() int

func GetAutoToolSearchCharThreshold

func GetAutoToolSearchCharThreshold(contextWindow int) int

func GetDeferredTools

func GetDeferredTools(tools []contract.Tool) []contract.Tool

func GetNonDeferredTools

func GetNonDeferredTools(tools []contract.Tool) []contract.Tool

func IsDeferredTool

func IsDeferredTool(tool contract.Tool) bool

func IsToolSearchEnabled

func IsToolSearchEnabled() bool

func IsToolSearchEnabledOptimistic

func IsToolSearchEnabledOptimistic() bool

func ModelSupportsToolReference

func ModelSupportsToolReference(model string) bool

func ParseAutoPercentage

func ParseAutoPercentage(value string) (int, bool)

Types

type BM25Engine

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

BM25Engine is an in-memory BM25 full-text search engine. Mirrors Codex's use of the `bm25` Rust crate with Language::English.

func NewBM25Engine

func NewBM25Engine(texts []string) *BM25Engine

NewBM25Engine builds a BM25 index from (id, text) pairs. The id slice is positional: ids[i] is the external identifier for docs[i].

func (*BM25Engine) Search

func (e *BM25Engine) Search(query string, limit int) []bm25SearchResult

Search returns up to limit results ranked by BM25 score for query. Mirrors Codex's SearchEngine::search(query, limit).

type SearchMatch

type SearchMatch struct {
	Name        string  `json:"name"`
	Namespace   string  `json:"namespace"`
	Score       float64 `json:"score"`
	Description string  `json:"description"`
	SearchHint  string  `json:"search_hint,omitempty"`
	Category    string  `json:"category,omitempty"`
	IsDeferred  bool    `json:"is_deferred"`
	IsMCP       bool    `json:"is_mcp"`
}

SearchMatch is one result returned by tool_search. Mirrors Codex's LoadableToolSpec (with defer_loading) but includes the full Seshat definition so the model can inspect the schema immediately.

type ToolSearchConfig

type ToolSearchConfig struct {
	Registry *registry.Registry
}

func DefaultToolSearchToolConfig

func DefaultToolSearchToolConfig(reg *registry.Registry) *ToolSearchConfig

type ToolSearchMode

type ToolSearchMode string
const (
	ToolSearchModeTST      ToolSearchMode = "tst"
	ToolSearchModeTSTAuto  ToolSearchMode = "tst-auto"
	ToolSearchModeStandard ToolSearchMode = "standard"
)

func GetToolSearchMode

func GetToolSearchMode() ToolSearchMode

type ToolSearchOutput

type ToolSearchOutput struct {
	Query      string        `json:"query"`
	Matches    []SearchMatch `json:"matches"`
	TotalTools int           `json:"total_tools"`
	Scored     int           `json:"scored"`
}

ToolSearchOutput is the JSON payload returned by tool_search.

type ToolSearchTool

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

ToolSearchTool implements the BM25-powered tool_search tool. Mirrors Codex's ToolSearchHandler (core/src/tools/handlers/tool_search.rs).

func NewToolSearchTool

func NewToolSearchTool(reg *registry.Registry) *ToolSearchTool

func (*ToolSearchTool) BackfillInput

func (t *ToolSearchTool) BackfillInput(_ context.Context, in map[string]any) map[string]any

func (*ToolSearchTool) Call

func (*ToolSearchTool) CheckPermissions

func (*ToolSearchTool) Definition

func (t *ToolSearchTool) Definition() contract.Definition

func (*ToolSearchTool) Description

func (t *ToolSearchTool) Description(_ context.Context) (string, error)

func (*ToolSearchTool) FormatResult

func (t *ToolSearchTool) FormatResult(data any) string

func (*ToolSearchTool) IsConcurrencySafe

func (t *ToolSearchTool) IsConcurrencySafe(_ map[string]any) bool

func (*ToolSearchTool) IsEnabled

func (t *ToolSearchTool) IsEnabled() bool

func (*ToolSearchTool) IsReadOnly

func (t *ToolSearchTool) IsReadOnly(_ map[string]any) bool

func (*ToolSearchTool) ValidateInput

func (t *ToolSearchTool) ValidateInput(_ context.Context, in map[string]any) (map[string]any, error)

Jump to

Keyboard shortcuts

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