tools

package
v0.0.0-...-aca68c1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package tools provides a comprehensive collection of pre-built tools for extending agent capabilities.

The tools package implements ready-to-use tool implementations that cover common use cases for agent interactions, from code execution and web search to memory management and artifact handling. These tools can be used directly or serve as examples for custom implementations.

Available Tools

The package provides several categories of tools:

## Function Tools

  • FunctionTool: Wraps arbitrary Go functions as tools with automatic schema generation
  • Automatic function calling utilities for reflection-based tool creation

## Agent Tools

  • Agent: Wraps other agents as tools for hierarchical agent composition
  • ExitLoopTool: Provides loop termination control for LoopAgent
  • GetUserChoiceTool: Interactive user input for decision-making

## Code Execution Tools

  • CodeExecutionTool: Secure code execution with multiple backend support
  • Integration with codeexecutor package for sandboxed execution

## Search and Data Tools

  • GoogleSearchTool: Built-in Google Search integration (Gemini 2.0+ models)
  • LoadWebPageTool: Web content fetching and processing
  • URLContextTool: Extract and analyze web page context

## Memory and Artifact Tools

  • LoadMemoryTool: Retrieve relevant memories for context
  • PreloadMemoryTool: Proactively load memories for agent sessions
  • LoadArtifactsTool: Access stored artifacts and files
  • ForwardingArtifactService: Artifact management delegation

## Utility Tools

  • LongRunningTool: Base class for asynchronous operations
  • ExampleTool: Demonstration tool for learning and testing

Basic Usage

Using pre-built tools with agents:

agent := agent.NewLLMAgent(ctx, "assistant",
	agent.WithTools(
		tools.NewGoogleSearchTool(),
		tools.NewCodeExecutionTool(executor),
		tools.NewLoadMemoryTool(),
	),
	agent.WithInstruction("Use available tools to help users with research and analysis"),
)

Function Tool Creation

Create tools from Go functions with automatic schema generation:

// Define a function
func CalculateArea(ctx context.Context, length, width float64) (float64, error) {
	return length * width, nil
}

// Convert to tool automatically
calculatorTool := tools.NewFunctionTool(CalculateArea,
	tools.WithDescription("Calculate the area of a rectangle"),
	tools.WithParameterDescription("length", "Length of the rectangle in meters"),
	tools.WithParameterDescription("width", "Width of the rectangle in meters"),
)

// Use with agent
agent := agent.NewLLMAgent(ctx, "calculator",
	agent.WithTools(calculatorTool),
)

Agent as Tool Pattern

Use agents as tools for hierarchical composition:

// Create specialized sub-agents
researchAgent := agent.NewLLMAgent(ctx, "researcher",
	agent.WithTools(tools.NewGoogleSearchTool()),
	agent.WithInstruction("Research topics thoroughly using web search"),
)

analysisAgent := agent.NewLLMAgent(ctx, "analyst",
	agent.WithTools(tools.NewCodeExecutionTool(executor)),
	agent.WithInstruction("Analyze data using statistical methods"),
)

// Create tool wrappers
researchTool := tools.NewAgent("research", "Research topics using web search")
analysisTool := tools.NewAgent("analyze", "Analyze data statistically")

// Compose into coordinator agent
coordinator := agent.NewLLMAgent(ctx, "coordinator",
	agent.WithTools(researchTool, analysisTool),
	agent.WithInstruction("Coordinate research and analysis tasks"),
)

Code Execution Tool

Provide secure code execution capabilities:

// Create executor with desired backend
executor := codeexecutor.NewContainerExecutor(
	codeexecutor.WithImage("python:3.11-slim"),
	codeexecutor.WithTimeout(30*time.Second),
)

// Create code execution tool
codeTool := tools.NewCodeExecutionTool(executor,
	tools.WithLanguageSupport("python", "javascript", "bash"),
	tools.WithMaxRetries(2),
)

agent := agent.NewLLMAgent(ctx, "developer",
	agent.WithTools(codeTool),
	agent.WithInstruction("You can execute code to solve problems"),
)

Memory Integration

Enable agents to access and store memories:

memoryService := memory.NewInMemoryService()

agent := agent.NewLLMAgent(ctx, "assistant",
	agent.WithTools(
		tools.NewLoadMemoryTool(),
		tools.NewPreloadMemoryTool(),
	),
	agent.WithMemoryService(memoryService),
	agent.WithInstruction("Remember important information from our conversations"),
)

