Documentation
¶
Overview ¶
Package fetch provides web page fetching and content extraction. It downloads a URL's HTML and extracts readable text content, stripping navigation, ads, and other boilerplate.
Package search provides a pluggable web search interface for the agent.
Each search provider implements the Provider interface and is registered by name. The Manager selects a provider based on configuration and exposes a single Manager.Search method that the tool layer calls.
Index ¶
- Constants
- func FetchToolDefinition() map[string]any
- func FetchToolHandler(f *Fetcher) func(ctx context.Context, args map[string]any) (string, error)
- func FormatResults(results []Result, count int) string
- func ToolDefinition() map[string]any
- func ToolHandler(mgr *Manager) func(ctx context.Context, args map[string]any) (string, error)
- type Brave
- type BraveConfig
- type FetchResult
- type Fetcher
- type Manager
- func (m *Manager) Configured() bool
- func (m *Manager) Providers() []string
- func (m *Manager) Register(p Provider)
- func (m *Manager) Search(ctx context.Context, query string, opts Options) ([]Result, error)
- func (m *Manager) SearchWith(ctx context.Context, provider, query string, opts Options) ([]Result, error)
- type Options
- type Provider
- type Result
- type SearXNG
- type SearXNGConfig
Constants ¶
const DefaultMaxBytes int64 = 5 * 1024 * 1024
DefaultMaxBytes is the maximum response body size (5 MB).
const DefaultMaxChars = 50000
DefaultMaxChars is the default character limit for extracted text.
const DefaultTimeout = 30 * time.Second
DefaultTimeout is the HTTP request timeout for fetching pages.
Variables ¶
This section is empty.
Functions ¶
func FetchToolDefinition ¶ added in v0.8.0
ToolDefinition returns the JSON Schema parameters for the web_fetch tool.
func FetchToolHandler ¶ added in v0.8.0
ToolHandler returns a function compatible with the tools.Tool Handler signature. It wraps the Fetcher for use as an agent tool.
func FormatResults ¶
FormatResults builds a human-readable result string.
func ToolDefinition ¶
ToolDefinition returns the JSON Schema parameters for the web_search tool.
Types ¶
type Brave ¶
type Brave struct {
// contains filtered or unexported fields
}
Brave implements the Provider interface for the Brave Search API.
type BraveConfig ¶
type BraveConfig struct {
APIKey string `yaml:"api_key"`
}
BraveConfig holds configuration for the Brave Search provider.
func (BraveConfig) Configured ¶
func (c BraveConfig) Configured() bool
Configured reports whether a Brave API key is set.
type FetchResult ¶ added in v0.8.0
type FetchResult struct {
URL string `json:"url"`
Title string `json:"title,omitempty"`
Content string `json:"content"`
ContentType string `json:"content_type,omitempty"`
Truncated bool `json:"truncated,omitempty"`
Length int `json:"length"`
StatusCode int `json:"status_code"`
}
Result holds the fetched and extracted content from a URL.
type Fetcher ¶ added in v0.8.0
type Fetcher struct {
// contains filtered or unexported fields
}
Fetcher downloads and extracts readable content from web pages.
func NewFetcher ¶ added in v0.8.0
func NewFetcher() *Fetcher
New creates a Fetcher with default settings.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds configured providers and routes searches.
func NewManager ¶
NewManager creates a search manager. The primary provider name determines which backend is used by default.
func (*Manager) Configured ¶
Configured reports whether at least one provider is registered.
type Options ¶
type Options struct {
// Count is the maximum number of results to return.
// Providers may return fewer. Zero means provider default.
Count int `json:"count,omitempty"`
// Language is an ISO 639-1 language code (e.g., "en", "de").
Language string `json:"language,omitempty"`
}
Options are optional parameters for a search query.
type Provider ¶
type Provider interface {
// Name returns the provider identifier (e.g., "searxng", "brave").
Name() string
// Search executes a query and returns results.
Search(ctx context.Context, query string, opts Options) ([]Result, error)
}
Provider is the interface that search backends implement.
type Result ¶
type Result struct {
Title string `json:"title"`
URL string `json:"url"`
Snippet string `json:"snippet,omitempty"`
}
Result is a single search result.
type SearXNG ¶
type SearXNG struct {
// contains filtered or unexported fields
}
SearXNG implements the Provider interface for a SearXNG instance.
func NewSearXNG ¶
NewSearXNG creates a SearXNG provider. The baseURL should be the root URL of the SearXNG instance (e.g., "http://localhost:8080").
type SearXNGConfig ¶
type SearXNGConfig struct {
URL string `yaml:"url"`
}
SearXNGConfig holds configuration for the SearXNG provider.
func (SearXNGConfig) Configured ¶
func (c SearXNGConfig) Configured() bool
Configured reports whether a SearXNG URL is set.