tool.go


Overview

The tool.go file defines internal interfaces and fundamental logic for implementing tools within the system. These tools serve as modular components that can be invoked by agents or other parts of the system to perform specialized tasks or computations. This file is part of the internal tooling framework and establishes contracts for how tools should declare their capabilities and execute their logic in the context of agent interactions.


Interfaces

1. FunctionTool

type FunctionTool interface {
    tool.Tool
    Declaration() *genai.FunctionDeclaration
    Run(ctx tool.Context, args any) (result map[string]any, err error)
}

Description

FunctionTool extends the base tool.Tool interface and represents a tool that encapsulates a single function-like operation. It provides a structured declaration of its callable interface and permits execution with input arguments.

Methods

Usage Example

var myTool FunctionTool
declaration := myTool.Declaration()
// Pass input arguments as a map or structured type
result, err := myTool.Run(ctx, inputArgs)
if err != nil {
    // handle error
}
// process result

2. RequestProcessor

type RequestProcessor interface {
    ProcessRequest(ctx tool.Context, req *model.LLMRequest) error
}

Description

RequestProcessor defines an interface for processing large language model (LLM) requests. Implementers of this interface are responsible for handling or modifying requests before they are sent to the LLM backend or for performing side-effects related to the request.

Methods

Usage Example

var processor RequestProcessor
err := processor.ProcessRequest(ctx, llmRequest)
if err != nil {
    // handle error
}

Implementation Details


Interactions with Other Components


Mermaid Diagram: Interface Structure for tool.go

classDiagram
class FunctionTool {
+Declaration()
+Run()
}
class RequestProcessor {
+ProcessRequest()
}
FunctionTool <|-- tool.Tool
RequestProcessor ..> model.LLMRequest
FunctionTool ..> genai.FunctionDeclaration
FunctionTool ..> tool.Context
RequestProcessor ..> tool.Context

This diagram illustrates the two main interfaces defined in the file, their key methods, and their relationships to other types such as tool.Tool, genai.FunctionDeclaration, tool.Context, and model.LLMRequest.