hitl

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package hitl 提供 Human-in-the-Loop 能力 通过 Aspect 切面和工具钩子实现人类确认点

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterWithConfirmation

func RegisterWithConfirmation(registry *tools.ToolRegistry, approver Approver)

RegisterWithConfirmation 注册工具并添加确认钩子 需要确认的工具权限级别:PermReadWrite 和 PermDangerous

func RegisterWithConfirmationForAll

func RegisterWithConfirmationForAll(registry *tools.ToolRegistry, approver Approver)

RegisterWithConfirmationForAll 注册工具并对所有工具添加确认钩子

func RegisterWithConfirmationForDangerous

func RegisterWithConfirmationForDangerous(registry *tools.ToolRegistry, approver Approver)

RegisterWithConfirmationForDangerous 仅对危险工具添加确认钩子

Types

type ApprovalRequest

type ApprovalRequest struct {
	ID      string         // 唯一标识
	Type    ApprovalType   // 确认类型
	Summary string         // 操作摘要
	Details map[string]any // 详细信息
	Timeout time.Duration  // 超时(0 = 不超时)
}

ApprovalRequest 确认请求

type ApprovalResponse

type ApprovalResponse struct {
	Approved bool   // 是否批准
	Reason   string // 拒绝原因(可选)
}

ApprovalResponse 确认响应

type ApprovalType

type ApprovalType string

ApprovalType 确认类型

const (
	ApprovalTool   ApprovalType = "tool"   // 工具调用确认
	ApprovalNode   ApprovalType = "node"   // 工作流节点确认
	ApprovalStep   ApprovalType = "step"   // 计划步骤确认
	ApprovalCustom ApprovalType = "custom" // 自定义确认
)

type Approver

type Approver interface {
	// RequestApproval 请求人类确认
	RequestApproval(ctx context.Context, req ApprovalRequest) (ApprovalResponse, error)
}

Approver 确认器接口 实现此接口来提供确认 UI(TUI 弹窗、Web 前端、Slack 消息等)

type AutoApprover

type AutoApprover struct{}

AutoApprover 自动批准(用于测试或 auto 模式)

func (AutoApprover) RequestApproval

type ChannelApprover

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

ChannelApprover 基于 channel 的确认器 适用于 TUI 等事件驱动的 UI

func NewChannelApprover

func NewChannelApprover(requestCh chan<- ApprovalRequest, responseCh <-chan ApprovalResponse) *ChannelApprover

NewChannelApprover 创建 channel 确认器

func (*ChannelApprover) RequestApproval

func (a *ChannelApprover) RequestApproval(ctx context.Context, req ApprovalRequest) (ApprovalResponse, error)

type NodeConfirmationAspect

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

NodeConfirmationAspect 工作流节点确认切面 在节点执行前请求人类确认

func NewNodeConfirmationAspect

func NewNodeConfirmationAspect(approver Approver, shouldCheck func(node.Node) bool, timeout time.Duration) *NodeConfirmationAspect

NewNodeConfirmationAspect 创建节点确认切面 shouldCheck 返回 true 的节点需要确认,nil = 所有节点都需要

func (*NodeConfirmationAspect) Around

func (a *NodeConfirmationAspect) Around(ctx *node.AspectContext, n node.Node, next func() (map[string]any, error)) (map[string]any, error)

type PlanConfirmation

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

PlanConfirmation Plan 步骤确认回调

func NewPlanConfirmation

func NewPlanConfirmation(approver Approver, shouldCheck func(step *agent.ExecStep) bool, timeout time.Duration) *PlanConfirmation

NewPlanConfirmation 创建计划确认

func (*PlanConfirmation) StepCallback

func (pc *PlanConfirmation) StepCallback(ctx context.Context) func(step *agent.ExecStep)

StepCallback 返回可传给 PlanExecutor 的步骤回调 使用传入的 ctx 作为父 context,而非 context.Background()

type ToolConfirmationHook

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

ToolConfirmationHook 工具调用确认钩子 注册到 ToolRegistry 的 BeforeExecuteHook

func NewToolConfirmationHook

func NewToolConfirmationHook(approver Approver, registry *tools.ToolRegistry, shouldCheck func(toolName string, perm tools.ToolPermission) bool, timeout time.Duration) *ToolConfirmationHook

NewToolConfirmationHook 创建工具确认钩子 shouldCheck 返回 true 的工具需要确认,nil = 仅 PermDangerous 需要确认 registry 用于查询工具的真实权限级别

func (*ToolConfirmationHook) Hook

func (h *ToolConfirmationHook) Hook() func(ctx context.Context, toolName string, args map[string]any) error

Hook 返回可注册到 ToolRegistry 的钩子函数

Jump to

Keyboard shortcuts

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