Web Search and Content Tools

Enable web research capabilities:

agent := agent.NewLLMAgent(ctx, "researcher",
	agent.WithTools(
		tools.NewGoogleSearchTool(),
		tools.NewLoadWebPageTool(),
		tools.NewURLContextTool(),
	),
	agent.WithInstruction("Research topics using web search and content analysis"),
)

Long-Running Operations

Handle asynchronous operations with long-running tools:

type DataProcessingTool struct {
	*tools.LongRunningTool
}

func (t *DataProcessingTool) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error) {
	// Start background processing
	jobID := t.startProcessingJob(args)

	// Return immediately with job tracking info
	return map[string]any{
		"job_id": jobID,
		"status": "processing",
		"check_url": fmt.Sprintf("/jobs/%s/status", jobID),
	}, nil
}

Interactive Tools

Create tools that interact with users:

agent := agent.NewLLMAgent(ctx, "interactive_assistant",
	agent.WithTools(
		tools.NewGetUserChoiceTool(),
	),
	agent.WithInstruction("Ask users for clarification when needed"),
)

// Agent can now ask users to choose between options
// The GetUserChoiceTool will present choices and collect user input

Artifact Management

Tools can save and load artifacts:

func (t *ReportGeneratorTool) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error) {
	report := t.generateReport(args)

	// Save report as artifact
	artifactService := toolCtx.GetArtifactService()
	_, err := artifactService.SaveArtifact(ctx,
		toolCtx.AppName(), toolCtx.UserID(), toolCtx.SessionID(),
		"report.pdf", &genai.Part{Bytes: reportPDF})

	return map[string]any{
		"status": "completed",
		"artifact": "report.pdf",
	}, nil
}

Error Handling Best Practices

Tools should provide clear error messages:

func (t *MyTool) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error) {
	// Validate required parameters
	query, ok := args["query"].(string)
	if !ok || query == "" {
		return nil, fmt.Errorf("query parameter is required and must be a non-empty string")
	}

	// Handle context cancellation
	select {
	case <-ctx.Done():
		return nil, ctx.Err()
	default:
	}

	// Call external service with proper error handling
	result, err := t.callExternalAPI(ctx, query)
	if err != nil {
		return nil, fmt.Errorf("external API call failed: %w", err)
	}

	return result, nil
}

Authentication Integration

Tools can request authentication credentials:

func (t *APITool) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error) {
	// Request API key authentication
	authConfig := &types.AuthConfig{
		Type: types.AuthTypeAPIKey,
		CredentialKey: "external_api_key",
	}

	toolCtx.RequestCredential("api_access", authConfig)

	// Tool framework handles credential flow
	// Tool receives authenticated client or credentials
	return t.callAuthenticatedAPI(args)
}

Performance Considerations

  1. Cache expensive computations and API calls
  2. Use appropriate timeouts for external services
  3. Implement connection pooling for HTTP clients
  4. Consider async processing for long operations
  5. Validate inputs early to avoid wasted processing

Security Guidelines

  1. Validate and sanitize all input parameters
  2. Use secure credential management
  3. Implement rate limiting for external APIs
  4. Log tool usage for audit trails
  5. Follow principle of least privilege

The tools package provides a solid foundation for agent capabilities while serving as examples for implementing custom tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecutorFromTool

func ExecutorFromTool(tool types.Tool) (types.CodeExecutor, bool)

ExecutorFromTool extracts the underlying CodeExecutor from a CodeExecutionTool. This can be useful for advanced use cases that need direct access to the executor.

func ExitLoop

func ExitLoop(toolCtx *types.ToolContext)

ExitLoop exits the loop.

Call this function only when you are instructed to do so.

func GetUserChoice

func GetUserChoice(_ []string, toolCtx *types.ToolContext)

GetUserChoice provides the options to the user and asks them to choose one.

func ToGeminiSchema

func ToGeminiSchema(openapiSchema *jsonschema.Schema) (*genai.Schema, error)

ToGeminiSchema converts a JSON schema to a Gemini Schema object. This is the main entry point for converting JSON schemas to Gemini-compatible schemas.

The function:

  1. Validates the input is a non-nil schema
  2. Sanitizes the schema to include only Gemini-supported fields
  3. Converts the sanitized schema to a genai.Schema object

Example usage:

