Documentation
¶
Overview ¶
Package tavily implements a web search tool backed by the Tavily API (https://docs.tavily.com), and serves as the reference implementation of the tools.ITool contract.
The tool is registered with an assistant like any other:
websearch, err := tavily.New() // reads TAVILY_API_KEY
if err != nil {
return err
}
agent = agent.WithTools(websearch)
Use NewWithAPIKey to supply the key directly. Search behavior is tuned with Tool.WithSearchOpts; the defaults are a basic search of at most 5 general results with an LLM-generated answer included.
It also implements tools.MCPTool, so the same instance can be published over MCP with Tool.RegisterMCP.
Note that the tool's default name is ToolName ("tavily_web_search"), not "web_search" — the latter is reserved by the assistants package for provider-native web search grounding.
Index ¶
- Constants
- Variables
- type SearchOpts
- type SearchRequest
- type SearchResult
- type Tool
- func (t *Tool) Call(ctx context.Context, input string) (string, error)
- func (t *Tool) Description() string
- func (t *Tool) Name() string
- func (t *Tool) Parameters() *jsonschema.Schema
- func (t *Tool) RegisterMCP(registrator tools.McpServerRegistrator) error
- func (t *Tool) Run(ctx context.Context, req *SearchRequest) (*SearchResult, error)
- func (t *Tool) RunMCP(ctx context.Context, req *SearchRequest) (*mcp.ToolResponse, error)
- func (t *Tool) WithBaseURL(baseURL string) *Tool
- func (t *Tool) WithDescription(description string) *Tool
- func (t *Tool) WithHTTPClient(client *http.Client) *Tool
- func (t *Tool) WithName(name string) *Tool
- func (t *Tool) WithSearchOpts(opts SearchOpts) *Tool
Constants ¶
const ToolName = "tavily_web_search"
Variables ¶
var DefaultAPIKeyEnvName = "TAVILY_API_KEY"
Functions ¶
This section is empty.
Types ¶
type SearchOpts ¶ added in v0.6.31
type SearchOpts struct {
// Available options: basic, advanced
// A basic search costs 1 API Credit, while an advanced search costs 2 API Credits.
SearchDepth string `json:"search_depth,omitempty"`
// Available options: general, news
Topic string `json:"topic,omitempty"`
// Include an LLM-generated answer to the provided query.
// `basic` or `true` returns a quick answer.
// `advanced` returns a more detailed answer.
IncludeAnswer bool `json:"include_answer,omitempty"`
// Required range: 0 <= x <= 20
MaxResults int `json:"max_results,omitempty"`
// A list of domains to specifically include in the search results.
IncludeDomains []string `json:"include_domains,omitempty"`
ExcludeDomains []string `json:"exclude_domains,omitempty"`
UseCache bool `json:"use_cache,omitempty"`
}
SearchOpts represents the options for a web search. See: https://docs.tavily.com/documentation/api-reference/endpoint/search
type SearchRequest ¶
type SearchRequest struct {
Query string `json:"Query" yaml:"Query" jsonschema:"title=Search Query,description=The query to search web."`
}
SearchRequest represents the tool input.
type SearchResult ¶
type SearchResult struct {
Results []tavilyModels.SearchResult `json:"results" yaml:"Results" jsonschema:"title=Search Results,description=The results from a web pages."`
Answer string `json:"answer,omitempty" yaml:"Answer" jsonschema:"title=Final Answer,description=The aggregated answer from a web search."`
}
SearchResult represents the structure for a search response
func (*SearchResult) GetContent ¶
func (i *SearchResult) GetContent() string
func (*SearchResult) String ¶
func (r *SearchResult) String() string
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool is a tool that provides a web search functionality
func NewWithAPIKey ¶
func (*Tool) Description ¶
func (*Tool) Parameters ¶
func (t *Tool) Parameters() *jsonschema.Schema
func (*Tool) RegisterMCP ¶ added in v0.1.9
func (t *Tool) RegisterMCP(registrator tools.McpServerRegistrator) error
func (*Tool) Run ¶
func (t *Tool) Run(ctx context.Context, req *SearchRequest) (*SearchResult, error)
func (*Tool) RunMCP ¶ added in v0.1.9
func (t *Tool) RunMCP(ctx context.Context, req *SearchRequest) (*mcp.ToolResponse, error)
func (*Tool) WithBaseURL ¶
func (*Tool) WithDescription ¶ added in v0.7.35
func (*Tool) WithSearchOpts ¶ added in v0.6.31
func (t *Tool) WithSearchOpts(opts SearchOpts) *Tool