Documentation
¶
Index ¶
- Constants
- func ExtractDiscoveredToolNames(messages []any) map[string]bool
- func GetAutoThresholdPercent() int
- func GetAutoToolSearchCharThreshold(contextWindow int) int
- func GetDeferredTools(tools []contract.Tool) []contract.Tool
- func GetNonDeferredTools(tools []contract.Tool) []contract.Tool
- func IsDeferredTool(tool contract.Tool) bool
- func IsToolSearchEnabled() bool
- func IsToolSearchEnabledOptimistic() bool
- func ModelSupportsToolReference(model string) bool
- func ParseAutoPercentage(value string) (int, bool)
- type BM25Engine
- type SearchMatch
- type ToolSearchConfig
- type ToolSearchMode
- type ToolSearchOutput
- type ToolSearchTool
- func (t *ToolSearchTool) BackfillInput(_ context.Context, in map[string]any) map[string]any
- func (t *ToolSearchTool) Call(ctx context.Context, input contract.CallInput, _ types.CanUseToolFn) (contract.CallResult, error)
- func (t *ToolSearchTool) CheckPermissions(_ context.Context, in map[string]any, _ contract.ToolUseContext) types.PermissionResult
- func (t *ToolSearchTool) Definition() contract.Definition
- func (t *ToolSearchTool) Description(_ context.Context) (string, error)
- func (t *ToolSearchTool) FormatResult(data any) string
- func (t *ToolSearchTool) IsConcurrencySafe(_ map[string]any) bool
- func (t *ToolSearchTool) IsEnabled() bool
- func (t *ToolSearchTool) IsReadOnly(_ map[string]any) bool
- func (t *ToolSearchTool) ValidateInput(_ context.Context, in map[string]any) (map[string]any, error)
Constants ¶
const DefaultAutoThresholdPercent = 10
const DefaultMaxResults = 8
DefaultMaxResults mirrors Codex's TOOL_SEARCH_DEFAULT_LIMIT = 8.
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.
const ToolSearchEnvVar = "ENABLE_TOOL_SEARCH"
const ToolSearchToolName = "tool_search"
Variables ¶
This section is empty.
Functions ¶
func GetAutoThresholdPercent ¶
func GetAutoThresholdPercent() int
func IsDeferredTool ¶
func IsToolSearchEnabled ¶
func IsToolSearchEnabled() bool
func IsToolSearchEnabledOptimistic ¶
func IsToolSearchEnabledOptimistic() bool
func ParseAutoPercentage ¶
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 ¶
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 (*ToolSearchTool) Call ¶
func (t *ToolSearchTool) Call(ctx context.Context, input contract.CallInput, _ types.CanUseToolFn) (contract.CallResult, error)
func (*ToolSearchTool) CheckPermissions ¶
func (t *ToolSearchTool) CheckPermissions(_ context.Context, in map[string]any, _ contract.ToolUseContext) types.PermissionResult
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