Documentation
¶
Overview ¶
Package functiontool provides a tool that wraps a Go function.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidArgument = errors.New("invalid argument")
ErrInvalidArgument indicates the input parameter type is invalid.
Functions ¶
func New ¶
New creates a new tool with a name, description, and the provided handler. Input schema is automatically inferred from the input and output types.
Example ¶
package main
import (
"github.com/safore-com/adk-go/tool"
"github.com/safore-com/adk-go/tool/functiontool"
)
type SumArgs struct {
A int `json:"a"`
B int `json:"b"`
}
type SumResult struct {
Sum int `json:"sum"`
}
func sumFunc(ctx tool.Context, input SumArgs) (SumResult, error) {
return SumResult{Sum: input.A + input.B}, nil
}
func main() {
sumTool, err := functiontool.New(functiontool.Config{
Name: "sum",
Description: "sums two integers",
}, sumFunc)
if err != nil {
panic(err)
}
_ = sumTool // use the tool
}
Types ¶
type Config ¶
type Config struct {
// The name of this tool.
Name string
// A human-readable description of the tool.
Description string
// An optional JSON schema object defining the expected parameters for the tool.
// If it is nil, FunctionTool tries to infer the schema based on the handler type.
InputSchema *jsonschema.Schema
// An optional JSON schema object defining the structure of the tool's output.
// If it is nil, FunctionTool tries to infer the schema based on the handler type.
OutputSchema *jsonschema.Schema
// IsLongRunning makes a FunctionTool a long-running operation.
IsLongRunning bool
// RequireConfirmation flags whether this tool must always ask for user confirmation
// before execution. If set to true, the ADK framework will automatically initiate
// a Human-in-the-Loop (HITL) confirmation request when this tool is invoked.
RequireConfirmation bool
// RequireConfirmationProvider allows for dynamic determination of whether
// user confirmation is needed. This field is a function called at runtime to decide if
// a confirmation request should be sent. The function takes the tool's input parameters as arguments.
// This provider offers more flexibility than the static RequireConfirmation flag,
// enabling conditional confirmation based on the invocation details.
// If set, this often takes precedence over the RequireConfirmation flag.
//
// Required signature for a provider function:
// func(toolInput ToolArgs) (bool)
// where ToolArgs is the input type of your go function
// Returning true means confirmation is required.
RequireConfirmationProvider any
}
Config is the input to the NewFunctionTool function.
Click to show internal directories.
Click to hide internal directories.