schema := &jsonschema.Schema{
    Type: "object",
    Properties: map[string]*jsonschema.Schema{
        "name": {Type: "string"},
        "age": {Type: "integer"},
    },
    Required: []string{"name"},
}

geminiSchema, err := ToGeminiSchema(schema)
if err != nil {
    // handle error
}

func ToSnakeCase

func ToSnakeCase(text string) string

ToSnakeCase converts a string into snake_case.

Handles lowerCamelCase, UpperCamelCase, space-separated case, acronyms (e.g., "REST API") and consecutive uppercase letters correctly. Also handles mixed cases with and without spaces.

Examples:

ToSnakeCase("camelCase") -> "camel_case"
ToSnakeCase("UpperCamelCase") -> "upper_camel_case"
ToSnakeCase("space separated") -> "space_separated"
ToSnakeCase("REST API") -> "rest_api"

This implementation uses a single-pass algorithm for optimal performance, avoiding regex compilation and multiple string allocations.

func ValidateGeminiSchema

func ValidateGeminiSchema(schema *genai.Schema) error

ValidateGeminiSchema validates that a schema is compatible with Gemini's requirements. This function checks for common issues and returns descriptive error messages.

Types

type Agent

type Agent struct {
	*tool.Tool
	// contains filtered or unexported fields
}

Agent is a tool.Tool that wraps an agent.

This tool allows an agent to be called as a tool within a larger application. The agent's input schema is used to define the tool's input parameters, and the agent's output is returned as the tool's result.

func NewAgent

func NewAgent(name, description string) *Agent

NewAgent creates a new Agent tool with the given options.

func (*Agent) Description

func (t *Agent) Description() string

Description implements types.Tool.

func (*Agent) GetDeclaration

func (t *Agent) GetDeclaration() *genai.FunctionDeclaration

GetDeclaration implements types.Tool.

TODO(zchee): implements correctly.

func (*Agent) IsLongRunning

func (t *Agent) IsLongRunning() bool

IsLongRunning implements types.Tool.

func (*Agent) Name

func (t *Agent) Name() string

Name implements types.Tool.

func (*Agent) ProcessLLMRequest

func (t *Agent) ProcessLLMRequest(ctx context.Context, toolCtx *types.ToolContext, request *types.LLMRequest) error

ProcessLLMRequest implements types.Tool.

func (*Agent) Run

func (t *Agent) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error)

Run implements types.Tool.

TODO(zchee): implements.

type AuthenticatedTool

type AuthenticatedTool struct {
	*tool.Tool

	Logger             *slog.Logger
	CredentialsManager *types.CredentialManager
	// contains filtered or unexported fields
}

AuthenticatedTool is a handles authentication before the actual tool logic gets called. Functions can accept a special `credential` argument which is the credential ready for use.

Experimental

This feature is experimental and may change or be removed in future versions without notice. It may introduce breaking changes at any time.

func NewAuthenticatedTool

func NewAuthenticatedTool(name, description string, authConfig *types.AuthConfig, opts ...AuthenticatedToolOption) *AuthenticatedTool

NewAuthenticatedTool creates a new authenticated tool with the given name, description, authConfig, and responseForAuthRequired.

func (*AuthenticatedTool) Description

func (t *AuthenticatedTool) Description() string

Description implements types.AuthenticatedTool.

func (*AuthenticatedTool) Execute

func (t *AuthenticatedTool) Execute(ctx context.Context, args map[string]any, toolCtx *types.ToolContext, credential *types.AuthCredential) (any, error)

Execute implements types.AuthenticatedTool.

func (*AuthenticatedTool) IsLongRunning

func (t *AuthenticatedTool) IsLongRunning() bool

IsLongRunning implements types.AuthenticatedTool.

func (*AuthenticatedTool) Name

func (t *AuthenticatedTool) Name() string

Name implements types.AuthenticatedTool.

func (*AuthenticatedTool) Run

func (t *AuthenticatedTool) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error)

Run implements types.AuthenticatedTool.

type AuthenticatedToolOption

type AuthenticatedToolOption func(*AuthenticatedTool)

AuthenticatedToolOption configures an AuthenticatedTool.

func WithResponseForAuthRequired

func WithResponseForAuthRequired(authRequired map[string]any) AuthenticatedToolOption

WithResponseForAuthRequired sets the authRequired response for the AuthenticatedTool.

type CodeExecutionTool

type CodeExecutionTool struct {
	*tool.Tool
	// contains filtered or unexported fields
}

