tool

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 7 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 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 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) 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