tool

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 8 Imported by: 0

README

Tools Package

This package provides implementations of various tools that adhere to the langchaingo Tool interface.

Available Tools

Uses the Tavily API for web search.

Usage:

import "github.com/smallnest/langgraphgo/tool"

// Create a new Tavily search tool
// It will look for TAVILY_API_KEY environment variable if apiKey is empty
tavilyTool, err := tool.NewTavilySearch("", tool.WithTavilySearchDepth("advanced"))
if err != nil {
    log.Fatal(err)
}

// Use the tool
result, err := tavilyTool.Call(context.Background(), "what is langgraphgo?")

Uses the Exa API for neural search.

Usage:

import "github.com/smallnest/langgraphgo/tool"

// Create a new Exa search tool
// It will look for EXA_API_KEY environment variable if apiKey is empty
exaTool, err := tool.NewExaSearch("", tool.WithExaNumResults(10))
if err != nil {
    log.Fatal(err)
}

// Use the tool
result, err := exaTool.Call(context.Background(), "golang agent frameworks")

Interface

All tools implement the following interface:

type Tool interface {
    Name() string
    Description() string
    Call(ctx context.Context, input string) (string, error)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BochaOption added in v0.3.2

type BochaOption func(*BochaSearch)

func WithBochaBaseURL added in v0.3.2

func WithBochaBaseURL(url string) BochaOption

WithBochaBaseURL sets the base URL for the Bocha API.

func WithBochaCount added in v0.3.2

func WithBochaCount(count int) BochaOption

WithBochaCount sets the number of results to return.

func WithBochaFreshness added in v0.3.2

func WithBochaFreshness(freshness string) BochaOption

WithBochaFreshness sets the freshness filter for the search. Valid values: "oneDay", "oneWeek", "oneMonth", "oneYear", "noLimit".

func WithBochaSummary added in v0.3.2

func WithBochaSummary(summary bool) BochaOption

WithBochaSummary sets whether to return a summary.

type BochaSearch added in v0.3.2

type BochaSearch struct {
	APIKey    string
	BaseURL   string
	Count     int
	Freshness string
	Summary   bool
}

BochaSearch is a tool that uses the Bocha API to search the web.

func NewBochaSearch added in v0.3.2

func NewBochaSearch(apiKey string, opts ...BochaOption) (*BochaSearch, error)

NewBochaSearch creates a new BochaSearch tool. If apiKey is empty, it tries to read from BOCHA_API_KEY environment variable.

func (*BochaSearch) Call added in v0.3.2

func (b *BochaSearch) Call(ctx context.Context, input string) (string, error)

Call executes the search.

func (*BochaSearch) Description added in v0.3.2

func (b *BochaSearch) Description() string

Description returns the description of the tool.

func (*BochaSearch) Name added in v0.3.2

func (b *BochaSearch) Name() string

Name returns the name of the tool.

type BraveOption added in v0.3.2

type BraveOption func(*BraveSearch)

func WithBraveBaseURL added in v0.3.2

func WithBraveBaseURL(baseURL string) BraveOption

WithBraveBaseURL sets the base URL for the Brave Search API.

func WithBraveCount added in v0.3.2

func WithBraveCount(count int) BraveOption

WithBraveCount sets the number of results to return (1-20).

func WithBraveCountry added in v0.3.2

func WithBraveCountry(country string) BraveOption

WithBraveCountry sets the country code for search results (e.g., "US", "CN").

func WithBraveLang added in v0.3.2

func WithBraveLang(lang string) BraveOption

WithBraveLang sets the language code for search results (e.g., "en", "zh").

type BraveSearch added in v0.3.2

type BraveSearch struct {
	APIKey  string
	BaseURL string
	Count   int
	Country string
	Lang    string
}

BraveSearch is a tool that uses the Brave Search API to search the web.

func NewBraveSearch added in v0.3.2

func NewBraveSearch(apiKey string, opts ...BraveOption) (*BraveSearch, error)

NewBraveSearch creates a new BraveSearch tool. If apiKey is empty, it tries to read from BRAVE_API_KEY environment variable.

func (*BraveSearch) Call added in v0.3.2

func (b *BraveSearch) Call(ctx context.Context, input string) (string, error)

Call executes the search.

func (*BraveSearch) Description added in v0.3.2

func (b *BraveSearch) Description() string

Description returns the description of the tool.

func (*BraveSearch) Name added in v0.3.2

func (b *BraveSearch) Name() string

Name returns the name of the tool.

type ExaOption

type ExaOption func(*ExaSearch)

func WithExaBaseURL

func WithExaBaseURL(url string) ExaOption

WithExaBaseURL sets the base URL for the Exa API.

func WithExaNumResults

func WithExaNumResults(num int) ExaOption

WithExaNumResults sets the number of results to return.

type ExaSearch

type ExaSearch struct {
	APIKey     string
	BaseURL    string
	NumResults int
}

ExaSearch is a tool that uses the Exa API to search the web.

func NewExaSearch

func NewExaSearch(apiKey string, opts ...ExaOption) (*ExaSearch, error)

NewExaSearch creates a new ExaSearch tool. If apiKey is empty, it tries to read from EXA_API_KEY environment variable.

func (*ExaSearch) Call

func (t *ExaSearch) Call(ctx context.Context, input string) (string, error)

Call executes the search.

func (*ExaSearch) Description

func (t *ExaSearch) Description() string

Description returns the description of the tool.

func (*ExaSearch) Name

func (t *ExaSearch) Name() string

Name returns the name of the tool.

type SearchResult added in v0.3.2

type SearchResult struct {
	Text   string
	Images []string
}

SearchResult represents a single search result with images

type TavilyOption

type TavilyOption func(*TavilySearch)

func WithTavilyBaseURL

func WithTavilyBaseURL(url string) TavilyOption

WithTavilyBaseURL sets the base URL for the Tavily API.

func WithTavilySearchDepth

func WithTavilySearchDepth(depth string) TavilyOption

WithTavilySearchDepth sets the search depth for the Tavily API. Valid values are "basic" and "advanced".

type TavilySearch

type TavilySearch struct {
	APIKey      string
	BaseURL     string
	SearchDepth string
}

TavilySearch is a tool that uses the Tavily API to search the web.

func NewTavilySearch

func NewTavilySearch(apiKey string, opts ...TavilyOption) (*TavilySearch, error)

NewTavilySearch creates a new TavilySearch tool. If apiKey is empty, it tries to read from TAVILY_API_KEY environment variable.

func (*TavilySearch) Call

func (t *TavilySearch) Call(ctx context.Context, input string) (string, error)

Call executes the search.

func (*TavilySearch) CallWithImages added in v0.3.2

func (t *TavilySearch) CallWithImages(ctx context.Context, input string) (*SearchResult, error)

CallWithImages executes the search and returns both text and images.

func (*TavilySearch) Description

func (t *TavilySearch) Description() string

Description returns the description of the tool.

func (*TavilySearch) Name

func (t *TavilySearch) Name() string

Name returns the name of the tool.

Jump to

Keyboard shortcuts

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