CodeExecutionTool provides code execution capabilities as a tool. It wraps a CodeExecutor and provides it as a tool that can be called by LLMs.

func NewCodeExecutionTool

func NewCodeExecutionTool(executor types.CodeExecutor) *CodeExecutionTool

NewCodeExecutionTool creates a new code execution tool with the given executor.

func (*CodeExecutionTool) Description

func (t *CodeExecutionTool) Description() string

Description implements types.Tool.

func (*CodeExecutionTool) GetDeclaration

func (t *CodeExecutionTool) GetDeclaration() *genai.FunctionDeclaration

GetDeclaration implements types.Tool.

func (*CodeExecutionTool) IsLongRunning

func (t *CodeExecutionTool) IsLongRunning() bool

IsLongRunning implements types.Tool.

func (*CodeExecutionTool) Name

func (t *CodeExecutionTool) Name() string

Name implements types.Tool.

func (*CodeExecutionTool) ProcessLLMRequest

func (t *CodeExecutionTool) ProcessLLMRequest(ctx context.Context, toolCtx *types.ToolContext, llmRequest *types.LLMRequest) error

ProcessLLMRequest implements types.Tool.

This method can be used to automatically add code execution capabilities to LLM requests.

func (*CodeExecutionTool) Run

func (t *CodeExecutionTool) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error)

Run implements types.Tool.

type Config

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

Config is the configuration for a [Tool].

func NewConfig

func NewConfig(name, description string, opts ...ToolOption) *Config

NewConfig creates a new Config with the given name and description.

type ExampleTool

type ExampleTool[T any] struct {
	*tool.Tool
	// contains filtered or unexported fields
}

ExampleTool represents a tool that adds (few-shot) examples to the types.LLMRequest.

func NewExampleTool

func NewExampleTool[T any](examples T) *ExampleTool[T]

NewExampleTool creates a new ExampleTool with the given examples.

func (*ExampleTool[T]) Description

func (t *ExampleTool[T]) Description() string

Description implements types.Tool.

func (*ExampleTool[T]) GetDeclaration

func (t *ExampleTool[T]) GetDeclaration() *genai.FunctionDeclaration

GetDeclaration implements types.Tool.

func (*ExampleTool[T]) IsLongRunning

func (t *ExampleTool[T]) IsLongRunning() bool

IsLongRunning implements types.Tool.

func (*ExampleTool[T]) Name

func (t *ExampleTool[T]) Name() string

Name implements types.Tool.

func (*ExampleTool[T]) ProcessLLMRequest

func (t *ExampleTool[T]) ProcessLLMRequest(ctx context.Context, toolCtx *types.ToolContext, request *types.LLMRequest) error

ProcessLLMRequest implements types.Tool.

func (*ExampleTool[T]) Run

Run implements types.Tool.

type ExecuteFunc

type ExecuteFunc func(ctx context.Context, params map[string]any) (any, error)

ExecuteFunc is the function type that executes a tool.

type ExtendedJSONSchema

type ExtendedJSONSchema struct {
	*jsonschema.Schema

	// PropertyOrdering extended field for property ordering.
	// Not a standard field in open api spec. Only used to support the order of the properties.
	PropertyOrdering []string `json:"property_ordering,omitempty"`
}

ExtendedJSONSchema represents a JSON schema with additional properties for Gemini compatibility. This extends the standard JSON schema with optional property ordering.

type ForwardingArtifactService

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

ForwardingArtifactService represents an artifact service that forwards to the parent tool context.

func NewForwardingArtifactService

func NewForwardingArtifactService(toolCtx *types.ToolContext) *ForwardingArtifactService

NewForwardingArtifactService returns a new ForwardingArtifactService given a tool context.

func (*ForwardingArtifactService) Close

func (a *ForwardingArtifactService) Close() error

Close implements types.ArtifactService.

func (*ForwardingArtifactService) DeleteArtifact

func (a *ForwardingArtifactService) DeleteArtifact(ctx context.Context, appName, userID, sessionID, filename string) error

DeleteArtifact implements types.ArtifactService.

func (*ForwardingArtifactService) ListArtifactKey

func (a *ForwardingArtifactService) ListArtifactKey(ctx context.Context, appName, userID, sessionID string) ([]string, error)

ListArtifactKey implements types.ArtifactService.

func (*ForwardingArtifactService) ListVersions

