Documentation
¶
Index ¶
- Constants
- func NewBingTool(apiKey string) tool.CallableTool
- func NewDDGTool(opts ...DDGOption) tool.CallableTool
- func NewTool(cfg Config, secretProvider security.SecretProvider, opts ...DDGOption) tool.CallableTool
- func NewWikipediaTool(opts ...WikipediaOption) tool.CallableTool
- type BingSearchRequest
- type Config
- type DDGOption
- type DDGSearchRequest
- type ProviderOption
- type SearchRequest
- type ToolProvider
- type WikipediaOption
- type WikipediaSearchRequest
Constants ¶
const ( ProviderDuckDuckGo = "duckduckgo" ProviderGoogle = "google" ProviderBing = "bing" )
Supported provider names for the Provider config field.
Variables ¶
This section is empty.
Functions ¶
func NewBingTool ¶
func NewBingTool(apiKey string) tool.CallableTool
NewBingTool creates a new Bing Web Search tool wrapped in the trpc-agent tool schema. The returned tool has the name "bing_search" and can be tested or composed independently.
func NewDDGTool ¶
func NewDDGTool(opts ...DDGOption) tool.CallableTool
NewDDGTool creates a new DuckDuckGo HTML search tool that scrapes real web search results from html.duckduckgo.com. This replaces the Instant Answer API tool which only worked for factual/encyclopedic queries. Without this tool, the agent has no free, key-less web search fallback and would fail on any query that isn't a well-known entity or definition.
func NewTool ¶
func NewTool(cfg Config, secretProvider security.SecretProvider, opts ...DDGOption) tool.CallableTool
NewTool creates a new web search tool configured to use a single provider. When Provider is empty it defaults to DuckDuckGo which requires no API keys. If the selected provider is missing credentials, it logs a warning and falls back to DuckDuckGo. When provider is Google and secretProvider is non-nil, OAuth is used for search when UseGoogleOAuth is true or GoogleAPIKey is empty (same token as Calendar/Drive/Gmail).
Optional DDGOptions can be provided to configure the fallback DuckDuckGo tool (e.g. for testing).
func NewWikipediaTool ¶
func NewWikipediaTool(opts ...WikipediaOption) tool.CallableTool
Types ¶
type BingSearchRequest ¶
type BingSearchRequest struct {
Query string `json:"query" jsonschema:"description=The search query to execute"`
}
BingSearchRequest is the input schema for the standalone Bing search tool.
type Config ¶
type Config struct {
Provider string `yaml:"provider,omitempty" toml:"provider,omitempty"`
GoogleAPIKey string `yaml:"google_api_key,omitempty" toml:"google_api_key,omitempty"`
GoogleCX string `yaml:"google_cx,omitempty" toml:"google_cx,omitempty"`
UseGoogleOAuth bool `yaml:"use_google_oauth,omitempty" toml:"use_google_oauth,omitempty"` // use shared Google OAuth token for search when SecretProvider is set
BingAPIKey string `yaml:"bing_api_key,omitempty" toml:"bing_api_key,omitempty"`
}
Config holds configuration for the web search tool. Provider selects the search backend: "google", "bing", or "duckduckgo" (default). Only one provider is active at a time. When Provider is "google", either set GoogleAPIKey+GoogleCX (API key auth; 100 free queries/day, then billing) or set UseGoogleOAuth true and GoogleCX (uses shared Google sign-in token; requires scope https://www.googleapis.com/auth/cse per Custom Search JSON API). Re-run the Google OAuth browser flow if the token was created before the cse scope was added.
type DDGOption ¶
type DDGOption func(*ddgHTMLTool)
DDGOption is a functional option for configuring the DuckDuckGo HTML tool.
func WithDDGEndpoint ¶
WithDDGEndpoint overrides the default DuckDuckGo HTML endpoint. Primarily used for testing with httptest.Server.
func WithDDGHTTPClient ¶
WithDDGHTTPClient sets a custom HTTP client for the DuckDuckGo tool. Useful for testing with httptest.Server or for custom transport configuration. The provided *http.Client is wrapped in a retryablehttp.Client with DDG-specific retry settings.
type DDGSearchRequest ¶
type DDGSearchRequest struct {
Query string `json:"query" jsonschema:"description=The search query to execute"`
}
DDGSearchRequest is the input schema for the DuckDuckGo HTML search tool.
type ProviderOption ¶
type ProviderOption func(*ToolProvider)
ProviderOption configures the websearch ToolProvider (e.g. WithSecretProvider).
func WithDDGOptions ¶
func WithDDGOptions(ddgOpts ...DDGOption) ProviderOption
WithDDGOptions passes options to the fallback DuckDuckGo tool (e.g. for testing).
func WithSecretProvider ¶
func WithSecretProvider(sp security.SecretProvider) ProviderOption
WithSecretProvider sets the SecretProvider so Google search can use the shared Google OAuth token (same sign-in as Calendar, Drive, Gmail) when UseGoogleOAuth is true or google_api_key is not set.
type SearchRequest ¶
type SearchRequest struct {
Query string `json:"query" jsonschema:"description=The search query to execute"`
}
SearchRequest is the input for the web_search tool.
type ToolProvider ¶
type ToolProvider struct {
// contains filtered or unexported fields
}
ToolProvider wraps websearch configuration and satisfies the tools.ToolProviders interface so it can be passed directly to tools.NewRegistry. Without this, websearch tools would need to be constructed inline inside the registry.
func NewToolProvider ¶
func NewToolProvider(cfg Config, opts ...ProviderOption) *ToolProvider
NewToolProvider creates a ToolProvider from the given websearch config. Pass WithSecretProvider(sp) to enable Google search via the shared OAuth token.
func (*ToolProvider) GetTools ¶
func (p *ToolProvider) GetTools() []tool.Tool
GetTools returns the websearch tool configured from the provider's config, as well as the separate wikipedia_search tool.
type WikipediaOption ¶
type WikipediaOption func(*wikipediaTool)
func WithWikipediaEndpoint ¶
func WithWikipediaEndpoint(endpoint string) WikipediaOption
func WithWikipediaHTTPClient ¶
func WithWikipediaHTTPClient(c *http.Client) WikipediaOption
type WikipediaSearchRequest ¶
type WikipediaSearchRequest struct {
Query string `json:"query" jsonschema:"description=The search query to execute"`
}