tools

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDifyRetrievalTool

func NewDifyRetrievalTool(cfg DifyRetrievalConfig) agentloop.Tool

NewDifyRetrievalTool creates an agentloop Tool that retrieves relevant document segments from a Dify knowledge base. Host, ApiKey, DatasetId and RetrievalModel are fixed at construction time and never exposed to the LLM.

Example:

agent, _ := agentloop.NewAgent(agentloop.AgentConfig{
    Tools: []agentloop.Tool{
        tools.NewDifyRetrievalTool(tools.DifyRetrievalConfig{
            Host:      "https://api.dify.ai",
            ApiKey:    os.Getenv("DIFY_API_KEY"),
            DatasetId: os.Getenv("DIFY_DATASET_ID"),
            RetrievalModel: &dify.RetrieveModelParam{TopK: 5},
        }),
    },
})

func NewTavilySearchTool

func NewTavilySearchTool(apiKey string, maxResults int, opts ...TavilySearchOption) agentloop.Tool

NewTavilySearchTool creates an agentloop Tool that performs a Tavily web search. apiKey is captured in a closure and never exposed to the LLM. maxResults controls how many results are returned (1-20); pass 0 to use the default of 5. opts are applied to the SearchReq after args, allowing callers to set any additional fields.

Example:

agent, _ := agentloop.NewAgent(agentloop.AgentConfig{
    Tools: []agentloop.Tool{tools.NewTavilySearchTool(os.Getenv("TAVILY_API_KEY"), 5)},
})

Types

type DifyRetrievalArgs

type DifyRetrievalArgs struct {
	// Query is the search query used to retrieve relevant segments. Required.
	Query string `json:"query"`
}

DifyRetrievalArgs are the typed arguments for the dify_retrieval tool.

type DifyRetrievalConfig

type DifyRetrievalConfig struct {
	// Host is the base URL of the Dify API (e.g. "https://api.dify.ai").
	Host string

	// ApiKey is the Dify dataset API key.
	ApiKey string

	// DatasetId is the ID of the Dify knowledge base (dataset) to query.
	DatasetId string

	// RetrievalModel controls retrieval behaviour (TopK, search method, reranking, etc.).
	// If nil, Dify will use the dataset's default retrieval settings.
	RetrievalModel *dify.RetrieveModelParam
}

DifyRetrievalConfig holds the caller-controlled parameters for NewDifyRetrievalTool. These are fixed at construction time and never exposed to the LLM.

type TavilySearchArgs

type TavilySearchArgs struct {
	// Query is the search query string. Required.
	Query string `json:"query"`

	// Topic narrows the search category. One of "general", "news", "finance".
	Topic string `json:"topic,omitempty"`

	// TimeRange restricts results to a time window. One of "day", "week", "month", "year".
	TimeRange string `json:"time_range,omitempty"`

	// StartDate returns results published after this date (format: YYYY-MM-DD).
	StartDate string `json:"start_date,omitempty"`

	// EndDate returns results published before this date (format: YYYY-MM-DD).
	EndDate string `json:"end_date,omitempty"`
}

TavilySearchArgs are the typed arguments for the tavily_search tool.

type TavilySearchOption

type TavilySearchOption func(o *search.SearchReq)

TavilySearchOption is a functional option that customizes the SearchReq before it is sent to Tavily. It is applied after all TavilySearchArgs fields have been set, so it can override any field.

Jump to

Keyboard shortcuts

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