func (a *ForwardingArtifactService) ListVersions(ctx context.Context, appName, userID, sessionID, filename string) ([]int, error)

ListVersions implements types.ArtifactService.

func (*ForwardingArtifactService) LoadArtifact

func (a *ForwardingArtifactService) LoadArtifact(ctx context.Context, appName, userID, sessionID, filename string, version int) (*genai.Part, error)

LoadArtifact implements types.ArtifactService.

func (*ForwardingArtifactService) SaveArtifact

func (a *ForwardingArtifactService) SaveArtifact(ctx context.Context, appName, userID, sessionID, filename string, artifact *genai.Part) (int, error)

SaveArtifact implements types.ArtifactService.

type Function

type Function func(ctx context.Context, args map[string]any) (any, error)

Function represents a user-defined function that can be called with a context.

type FunctionOption

type FunctionOption func(*functionConfig)

FunctionOption represents configuration options for function declaration building.

func WithDescription

func WithDescription(description string) FunctionOption

WithDescription sets a description for the function declaration.

func WithName

func WithName(name string) FunctionOption

WithName sets a custom name for the function declaration.

func WithParameterDescription

func WithParameterDescription(paramName, description string) FunctionOption

WithParameterDescription sets a description for a specific parameter.

func WithResponseSchema

func WithResponseSchema() FunctionOption

WithResponseSchema includes response schema in the function declaration.

type FunctionTool

type FunctionTool struct {
	*tool.Tool
	// contains filtered or unexported fields
}

FunctionTool represents a tool that wraps a user-defined function.

TODO(zchee): implements correctly.

func NewFunctionTool

func NewFunctionTool(fn Function) *FunctionTool

NewFunctionTool returns the new FunctionTool with the given name, description and function.

func (*FunctionTool) Description

func (t *FunctionTool) Description() string

Description implements types.Tool.

func (*FunctionTool) GetDeclaration

func (t *FunctionTool) GetDeclaration() *genai.FunctionDeclaration

GetDeclaration implements types.Tool.

func (*FunctionTool) IsLongRunning

func (t *FunctionTool) IsLongRunning() bool

IsLongRunning implements types.Tool.

func (*FunctionTool) Name

func (t *FunctionTool) Name() string

Name implements types.Tool.

func (*FunctionTool) ProcessLLMRequest

func (t *FunctionTool) ProcessLLMRequest(ctx context.Context, toolCtx *types.ToolContext, request *types.LLMRequest) error

ProcessLLMRequest implements types.Tool.

func (*FunctionTool) Run

func (t *FunctionTool) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error)

Run implements types.Tool.

type GoogleSearchTool

type GoogleSearchTool struct {
	*tool.Tool
}

GoogleSearchTool represents a built-in tool that is automatically invoked by Gemini 2 models to retrieve search results from Google Search.

This tool operates internally within the model and does not require or perform local code execution.

func NewGoogleSearchTool

func NewGoogleSearchTool() *GoogleSearchTool

NewGoogleSearchTool returns the new GoogleSearchTool.

func (*GoogleSearchTool) Description

func (t *GoogleSearchTool) Description() string

Description implements types.Tool.

func (*GoogleSearchTool) GetDeclaration

func (t *GoogleSearchTool) GetDeclaration() *genai.FunctionDeclaration

GetDeclaration implements types.Tool.

func (*GoogleSearchTool) IsLongRunning

func (t *GoogleSearchTool) IsLongRunning() bool

IsLongRunning implements types.Tool.

func (*GoogleSearchTool) Name

func (t *GoogleSearchTool) Name() string

Name implements types.Tool.

func (*GoogleSearchTool) ProcessLLMRequest

func (t *GoogleSearchTool) ProcessLLMRequest(ctx context.Context, toolCtx *types.ToolContext, request *types.LLMRequest) error

ProcessLLMRequest implements types.Tool.

func (*GoogleSearchTool) Run

func (t *GoogleSearchTool) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error)

Run implements types.Tool.

type LoadArtifactsTool

type LoadArtifactsTool struct {
	*tool.Tool
}

LoadArtifactsTool represents a tool that loads the artifacts and adds them to the session.

func NewLoadArtifactsTool

func NewLoadArtifactsTool() *LoadArtifactsTool

NewLoadArtifactsTool returns the new LoadArtifactsTool.

func (*LoadArtifactsTool) Description

func (t *LoadArtifactsTool) Description() string

