tools

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultViewTokens = 1024

DefaultViewTokens is the number of tokens to show to the model used when calling displayPage

Variables

This section is empty.

Functions

This section is empty.

Types

type Browser

type Browser struct {
	// contains filtered or unexported fields
}

func NewBrowser

func NewBrowser(state *responses.BrowserStateData) *Browser

func (*Browser) State

func (b *Browser) State() *responses.BrowserStateData

State is only accessed in a single thread, as each chat has its own browser state

type BrowserCrawler

type BrowserCrawler struct{}

BrowserCrawler tool for crawling web pages using ollama.com crawl API

func (*BrowserCrawler) Description

func (g *BrowserCrawler) Description() string

func (*BrowserCrawler) Execute

func (g *BrowserCrawler) Execute(ctx context.Context, args map[string]any) (*CrawlResponse, error)

func (*BrowserCrawler) Name

func (g *BrowserCrawler) Name() string

func (*BrowserCrawler) Prompt

func (g *BrowserCrawler) Prompt() string

func (*BrowserCrawler) Schema

func (g *BrowserCrawler) Schema() map[string]any

type BrowserFind

type BrowserFind struct {
	Browser
}

func NewBrowserFind

func NewBrowserFind(bb *Browser) *BrowserFind

func (*BrowserFind) Description

func (b *BrowserFind) Description() string

func (*BrowserFind) Execute

func (b *BrowserFind) Execute(ctx context.Context, args map[string]any) (any, string, error)

func (*BrowserFind) Name

func (b *BrowserFind) Name() string

func (*BrowserFind) Prompt

func (b *BrowserFind) Prompt() string

func (*BrowserFind) Schema

func (b *BrowserFind) Schema() map[string]any

type BrowserOpen

type BrowserOpen struct {
	Browser
	// contains filtered or unexported fields
}

func NewBrowserOpen

func NewBrowserOpen(bb *Browser) *BrowserOpen

func (*BrowserOpen) Description

func (b *BrowserOpen) Description() string

func (*BrowserOpen) Execute

func (b *BrowserOpen) Execute(ctx context.Context, args map[string]any) (any, string, error)

func (*BrowserOpen) Name

func (b *BrowserOpen) Name() string

func (*BrowserOpen) Prompt

func (b *BrowserOpen) Prompt() string

func (*BrowserOpen) Schema

func (b *BrowserOpen) Schema() map[string]any

type BrowserSearch

type BrowserSearch struct {
	Browser
	// contains filtered or unexported fields
}

func NewBrowserSearch

func NewBrowserSearch(bb *Browser) *BrowserSearch

NewBrowserSearch creates a new browser search instance

func (*BrowserSearch) Description

func (b *BrowserSearch) Description() string

func (*BrowserSearch) Execute

func (b *BrowserSearch) Execute(ctx context.Context, args map[string]any) (any, string, error)

func (*BrowserSearch) Name

func (b *BrowserSearch) Name() string

func (*BrowserSearch) Prompt

func (b *BrowserSearch) Prompt() string

func (*BrowserSearch) Schema

func (b *BrowserSearch) Schema() map[string]any

type BrowserState

type BrowserState struct {
	Data *responses.BrowserStateData
	// contains filtered or unexported fields
}

BrowserState manages the browsing session on a per-chat basis

type BrowserWebSearch

type BrowserWebSearch struct{}

BrowserWebSearch tool for searching the web using ollama.com search API

func (*BrowserWebSearch) Description

func (w *BrowserWebSearch) Description() string

func (*BrowserWebSearch) Execute

func (w *BrowserWebSearch) Execute(ctx context.Context, args map[string]any) (any, error)

func (*BrowserWebSearch) Name

func (w *BrowserWebSearch) Name() string

func (*BrowserWebSearch) Prompt

func (w *BrowserWebSearch) Prompt() string

func (*BrowserWebSearch) Schema

func (w *BrowserWebSearch) Schema() map[string]any

type CrawlContent

type CrawlContent struct {
	Snippet  string `json:"snippet"`
	FullText string `json:"full_text"`
}

CrawlContent represents the content of a crawled page

type CrawlExtras

type CrawlExtras struct {
	Links []CrawlLink `json:"links"`
}

CrawlExtras represents additional data from the crawl API

type CrawlLink struct {
	URL  string `json:"url"`
	Href string `json:"href"`
	Text string `json:"text"`
}

CrawlLink represents a link found on a crawled page

type CrawlResponse

type CrawlResponse struct {
	Results map[string][]CrawlResult `json:"results"`
}

CrawlResponse represents the complete response from the crawl API

type CrawlResult

