websearch

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: 9 Imported by: 0

Documentation

Index

Constants

View Source
const SearchHint = "search the web for current information"
View Source
const ToolDescription = `` /* 1538-byte string literal not displayed */
View Source
const ToolName = "web_search"

ToolName is the name of the web search tool.

Variables

This section is empty.

Functions

func GetConfiguredProviders

func GetConfiguredProviders() []string

GetConfiguredProviders returns the list of configured providers.

func GetProviderMode

func GetProviderMode() string

GetProviderMode returns the current provider mode.

func IsEnabled

func IsEnabled() bool

IsEnabled reports whether WebSearch should be enabled from environment. Returns true if any provider is configured.

Types

type Input

type Input = searchcore.Input

type Output

type Output = searchcore.Output

type RunnerFn

type RunnerFn func(ctx context.Context, query string, allowedDomains, blockedDomains []string) (Output, error)

RunnerFn is an optional hook that replaces the env-based provider chain. It receives the query and domain filters and must return a full Output. When nil the tool falls back to the env-configured provider chain.

func NewRunnerFromKeys

func NewRunnerFromKeys(keys map[string]string) RunnerFn

NewRunnerFromKeys builds a RunnerFn that uses explicit per-user provider API keys instead of reading from process environment. This enables safe concurrent job execution across multiple owners without os.Setenv races. keys must be keyed by provider name: "tavily", "exa", "jina", "langsearch".

type Tool

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

Tool implements the WebSearch tool.

func NewTool

func NewTool() *Tool

NewTool creates a new WebSearch tool.

func NewToolWithProvider

func NewToolWithProvider(provider searchproviders.SearchProvider) *Tool

NewToolWithProvider creates a WebSearch tool with an explicit provider. Deprecated: Use the provider chain system instead.

func (*Tool) BackfillInput

func (t *Tool) BackfillInput(ctx context.Context, input map[string]any) map[string]any

BackfillInput enriches a shallow clone of the parsed input with derived permission fields.

func (*Tool) Call

func (t *Tool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)

Call executes the web search using the provider chain.

func (*Tool) CheckPermissions

func (t *Tool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

CheckPermissions applies shared web policy before delegating any remaining decision to the global permission pipeline.

func (*Tool) Definition

func (t *Tool) Definition() tool.Definition

Definition returns the tool definition.

func (*Tool) Description

func (t *Tool) Description(ctx context.Context) (string, error)

Description returns the tool description.

func (*Tool) FormatResult

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

FormatResult serialises the tool output into the tool_result content string.

func (*Tool) IsAvailableNow

func (t *Tool) IsAvailableNow() bool

IsAvailableNow returns true when a search provider is actually available at the current moment — either because a per-request runner was injected by the backend (DB-backed providers) or because at least one env-based provider is configured (TAVILY_API_KEY, EXA_API_KEY, etc.). This is the dynamic check used to hide the tool from the model when no provider is configured, without interfering with session map registration.

func (*Tool) IsConcurrencySafe

func (t *Tool) IsConcurrencySafe(input map[string]any) bool

IsConcurrencySafe reports that WebSearch requests can run concurrently.

func (*Tool) IsEnabled

func (t *Tool) IsEnabled() bool

IsEnabled always returns true so that web_search is registered in the session tool map at session creation time. Actual provider availability is checked at request time via IsAvailableNow, which is called by EffectiveToolSurface after any per-request runner has been injected.

func (*Tool) IsReadOnly

func (t *Tool) IsReadOnly(input map[string]any) bool

IsReadOnly reports that WebSearch does not modify state.

func (*Tool) PreparePermissionMatcher

func (t *Tool) PreparePermissionMatcher(ctx context.Context, input map[string]any) (func(string) bool, error)

PreparePermissionMatcher compiles content-specific permission matching for domain- and provider-aware search rules.

func (*Tool) SetRunner

func (t *Tool) SetRunner(fn RunnerFn)

SetRunner installs a runtime runner that overrides the env-based provider chain. Pass nil to restore the default env-based behaviour.

func (*Tool) ValidateInput

func (t *Tool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)

ValidateInput validates and normalizes WebSearch input.

Jump to

Keyboard shortcuts

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