Description implements types.Tool.

func (*LoadArtifactsTool) GetDeclaration

func (t *LoadArtifactsTool) GetDeclaration() *genai.FunctionDeclaration

GetDeclaration implements types.Tool.

func (*LoadArtifactsTool) IsLongRunning

func (t *LoadArtifactsTool) IsLongRunning() bool

IsLongRunning implements types.Tool.

func (*LoadArtifactsTool) Name

func (t *LoadArtifactsTool) Name() string

Name implements types.Tool.

func (*LoadArtifactsTool) ProcessLLMRequest

func (t *LoadArtifactsTool) ProcessLLMRequest(ctx context.Context, toolCtx *types.ToolContext, request *types.LLMRequest) error

ProcessLLMRequest implements types.Tool.

func (*LoadArtifactsTool) Run

func (t *LoadArtifactsTool) Run(ctx context.Context, args map[string]any, toolCtx *types.ToolContext) (any, error)

Run implements types.Tool.

type LoadMemoryResponse

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

LoadMemoryResponse represents a response from the LoadMemory tool.

func LoadMemory

func LoadMemory(ctx context.Context, query string, toolCtx *types.ToolContext) (*LoadMemoryResponse, error)

LoadMemory loads the memory for the current user.

type LoadMemoryTool

type LoadMemoryTool struct{}

LoadMemoryTool represents a tool that loads the memory for the current user.

NOTE(adk-python): Currently this tool only uses text part from the memory.

TODO(zchee): depends on FunctionTool.

type LongRunningFunctionTool

type LongRunningFunctionTool struct {
	*FunctionTool
}

LongRunningFunctionTool represents a function tool that returns the result asynchronously.

This tool is used for long-running operations that may take a significant amount of time to complete. The framework will call the function. Once the function returns, the response will be returned asynchronously to the framework which is identified by the function_call_id.

Example:

tool = LongRunningFunctionTool(a_long_running_function)

func NewLongRunningFunctionTool

func NewLongRunningFunctionTool(fn Function) *LongRunningFunctionTool

NewLongRunningFunctionTool returns the new LongRunningFunctionTool with the given function.

type PreloadMemoryTool

type PreloadMemoryTool struct {
	*tool.Tool
}

PreloadMemoryTool represents a tool that preloads the memory for the current user.

NOTE(adk-python): Currently this tool only uses text part from the memory.

func NewPreloadMemoryTool

func NewPreloadMemoryTool() *PreloadMemoryTool

NewPreloadMemoryTool returns the new PreloadMemoryTool.

func (*PreloadMemoryTool) ProcessLLMRequest

func (t *PreloadMemoryTool) ProcessLLMRequest(ctx context.Context, toolCtx *types.ToolContext, request *types.LLMRequest) error

ProcessLLMRequest implements types.Tool.

type ToolOption

type ToolOption func(*Config)

ToolOption configures a Config.

func WithInputSchema

func WithInputSchema(schema *genai.Schema) ToolOption

WithInputSchema sets the input schema of the Config.

func WithIsLongNunning

func WithIsLongNunning(isLongNunning bool) ToolOption

WithIsLongNunning sets the isLongNunning of the Config.

func WithToolExecuteFunc

func WithToolExecuteFunc(executeFunc ExecuteFunc) ToolOption

WithToolExecuteFunc sets the execute function of the Config.

type URLContextTool

type URLContextTool struct {
	*tool.Tool
}

URLContextTool represents a built-in tool that is automatically invoked by Gemini 2 models to retrieve content from the URLs and use that content to inform and shape its response.

This tool operates internally within the model and does not require or perform local code execution.

func NewUrlContextTool

func NewUrlContextTool() *URLContextTool

NewUrlContextTool returns the new URLContextTool.

func (*URLContextTool) ProcessLLMRequest

func (t *URLContextTool) ProcessLLMRequest(ctx context.Context, toolCtx *types.ToolContext, request *types.LLMRequest) error

ProcessLLMRequest implements types.Tool.

type WebPageTool

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

WebPageTool represents a tool that can be used to load a web page.

func NewWebPageTool

func NewWebPageTool(hc *http.Client) *WebPageTool

func (*WebPageTool) LoadWebPage

func (t *WebPageTool) LoadWebPage(ctx context.Context, uri string) (string, error)

LoadWebPage fetches the content in the url and returns the text in it.

Jump to

Keyboard shortcuts

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