Documentation
¶
Index ¶
- Variables
- func FormatResults(results []SearchResult, query string) string
- func RegisterDefaultTools() error
- type Article
- type BaseSearchTool
- type Category
- type GitHubOption
- type GitHubSearch
- type Registry
- func (r *Registry) DescribeAll() string
- func (r *Registry) Get(name string) (SearchTool, bool)
- func (r *Registry) GetByCategory(category Category) []SearchTool
- func (r *Registry) List() []string
- func (r *Registry) Register(category Category, tool SearchTool) error
- func (r *Registry) SearchAll(ctx context.Context, category Category, query string, limitPerTool int) ([]SearchResult, error)
- type ScholarOption
- type ScholarPaper
- type ScholarSearch
- type SearchResult
- type SearchTool
- type SogouSearchResult
- type TavilyOption
- type TavilyResponse
- type TavilyResult
- type TavilySearch
- type WeChatOption
- type WeChatSearch
- func (w *WeChatSearch) Call(ctx context.Context, input string) (string, error)
- func (w *WeChatSearch) Description() string
- func (w *WeChatSearch) Name() string
- func (w *WeChatSearch) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
- func (w *WeChatSearch) SearchArticles(ctx context.Context, query string, count int) ([]Article, error)
- type ZhihuOption
- type ZhihuSearch
- type ZhihuSearchResult
Constants ¶
This section is empty.
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry is the default global registry.
Functions ¶
func FormatResults ¶
func FormatResults(results []SearchResult, query string) string
FormatResults formats search results into a readable string. It limits the output size to avoid exceeding token limits.
func RegisterDefaultTools ¶
func RegisterDefaultTools() error
RegisterDefaultTools registers all default search tools.
Types ¶
type Article ¶
type Article struct {
Title string
SogouURL string
RealURL string
PublishTime string
Content string
}
Article represents a WeChat article search result.
type BaseSearchTool ¶
BaseSearchTool provides common functionality for search tools.
func (*BaseSearchTool) GetDefaultUserAgent ¶
func (b *BaseSearchTool) GetDefaultUserAgent() string
GetDefaultUserAgent returns the default user agent.
func (*BaseSearchTool) SetUserAgent ¶
func (b *BaseSearchTool) SetUserAgent(ua string)
SetUserAgent sets a custom user agent.
type GitHubOption ¶
type GitHubOption func(*GitHubSearch)
GitHubOption is a function type for configuring GitHubSearch.
func WithGitHubTimeout ¶
func WithGitHubTimeout(timeout time.Duration) GitHubOption
WithGitHubTimeout sets the request timeout.
func WithGitHubToken ¶
func WithGitHubToken(token string) GitHubOption
WithGitHubToken sets the GitHub Personal Access Token.
func WithGitHubUserAgent ¶
func WithGitHubUserAgent(ua string) GitHubOption
WithGitHubUserAgent sets a custom User-Agent header.
type GitHubSearch ¶
type GitHubSearch struct {
UserAgent string
Timeout time.Duration
Token string // GitHub Personal Access Token (optional but recommended)
}
GitHubSearch is a tool for searching GitHub repositories, code, and issues.
func NewGitHubSearch ¶
func NewGitHubSearch(opts ...GitHubOption) (*GitHubSearch, error)
NewGitHubSearch creates a new GitHubSearch tool.
func (*GitHubSearch) Description ¶
func (g *GitHubSearch) Description() string
Description returns the description of the tool.
func (*GitHubSearch) Search ¶
func (g *GitHubSearch) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
Search implements the SearchTool interface.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages all available search tools.
func (*Registry) DescribeAll ¶
DescribeAll returns descriptions of all registered tools.
func (*Registry) Get ¶
func (r *Registry) Get(name string) (SearchTool, bool)
Get retrieves a tool by name.
func (*Registry) GetByCategory ¶
func (r *Registry) GetByCategory(category Category) []SearchTool
GetByCategory returns all tools in a specific category.
type ScholarOption ¶
type ScholarOption func(*ScholarSearch)
ScholarOption is a function type for configuring ScholarSearch.
func WithScholarTimeout ¶
func WithScholarTimeout(timeout time.Duration) ScholarOption
WithScholarTimeout sets the request timeout.
func WithScholarUserAgent ¶
func WithScholarUserAgent(ua string) ScholarOption
WithScholarUserAgent sets a custom User-Agent header.
type ScholarPaper ¶
type ScholarPaper struct {
Title string
URL string
Authors string
Year string
Abstract string
Source string
Citations int
}
ScholarPaper represents a paper from Google Scholar.
type ScholarSearch ¶
ScholarSearch is a tool for searching academic papers via Google Scholar.
func NewScholarSearch ¶
func NewScholarSearch(opts ...ScholarOption) (*ScholarSearch, error)
NewScholarSearch creates a new ScholarSearch tool.
func (*ScholarSearch) Description ¶
func (s *ScholarSearch) Description() string
Description returns the description of the tool.
func (*ScholarSearch) Name ¶
func (s *ScholarSearch) Name() string
Name returns the name of the tool.
func (*ScholarSearch) Search ¶
func (s *ScholarSearch) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
Search implements the SearchTool interface.
type SearchResult ¶
type SearchResult struct {
Title string // 标题
URL string // 链接
Author string // 作者/发布者
PublishTime string // 发布时间
Summary string // 内容摘要
Content string // 完整内容(可选)
Source string // 来源平台
}
SearchResult represents a unified search result across different sources.
type SearchTool ¶
type SearchTool interface {
// Name returns the tool name
Name() string
// Description returns what this tool does
Description() string
// Call executes the search with the given input query
// Returns formatted results as a string
Call(ctx context.Context, input string) (string, error)
// Search performs the actual search and returns structured results
// This can be used when you need programmatic access to the results
Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
}
SearchTool is the unified interface for all search tools.
type SogouSearchResult ¶
SogouSearchResult represents a search result from Sogou WeChat search.
type TavilyOption ¶
type TavilyOption func(*TavilySearch)
TavilyOption is a function type for configuring TavilySearch.
func WithTavilyAPIKey ¶
func WithTavilyAPIKey(apiKey string) TavilyOption
WithTavilyAPIKey sets the Tavily API key.
func WithTavilyMaxResults ¶
func WithTavilyMaxResults(maxResults int) TavilyOption
WithTavilyMaxResults sets the maximum number of results to return.
func WithTavilySearchDepth ¶
func WithTavilySearchDepth(depth string) TavilyOption
WithTavilySearchDepth sets the search depth ("basic" or "advanced").
func WithTavilyTimeout ¶
func WithTavilyTimeout(timeout time.Duration) TavilyOption
WithTavilyTimeout sets the request timeout.
func WithTavilyUserAgent ¶
func WithTavilyUserAgent(ua string) TavilyOption
WithTavilyUserAgent sets a custom User-Agent header.
type TavilyResponse ¶
type TavilyResponse struct {
Answer string `json:"answer"`
Query string `json:"query"`
Results []TavilyResult `json:"results"`
}
TavilyResponse represents the response from Tavily API.
type TavilyResult ¶
type TavilyResult struct {
Title string `json:"title"`
URL string `json:"url"`
Content string `json:"content"`
Score float64 `json:"score"`
RawContent string `json:"raw_content"`
Snippet string `json:"snippet"`
PublishedDate string `json:"published_date"`
Author string `json:"author"`
}
TavilyResult represents a single search result from Tavily.
type TavilySearch ¶
type TavilySearch struct {
APIKey string
UserAgent string
Timeout time.Duration
MaxResults int
SearchDepth string // "basic" or "advanced"
}
TavilySearch is a tool for searching using Tavily API. Tavily is a search API specifically designed for AI agents.
func NewTavilySearch ¶
func NewTavilySearch(opts ...TavilyOption) (*TavilySearch, error)
NewTavilySearch creates a new TavilySearch tool.
func (*TavilySearch) Description ¶
func (t *TavilySearch) Description() string
Description returns the description of the tool.
func (*TavilySearch) Search ¶
func (t *TavilySearch) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
Search implements the SearchTool interface.
type WeChatOption ¶
type WeChatOption func(*WeChatSearch)
WeChatOption is a function type for configuring WeChatSearch.
func WithWeChatCount ¶
func WithWeChatCount(count int) WeChatOption
WithWeChatCount sets the number of articles to fetch (1-10).
func WithWeChatUserAgent ¶
func WithWeChatUserAgent(ua string) WeChatOption
WithWeChatUserAgent sets a custom User-Agent header.
type WeChatSearch ¶
WeChatSearch is a tool for searching WeChat official account articles via Sogou.
func NewWeChatSearch ¶
func NewWeChatSearch(opts ...WeChatOption) (*WeChatSearch, error)
NewWeChatSearch creates a new WeChatSearch tool.
func (*WeChatSearch) Description ¶
func (w *WeChatSearch) Description() string
Description returns the description of the tool.
func (*WeChatSearch) Search ¶
func (w *WeChatSearch) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
Search implements the SearchTool interface.
func (*WeChatSearch) SearchArticles ¶
func (w *WeChatSearch) SearchArticles(ctx context.Context, query string, count int) ([]Article, error)
SearchArticles searches WeChat articles via Sogou and returns the results.
type ZhihuOption ¶
type ZhihuOption func(*ZhihuSearch)
ZhihuOption is a function type for configuring ZhihuSearch.
func WithZhihuTimeout ¶
func WithZhihuTimeout(timeout time.Duration) ZhihuOption
WithZhihuTimeout sets the request timeout.
func WithZhihuUserAgent ¶
func WithZhihuUserAgent(ua string) ZhihuOption
WithZhihuUserAgent sets a custom User-Agent header.
type ZhihuSearch ¶
ZhihuSearch is a tool for searching Zhihu questions and answers.
func NewZhihuSearch ¶
func NewZhihuSearch(opts ...ZhihuOption) (*ZhihuSearch, error)
NewZhihuSearch creates a new ZhihuSearch tool.
func (*ZhihuSearch) Description ¶
func (z *ZhihuSearch) Description() string
Description returns the description of the tool.
func (*ZhihuSearch) Search ¶
func (z *ZhihuSearch) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
Search implements the SearchTool interface.