search

package
v0.8.2 Latest Latest
Warning

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

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

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

View Source
const DefaultMaxBytes int64 = 5 * 1024 * 1024

DefaultMaxBytes is the maximum response body size (5 MB).

View Source
const DefaultMaxChars = 50000

DefaultMaxChars is the default character limit for extracted text.

View Source
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

func FetchToolDefinition() map[string]any

ToolDefinition returns the JSON Schema parameters for the web_fetch tool.

func FetchToolHandler added in v0.8.0

func FetchToolHandler(f *Fetcher) func(ctx context.Context, args map[string]any) (string, error)

ToolHandler returns a function compatible with the tools.Tool Handler signature. It wraps the Fetcher for use as an agent tool.

func FormatResults

func FormatResults(results []Result, count int) string

FormatResults builds a human-readable result string.

func ToolDefinition

func ToolDefinition() map[string]any

ToolDefinition returns the JSON Schema parameters for the web_search tool.

func ToolHandler

func ToolHandler(mgr *Manager) func(ctx context.Context, args map[string]any) (string, error)

ToolHandler returns a function compatible with the tools.Tool Handler signature. It wraps the Manager's search method for use as an agent tool.

Types

type Brave

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

Brave implements the Provider interface for the Brave Search API.

func NewBrave

func NewBrave(apiKey string) *Brave

NewBrave creates a Brave Search provider.

func (*Brave) Name

func (b *Brave) Name() string

func (*Brave) Search

func (b *Brave) Search(ctx context.Context, query string, opts Options) ([]Result, error)

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.

func (*Fetcher) Fetch added in v0.8.0

func (f *Fetcher) Fetch(ctx context.Context, rawURL string, maxChars int) (*FetchResult, error)

Fetch downloads the URL and extracts readable text content. maxChars limits the output length; 0 uses DefaultMaxChars.

type Manager

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

Manager holds configured providers and routes searches.

func NewManager

func NewManager(primary string) *Manager

NewManager creates a search manager. The primary provider name determines which backend is used by default.

func (*Manager) Configured

func (m *Manager) Configured() bool

Configured reports whether at least one provider is registered.

func (*Manager) Providers

func (m *Manager) Providers() []string

Providers returns the names of all registered providers.

func (*Manager) Register

func (m *Manager) Register(p Provider)

Register adds a provider to the manager.

func (*Manager) Search

func (m *Manager) Search(ctx context.Context, query string, opts Options) ([]Result, error)

Search runs a query against the primary provider.

func (*Manager) SearchWith

func (m *Manager) SearchWith(ctx context.Context, provider, query string, opts Options) ([]Result, error)

SearchWith runs a query against a specific named provider.

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

func NewSearXNG(baseURL string) *SearXNG

NewSearXNG creates a SearXNG provider. The baseURL should be the root URL of the SearXNG instance (e.g., "http://localhost:8080").

func (*SearXNG) Name

func (s *SearXNG) Name() string

func (*SearXNG) Search

func (s *SearXNG) Search(ctx context.Context, query string, opts Options) ([]Result, error)

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.

Jump to

Keyboard shortcuts

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