approvaltool

package
v1.31.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package approvaltool provides a Human-in-the-Loop (HITL) tool example.

This tool demonstrates the long-running/HITL pattern where: 1. Tool returns immediately with a pending status 2. Task transitions to `input_required` state 3. Human provides approval/rejection 4. Task resumes with the human's decision

This is different from StreamingTool which produces incremental output but runs to completion without human intervention.

Example usage:

tool := approvaltool.New(approvaltool.Config{
    Name:        "request_approval",
    Description: "Request human approval for sensitive operations",
})

A2A Protocol Mapping:

  • Initial call: Returns immediately with pending status
  • Task state: Transitions to `input_required`
  • A2A event: `status-update` with `state: input_required`
  • Human response: Sent via `message/send` with approval decision
  • Resume: Task continues with approval result

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApprovalTool

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

ApprovalTool implements a HITL approval workflow.

func New

func New(cfg Config) *ApprovalTool

New creates a new approval tool.

func (*ApprovalTool) Call

func (t *ApprovalTool) Call(ctx tool.Context, args map[string]any) (map[string]any, error)

Call executes the approval request. For HITL tools, this returns immediately with a pending status. The actual approval/rejection comes later via human input.

func (*ApprovalTool) Description

func (t *ApprovalTool) Description() string

Description returns the tool description.

func (*ApprovalTool) IsLongRunning

func (t *ApprovalTool) IsLongRunning() bool

IsLongRunning returns false - this is not an async tool.

func (*ApprovalTool) Name

func (t *ApprovalTool) Name() string

Name returns the tool name.

func (*ApprovalTool) RequiresApproval

func (t *ApprovalTool) RequiresApproval() bool

RequiresApproval returns true - this is a HITL tool. The difference from streaming: - Streaming: produces incremental output but runs to completion - RequiresApproval: pauses and waits for human input before execution

func (*ApprovalTool) Schema

func (t *ApprovalTool) Schema() map[string]any

Schema returns the JSON schema for the tool parameters.

type Config

type Config struct {
	// Name is the tool name (default: "request_approval")
	Name string

	// Description describes what the tool does
	Description string

	// RequiredFields specifies what information is needed for approval
	RequiredFields []string
}

Config configures the approval tool.

Jump to

Keyboard shortcuts

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