default_tools

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package default_tools provides built-in tools for smolagents.

This includes core tools like GoInterpreter, WebSearch, FinalAnswer, and other essential tools that agents commonly use.

Index

Constants

This section is empty.

Variables

View Source
var BaseBuiltinPackages = []string{
	"fmt", "math", "math/rand", "strings", "strconv", "time",
	"encoding/json", "encoding/csv", "encoding/base64",
	"regexp", "sort", "unicode", "unicode/utf8",
	"crypto/md5", "crypto/sha1", "crypto/sha256",
	"path", "path/filepath", "net/url",
	"compress/gzip", "archive/zip",
	"bytes", "bufio", "io", "container/list", "container/heap",
}

BaseBuiltinPackages lists Go packages allowed in GoInterpreterTool

View Source
var ToolMapping = map[string]func() tools.Tool{
	"go_interpreter":    func() tools.Tool { return NewGoInterpreterTool() },
	"final_answer":      func() tools.Tool { return NewFinalAnswerTool() },
	"user_input":        func() tools.Tool { return NewUserInputTool() },
	"web_search":        func() tools.Tool { return NewWebSearchTool() },
	"duckduckgo_search": func() tools.Tool { return NewDuckDuckGoSearchTool() },
	"google_search":     func() tools.Tool { return NewGoogleSearchTool() },
	"visit_webpage":     func() tools.Tool { return NewVisitWebpageTool() },
	"wikipedia_search":  func() tools.Tool { return NewWikipediaSearchTool() },
	"speech_to_text":    func() tools.Tool { return NewSpeechToTextTool() },
	"pipeline_tool":     func() tools.Tool { return NewPipelineTool() },
	"vision_browser":    func() tools.Tool { return NewVisionBrowser() },
}

ToolMapping maps tool names to their constructor functions

Functions

func GetToolByName

func GetToolByName(name string) (tools.Tool, error)

GetToolByName returns a tool instance by name

func ListAvailableTools

func ListAvailableTools() []string

ListAvailableTools returns a list of all available tool names

func NewVisionBrowser

func NewVisionBrowser() tools.Tool

NewVisionBrowser creates a new vision browser tool (wrapper)

func RegisterTool

func RegisterTool(name string, constructor func() tools.Tool)

RegisterTool registers a new tool in the global mapping

Types

type DuckDuckGoSearchTool

type DuckDuckGoSearchTool struct {
	*tools.BaseTool
	MaxResults int    `json:"max_results"`
	UserAgent  string `json:"user_agent"`
}

DuckDuckGoSearchTool performs web searches using DuckDuckGo

func NewDuckDuckGoSearchTool

func NewDuckDuckGoSearchTool() *DuckDuckGoSearchTool

NewDuckDuckGoSearchTool creates a new DuckDuckGo search tool

type FinalAnswerTool

type FinalAnswerTool struct {
	*tools.BaseTool
}

FinalAnswerTool provides the final answer to a problem

func NewFinalAnswerTool

func NewFinalAnswerTool() *FinalAnswerTool

NewFinalAnswerTool creates a new final answer tool

type GoExecutor

type GoExecutor interface {
	Execute(code string, authorizedImports []string) (interface{}, error)
	SendVariables(variables map[string]interface{}) error
	SendTools(tools map[string]tools.Tool) error
	GetState() map[string]interface{}
	Reset() error
}

GoExecutor interface for executing Go code

type GoInterpreterTool

type GoInterpreterTool struct {
	*tools.BaseTool
	AuthorizedPackages []string                               `json:"authorized_packages"`
	GoEvaluator        func(string, []string) (string, error) `json:"-"`
	// contains filtered or unexported fields
}

GoInterpreterTool evaluates Go code safely

func NewGoInterpreterTool

func NewGoInterpreterTool(authorizedPackages ...[]string) *GoInterpreterTool

NewGoInterpreterTool creates a new Go interpreter tool

func NewGoInterpreterToolWithExecutor

func NewGoInterpreterToolWithExecutor(executor GoExecutor, authorizedPackages ...[]string) *GoInterpreterTool

NewGoInterpreterToolWithExecutor creates a new Go interpreter tool with a custom executor

func (*GoInterpreterTool) GetExecutor

func (git *GoInterpreterTool) GetExecutor() GoExecutor

GetExecutor returns the Go executor for this tool

func (*GoInterpreterTool) SetExecutor

func (git *GoInterpreterTool) SetExecutor(executor GoExecutor)

SetExecutor sets the Go executor for this tool

type GoogleSearchTool

type GoogleSearchTool struct {
	*tools.BaseTool
	APIKey       string `json:"api_key"`
	SearchEngine string `json:"search_engine"` // "serp" or "serper"
	MaxResults   int    `json:"max_results"`
}

GoogleSearchTool performs web searches using Google Search API

func NewGoogleSearchTool

func NewGoogleSearchTool() *GoogleSearchTool

NewGoogleSearchTool creates a new Google search tool

type PipelineTool

type PipelineTool struct {
	*tools.BaseTool
	PipelineType string `json:"pipeline_type"`
	ModelName    string `json:"model_name"`
	APIKey       string `json:"api_key"`
}

PipelineTool executes HuggingFace transformers pipelines

func NewPipelineTool

func NewPipelineTool() *PipelineTool

NewPipelineTool creates a new pipeline tool

type SpeechToTextTool

type SpeechToTextTool struct {
	*tools.BaseTool
	Model    string `json:"model"`
	Language string `json:"language"`
	APIKey   string `json:"api_key"`
	APIBase  string `json:"api_base"`
}

SpeechToTextTool converts audio to text using Whisper

func NewSpeechToTextTool

func NewSpeechToTextTool() *SpeechToTextTool

NewSpeechToTextTool creates a new speech-to-text tool

type UserInputTool

type UserInputTool struct {
	*tools.BaseTool
}

UserInputTool asks for user input on specific questions

func NewUserInputTool

func NewUserInputTool() *UserInputTool

NewUserInputTool creates a new user input tool

type VisitWebpageTool

type VisitWebpageTool struct {
	*tools.BaseTool
	MaxOutputLength int `json:"max_output_length"`
	Timeout         int `json:"timeout"`
}

VisitWebpageTool visits a webpage and converts it to markdown

func NewVisitWebpageTool

func NewVisitWebpageTool(options ...map[string]interface{}) *VisitWebpageTool

NewVisitWebpageTool creates a new webpage visitor tool

type WebSearchTool

type WebSearchTool struct {
	*tools.BaseTool
	MaxResults int    `json:"max_results"`
	Engine     string `json:"engine"`
}

WebSearchTool performs web searches using multiple engines

func NewWebSearchTool

func NewWebSearchTool(options ...map[string]interface{}) *WebSearchTool

NewWebSearchTool creates a new web search tool

type WikipediaSearchTool

type WikipediaSearchTool struct {
	*tools.BaseTool
	UserAgent     string `json:"user_agent"`
	Language      string `json:"language"`
	ContentType   string `json:"content_type"`
	ExtractFormat string `json:"extract_format"`
}

WikipediaSearchTool searches Wikipedia and returns formatted content

func NewWikipediaSearchTool

func NewWikipediaSearchTool(options ...map[string]interface{}) *WikipediaSearchTool

NewWikipediaSearchTool creates a new Wikipedia search tool

Jump to

Keyboard shortcuts

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