type CrawlResult struct {
	Title   string       `json:"title"`
	URL     string       `json:"url"`
	Content CrawlContent `json:"content"`
	Extras  CrawlExtras  `json:"extras"`
}

CrawlResult represents a single crawl result

type FetchRequest

type FetchRequest struct {
	URL string `json:"url"`
}

type FetchResponse

type FetchResponse struct {
	Title   string   `json:"title"`
	Content string   `json:"content"`
	Links   []string `json:"links"`
}

type PageType

type PageType string
const (
	PageTypeSearchResults PageType = "initial_results"
	PageTypeWebpage       PageType = "webpage"
)

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages the available tools and their execution

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new tool registry with no tools

func (*Registry) AvailableTools

func (r *Registry) AvailableTools() []map[string]any

ToolSchemas returns all tools as schema maps suitable for API calls

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, args map[string]any) (any, string, error)

Execute runs a tool with the given name and arguments

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, bool)

Get retrieves a tool by name

func (*Registry) List

func (r *Registry) List() []Tool

List returns all available tools

func (*Registry) Register

func (r *Registry) Register(tool Tool)

Register adds a tool to the registry

func (*Registry) SetWorkingDir

func (r *Registry) SetWorkingDir(dir string)

SetWorkingDir sets the working directory for all tool operations

func (*Registry) ToolNames

func (r *Registry) ToolNames() []string

ToolNames returns a list of all tool names

type SearchRequest

type SearchRequest struct {
	Query      string `json:"query"`
	MaxResults int    `json:"max_results,omitempty"`
}

type SearchResponse

type SearchResponse struct {
	Results []SearchResult `json:"results"`
}

type SearchResult

type SearchResult struct {
	Title   string `json:"title"`
	URL     string `json:"url"`
	Content string `json:"content"`
}

type Tool

type Tool interface {
	// Name returns the unique identifier for the tool
	Name() string

	// Description returns a human-readable description of what the tool does
	Description() string

	// Schema returns the JSON schema for the tool's parameters
	Schema() map[string]any

	// Execute runs the tool with the given arguments and returns result to store in db, and a string result for the model
	Execute(ctx context.Context, args map[string]any) (any, string, error)

	// Prompt returns a prompt for the tool
	Prompt() string
}

Tool defines the interface that all tools must implement

type ToolCall

type ToolCall struct {
	ID       string       `json:"id"`
	Type     string       `json:"type"`
	Function ToolFunction `json:"function"`
}

ToolCall represents a request to execute a tool

type ToolFunction

type ToolFunction struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments"`
}

ToolFunction represents the function call details

type ToolResult

type ToolResult struct {
	ToolCallID string `json:"tool_call_id"`
	Content    any    `json:"content"`
	Error      string `json:"error,omitempty"`
}

ToolResult represents the result of a tool execution

type WebFetch

type WebFetch struct{}

func (*WebFetch) Description

func (w *WebFetch) Description() string

func (*WebFetch) Execute

func (w *WebFetch) Execute(ctx context.Context, args map[string]any) (any, string, error)

func (*WebFetch) Name

func (w *WebFetch) Name() string

func (*WebFetch) Prompt

func (w *WebFetch) Prompt() string

func (*WebFetch) Schema

func (g *WebFetch) Schema() map[string]any

type WebSearch

type WebSearch struct{}

func (*WebSearch) Description

func (w *WebSearch) Description() string

func (*WebSearch) Execute

func (w *WebSearch) Execute(ctx context.Context, args map[string]any) (any, string, error)

func (*WebSearch) Name

func (w *WebSearch) Name() string

func (*WebSearch) Prompt

func (w *WebSearch) Prompt() string

func (*WebSearch) Schema

func (g *WebSearch) Schema() map[string]any

type WebSearchContent

type WebSearchContent struct {
	Snippet  string `json:"snippet"`
	FullText string `json:"full_text"`
}

WebSearchContent represents the content of a search result

type WebSearchMetadata

type WebSearchMetadata struct {
	PublishedDate *time.Time `json:"published_date,omitempty"`
}

WebSearchMetadata represents metadata for a search result

type WebSearchResponse

type WebSearchResponse struct {
	Results map[string][]WebSearchResult `json:"results"`
}

WebSearchResponse represents the complete response from the websearch API

type WebSearchResult

type WebSearchResult struct {
	Title    string            `json:"title"`
	URL      string            `json:"url"`
	Content  WebSearchContent  `json:"content"`
	Metadata WebSearchMetadata `json:"metadata"`
}

WebSearchResult represents a single search result

Jump to

Keyboard shortcuts

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