tools

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildSubagentSystemPrompt

func BuildSubagentSystemPrompt(params *SubagentSystemPromptParams) string

BuildSubagentSystemPrompt 构建分身系统提示词

func GenerateChildSessionKey

func GenerateChildSessionKey(agentID string) string

GenerateChildSessionKey 生成子会话密钥

func GenerateRunID

func GenerateRunID() string

GenerateRunID 生成运行ID

func MarshalParams

func MarshalParams(params map[string]interface{}) (string, error)

MarshalParams 序列化参数为 JSON

func ToSchema

func ToSchema(tool Tool) map[string]interface{}

ToSchema 转换为 OpenAI 函数格式

func UnmarshalParams

func UnmarshalParams(data string) (map[string]interface{}, error)

UnmarshalParams 反序列化参数

func ValidateParameters

func ValidateParameters(params map[string]interface{}, schema map[string]interface{}) error

ValidateParameters 验证参数

Types

type AgentContentBlock added in v0.3.2

type AgentContentBlock interface {
	ContentType() string
}

AgentContentBlock represents a content block from agent tools.

type AgentTextContent added in v0.3.2

type AgentTextContent struct {
	Text string
}

AgentTextContent is a text content block.

func (AgentTextContent) ContentType added in v0.3.2

func (a AgentTextContent) ContentType() string

type AgentToolAdapter added in v0.3.2

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

AgentToolAdapter 将 AgentToolInterface 适配为 tools.Tool

func (*AgentToolAdapter) Description added in v0.3.2

func (a *AgentToolAdapter) Description() string

func (*AgentToolAdapter) Execute added in v0.3.2

func (a *AgentToolAdapter) Execute(ctx context.Context, params map[string]interface{}) (string, error)

func (*AgentToolAdapter) Name added in v0.3.2

func (a *AgentToolAdapter) Name() string

func (*AgentToolAdapter) Parameters added in v0.3.2

func (a *AgentToolAdapter) Parameters() map[string]interface{}

type AgentToolInterface added in v0.3.2

type AgentToolInterface interface {
	Name() string
	Description() string
	Label() string
	Parameters() map[string]any
	Execute(ctx context.Context, params map[string]any, onUpdate func(AgentToolResult)) (AgentToolResult, error)
}

AgentToolInterface defines the interface for agent tools without importing agent package. This avoids circular dependency between agent/tools and agent packages.

type AgentToolResult added in v0.3.2

type AgentToolResult struct {
	Content []AgentContentBlock
	Details map[string]any
	Error   error
}

AgentToolResult represents the result of an agent tool execution.

type BaseTool

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

BaseTool 基础工具

func NewBaseTool

func NewBaseTool(name, description string, parameters map[string]interface{}, executeFunc func(ctx context.Context, params map[string]interface{}) (string, error)) *BaseTool

NewBaseTool 创建基础工具

func NewUseSkillTool

func NewUseSkillTool() *BaseTool

NewUseSkillTool 创建使用技能的工具 这个工具用于让 LLM 选择要使用的技能,然后触发第二阶段的完整内容加载

func (*BaseTool) Description

func (t *BaseTool) Description() string

Description 返回工具描述

func (*BaseTool) Execute

func (t *BaseTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行工具

func (*BaseTool) ExecuteWithStreaming

func (t *BaseTool) ExecuteWithStreaming(ctx context.Context, params map[string]interface{}, onUpdate func(ToolResult)) (ToolResult, error)

ExecuteWithStreaming executes the tool with streaming support (new agent compatibility)

func (*BaseTool) Name

func (t *BaseTool) Name() string

Name 返回工具名称

func (*BaseTool) Parameters

func (t *BaseTool) Parameters() map[string]interface{}

Parameters 返回参数定义

type BrowserCDPExecutor added in v0.2.2

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

BrowserCDPExecutor CDP 执行器实现

func (*BrowserCDPExecutor) ExecuteCDP added in v0.2.2

func (e *BrowserCDPExecutor) ExecuteCDP(ctx context.Context, method string, params map[string]interface{}) (map[string]interface{}, error)

ExecuteCDP 执行 CDP 命令

func (*BrowserCDPExecutor) GetDirectClient added in v0.2.2

func (e *BrowserCDPExecutor) GetDirectClient() (*cdp.Client, error)

GetDirectClient 获取直接 CDP 客户端

func (*BrowserCDPExecutor) IsDirectMode added in v0.2.2

func (e *BrowserCDPExecutor) IsDirectMode() bool

IsDirectMode 检查是否为直接模式

type BrowserCDPTool

type BrowserCDPTool struct {
	*BrowserTool
}

BrowserCDPTool Enhanced browser automation tool with advanced CDP features

func NewBrowserCDPTool

func NewBrowserCDPTool(headless bool, timeout int) *BrowserCDPTool

NewBrowserCDPTool Create enhanced CDP browser tool

func (*BrowserCDPTool) BrowserClose

func (b *BrowserCDPTool) BrowserClose(ctx context.Context, params map[string]interface{}) (string, error)

BrowserClose Close current tab

func (*BrowserCDPTool) BrowserCreateTab

func (b *BrowserCDPTool) BrowserCreateTab(ctx context.Context, params map[string]interface{}) (string, error)

BrowserCreateTab Create a new tab

func (*BrowserCDPTool) BrowserEmulateDevice

func (b *BrowserCDPTool) BrowserEmulateDevice(ctx context.Context, params map[string]interface{}) (string, error)

BrowserEmulateDevice Emulate a specific device (mobile, tablet, desktop)

func (*BrowserCDPTool) BrowserExtractStructuredData

func (b *BrowserCDPTool) BrowserExtractStructuredData(ctx context.Context, params map[string]interface{}) (string, error)

BrowserExtractStructuredData Extract structured data from page using schema.org, JSON-LD, or custom selectors

func (*BrowserCDPTool) BrowserGetAllCookies

func (b *BrowserCDPTool) BrowserGetAllCookies(ctx context.Context, params map[string]interface{}) (string, error)

BrowserGetAllCookies Get all cookies for the current page

func (*BrowserCDPTool) BrowserGetMetrics

func (b *BrowserCDPTool) BrowserGetMetrics(ctx context.Context, params map[string]interface{}) (string, error)

BrowserGetMetrics Get performance metrics for the current page

func (*BrowserCDPTool) BrowserPrintToPDF

func (b *BrowserCDPTool) BrowserPrintToPDF(ctx context.Context, params map[string]interface{}) (string, error)

BrowserPrintToPDF Generate PDF of current page

func (*BrowserCDPTool) BrowserSetViewport

func (b *BrowserCDPTool) BrowserSetViewport(ctx context.Context, params map[string]interface{}) (string, error)

BrowserSetViewport Set custom viewport size

func (*BrowserCDPTool) GetCDPTools

func (b *BrowserCDPTool) GetCDPTools() []Tool

GetCDPTools Get all CDP-enhanced browser tools

type BrowserSessionManager

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

BrowserSessionManager 浏览器会话管理器 (使用 Chrome DevTools Protocol 或 OpenClaw Relay)

func GetBrowserSession

func GetBrowserSession() *BrowserSessionManager

GetBrowserSession 获取浏览器会话管理器(单例)

func (*BrowserSessionManager) GetClient

func (b *BrowserSessionManager) GetClient() (*cdp.Client, error)

GetClient 获取 CDP 客户端

func (*BrowserSessionManager) GetConnectionMode added in v0.2.2

func (b *BrowserSessionManager) GetConnectionMode() ConnectionMode

GetConnectionMode 获取当前连接模式

func (*BrowserSessionManager) GetRelayClient added in v0.2.2

func (b *BrowserSessionManager) GetRelayClient() *RelaySessionManager

GetRelayClient 获取 Relay 客户端

func (*BrowserSessionManager) IsReady

func (b *BrowserSessionManager) IsReady() bool

IsReady 检查会话是否就绪

func (*BrowserSessionManager) IsRelayMode added in v0.2.2

func (b *BrowserSessionManager) IsRelayMode() bool

IsRelayMode 检查是否使用 Relay 模式

func (*BrowserSessionManager) Start

func (b *BrowserSessionManager) Start(timeout time.Duration) error

Start 启动浏览器会话

func (*BrowserSessionManager) StartWithMode added in v0.2.2

func (b *BrowserSessionManager) StartWithMode(timeout time.Duration, relayURL string, mode ConnectionMode) error

StartWithMode 使用指定模式启动浏览器会话

func (*BrowserSessionManager) Stop

func (b *BrowserSessionManager) Stop()

Stop 停止浏览器会话

type BrowserTool

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

BrowserTool Browser tool using Chrome DevTools Protocol or OpenClaw Relay

func NewBrowserTool

func NewBrowserTool(headless bool, timeout int) *BrowserTool

NewBrowserTool Create browser tool

func NewBrowserToolWithRelay added in v0.2.2

func NewBrowserToolWithRelay(headless bool, timeout int, relayURL, relayMode string) *BrowserTool

NewBrowserToolWithRelay Create browser tool with Relay support

func (*BrowserTool) BrowserClick

func (b *BrowserTool) BrowserClick(ctx context.Context, params map[string]interface{}) (string, error)

BrowserClick Click element on page

func (*BrowserTool) BrowserExecuteScript

func (b *BrowserTool) BrowserExecuteScript(ctx context.Context, params map[string]interface{}) (string, error)

BrowserExecuteScript Execute JavaScript in browser

func (*BrowserTool) BrowserFillInput

func (b *BrowserTool) BrowserFillInput(ctx context.Context, params map[string]interface{}) (string, error)

BrowserFillInput Fill input field

func (*BrowserTool) BrowserGetText

func (b *BrowserTool) BrowserGetText(ctx context.Context, params map[string]interface{}) (string, error)

BrowserGetText Get page text content

func (*BrowserTool) BrowserNavigate

func (b *BrowserTool) BrowserNavigate(ctx context.Context, params map[string]interface{}) (string, error)

BrowserNavigate Navigate browser to URL

func (*BrowserTool) BrowserScreenshot

func (b *BrowserTool) BrowserScreenshot(ctx context.Context, params map[string]interface{}) (string, error)

BrowserScreenshot Take screenshot of page

func (*BrowserTool) Close

func (b *BrowserTool) Close() error

Close Close browser tool and cleanup resources

func (*BrowserTool) GetTools

func (b *BrowserTool) GetTools() []Tool

GetTools Get all browser tools

type CDPExecutor added in v0.2.2

type CDPExecutor interface {
	ExecuteCDP(ctx context.Context, method string, params map[string]interface{}) (map[string]interface{}, error)
	IsDirectMode() bool
	GetDirectClient() (*cdp.Client, error)
}

CDPExecutor CDP 命令执行器接口(支持直接 CDP 和 Relay 两种模式)

type ConnectionMode added in v0.2.2

type ConnectionMode string

ConnectionMode 浏览器连接模式

const (
	ModeAuto   ConnectionMode = "auto"   // 自动检测(优先尝试 relay,失败则尝试 direct)
	ModeDirect ConnectionMode = "direct" // 直接 CDP 连接
	ModeRelay  ConnectionMode = "relay"  // 通过 OpenClaw Relay 连接
)

type ContentBlock

type ContentBlock interface {
	ContentType() string
}

ContentBlock represents a block of content in a message

type CronTool added in v0.3.1

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

CronTool provides cron job management functionality

func NewCronTool added in v0.3.1

func NewCronTool(service *cron.Service) *CronTool

NewCronTool creates a new cron tool with an existing cron service

func NewCronToolWithConfig added in v0.3.3

func NewCronToolWithConfig(enabled bool, storePath string, messageBus *bus.MessageBus) *CronTool

NewCronToolWithConfig creates a new cron tool and creates its own cron service Use this when you want the tool to manage its own cron service

func (*CronTool) Exec added in v0.3.1

func (t *CronTool) Exec(ctx context.Context, params map[string]interface{}) (string, error)

Exec executes a cron command (legacy interface for backward compatibility)

func (*CronTool) GetTools added in v0.3.1

func (t *CronTool) GetTools() []Tool

GetTools returns both the legacy `cron` tool and new explicit `cron_*` tools The legacy tool provides backward compatibility and advanced features The new tools provide better LLM compatibility with explicit parameters

type DeliveryContext

type DeliveryContext struct {
	Channel   string `json:"channel,omitempty"`
	AccountID string `json:"account_id,omitempty"`
	To        string `json:"to,omitempty"`
	ThreadID  string `json:"thread_id,omitempty"`
}

DeliveryContext 传递上下文

type FileSystemTool

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

FileSystemTool 文件系统工具

func NewFileSystemTool

func NewFileSystemTool(allowedPaths, deniedPaths []string, workspace string) *FileSystemTool

NewFileSystemTool 创建文件系统工具

func (*FileSystemTool) EditFile

func (t *FileSystemTool) EditFile(ctx context.Context, params map[string]interface{}) (string, error)

EditFile 编辑文件(精确字符串替换)

func (*FileSystemTool) GetTools

func (t *FileSystemTool) GetTools() []Tool

GetTools 获取所有文件系统工具

func (*FileSystemTool) ListDir

func (t *FileSystemTool) ListDir(ctx context.Context, params map[string]interface{}) (string, error)

ListDir 列出目录

func (*FileSystemTool) ReadConfig

func (t *FileSystemTool) ReadConfig(ctx context.Context, params map[string]interface{}) (string, error)

ReadConfig 读取配置文件

func (*FileSystemTool) ReadFile

func (t *FileSystemTool) ReadFile(ctx context.Context, params map[string]interface{}) (string, error)

ReadFile 读取文件

func (*FileSystemTool) UpdateConfig

func (t *FileSystemTool) UpdateConfig(ctx context.Context, params map[string]interface{}) (string, error)

UpdateConfig 更新配置文件

func (*FileSystemTool) WriteFile

func (t *FileSystemTool) WriteFile(ctx context.Context, params map[string]interface{}) (string, error)

WriteFile 写入文件

type ImageContent

type ImageContent struct {
	URL      string `json:"url,omitempty"`
	Data     string `json:"data,omitempty"` // base64
	MimeType string `json:"mimeType,omitempty"`
}

ImageContent represents image content

func (ImageContent) ContentType

func (i ImageContent) ContentType() string

type MemoryAddTool

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

MemoryAddTool memory 添加工具

func NewMemoryAddTool

func NewMemoryAddTool(searchManager memory.MemorySearchManager) *MemoryAddTool

NewMemoryAddTool 创建 memory 添加工具

func (*MemoryAddTool) Description

func (t *MemoryAddTool) Description() string

Description 返回工具描述

func (*MemoryAddTool) Execute

func (t *MemoryAddTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行工具

func (*MemoryAddTool) Name

func (t *MemoryAddTool) Name() string

Name 返回工具名称

func (*MemoryAddTool) Parameters

func (t *MemoryAddTool) Parameters() map[string]interface{}

Parameters 返回参数定义

type MemoryTool

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

MemoryTool memory 搜索工具

func NewMemoryTool

func NewMemoryTool(searchManager memory.MemorySearchManager) *MemoryTool

NewMemoryTool 创建 memory 搜索工具

func (*MemoryTool) Description

func (t *MemoryTool) Description() string

Description 返回工具描述

func (*MemoryTool) Execute

func (t *MemoryTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行工具

func (*MemoryTool) Name

func (t *MemoryTool) Name() string

Name 返回工具名称

func (*MemoryTool) Parameters

func (t *MemoryTool) Parameters() map[string]interface{}

Parameters 返回参数定义

type MessageTool

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

MessageTool 消息工具

func NewMessageTool

func NewMessageTool(bus *bus.MessageBus) *MessageTool

NewMessageTool 创建消息工具

func (*MessageTool) GetTools

func (t *MessageTool) GetTools() []Tool

GetTools 获取所有消息工具

func (*MessageTool) SendMessage

func (t *MessageTool) SendMessage(ctx context.Context, params map[string]interface{}) (string, error)

SendMessage 发送消息

func (*MessageTool) SetCurrent

func (t *MessageTool) SetCurrent(channel, chatID string)

SetCurrent 设置当前通道和聊天

type Registry

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

Registry 工具注册表

func NewRegistry

func NewRegistry() *Registry

NewRegistry 创建工具注册表

func (*Registry) Clear

func (r *Registry) Clear()

Clear 清空所有工具

func (*Registry) Count

func (r *Registry) Count() int

Count 返回工具数量

func (*Registry) Execute

func (r *Registry) Execute(ctx context.Context, name string, params map[string]interface{}) (string, error)

Execute 执行工具

func (*Registry) Get

func (r *Registry) Get(name string) (Tool, bool)

Get 获取工具

func (*Registry) GetDefinitions

func (r *Registry) GetDefinitions() []map[string]interface{}

GetDefinitions 获取所有工具的 OpenAI 格式定义

func (*Registry) Has

func (r *Registry) Has(name string) bool

Has 检查工具是否存在

func (*Registry) List

func (r *Registry) List() []Tool

List 列出所有工具

func (*Registry) Register

func (r *Registry) Register(tool Tool) error

Register 注册工具

func (*Registry) RegisterAgentTool added in v0.3.2

func (r *Registry) RegisterAgentTool(tool AgentToolInterface) error

RegisterAgentTool 注册 agent.Tool 类型的工具(使用接口避免循环导入)

func (*Registry) Unregister

func (r *Registry) Unregister(name string)

Unregister 注销工具

type RelayClient added in v0.2.2

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

RelayClient OpenClaw Browser Relay 客户端 OpenClaw 使用 WebSocket + JSON 文本帧协议进行通信

func NewRelayClient added in v0.2.2

func NewRelayClient(url string) *RelayClient

NewRelayClient 创建新的 Relay 客户端

func (*RelayClient) Close added in v0.2.2

func (r *RelayClient) Close() error

Close 关闭连接

func (*RelayClient) Connect added in v0.2.2

func (r *RelayClient) Connect(ctx context.Context) error

Connect 连接到 OpenClaw Relay 服务器

func (*RelayClient) Execute added in v0.2.2

func (r *RelayClient) Execute(ctx context.Context, method string, params map[string]interface{}) (map[string]interface{}, error)

Execute 执行 CDP 命令通过 Relay

func (*RelayClient) IsConnected added in v0.2.2

func (r *RelayClient) IsConnected() bool

IsConnected 检查是否已连接

type RelayError added in v0.2.2

type RelayError struct {
	Message string `json:"message"`
	Code    int    `json:"code"`
}

RelayError OpenClaw Relay 错误格式

type RelayRequest added in v0.2.2

type RelayRequest struct {
	Type   string                 `json:"type"`   // "req"
	ID     string                 `json:"id"`     // 唯一请求ID
	Method string                 `json:"method"` // CDP 方法名 (如 "Page.navigate")
	Params map[string]interface{} `json:"params"` // CDP 参数
}

RelayRequest OpenClaw Relay 请求格式

type RelayResponse added in v0.2.2

type RelayResponse struct {
	Type    string                 `json:"type"` // "res"
	ID      string                 `json:"id"`   // 对应的请求ID
	OK      bool                   `json:"ok"`   // 是否成功
	Payload map[string]interface{} `json:"payload"`
	Error   *RelayError            `json:"error,omitempty"`
}

RelayResponse OpenClaw Relay 响应格式

type RelaySessionManager added in v0.2.2

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

RelaySessionManager OpenClaw Relay 会话管理器

func GetRelaySession added in v0.2.2

func GetRelaySession() *RelaySessionManager

GetRelaySession 获取 Relay 会话管理器(单例)

func (*RelaySessionManager) Execute added in v0.2.2

func (r *RelaySessionManager) Execute(ctx context.Context, method string, params map[string]interface{}) (map[string]interface{}, error)

Execute 执行 CDP 命令

func (*RelaySessionManager) GetClient added in v0.2.2

func (r *RelaySessionManager) GetClient() *RelayClient

GetClient 获取 Relay 客户端

func (*RelaySessionManager) IsReady added in v0.2.2

func (r *RelaySessionManager) IsReady() bool

IsReady 检查会话是否就绪

func (*RelaySessionManager) Start added in v0.2.2

func (r *RelaySessionManager) Start(relayURL string, timeout time.Duration) error

Start 启动 Relay 会话

func (*RelaySessionManager) Stop added in v0.2.2

func (r *RelaySessionManager) Stop()

Stop 停止 Relay 会话

type ShellTool

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

ShellTool Shell 工具

func NewShellTool

func NewShellTool(
	enabled bool,
	allowedCmds, deniedCmds []string,
	timeout int,
	workingDir string,
	sandboxConfig config.SandboxConfig,
) *ShellTool

NewShellTool 创建 Shell 工具

func (*ShellTool) Close

func (t *ShellTool) Close() error

Close 关闭工具

func (*ShellTool) Exec

func (t *ShellTool) Exec(ctx context.Context, params map[string]interface{}) (string, error)

Exec 执行 Shell 命令

func (*ShellTool) GetTools

func (t *ShellTool) GetTools() []Tool

GetTools 获取所有 Shell 工具

type SpawnTool

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

SpawnTool 子代理工具

func NewSpawnTool

func NewSpawnTool(subagentMgr SubagentManager) *SpawnTool

NewSpawnTool 创建子代理工具

func (*SpawnTool) GetTools

func (t *SpawnTool) GetTools() []Tool

GetTools 获取所有子代理工具

func (*SpawnTool) SetCurrent

func (t *SpawnTool) SetCurrent(channel, chatID string)

SetCurrent 设置当前通道和聊天

func (*SpawnTool) Spawn

func (t *SpawnTool) Spawn(ctx context.Context, params map[string]interface{}) (string, error)

Spawn 启动子代理

type SubagentManager

type SubagentManager interface {
	Spawn(ctx context.Context, task, label, originChannel, originChatID string) (string, error)
}

SubagentManager 子代理管理器接口(避免循环导入)

type SubagentRegistryInterface

type SubagentRegistryInterface interface {
	RegisterRun(params *SubagentRunParams) error
}

SubagentRegistryInterface 分身注册表接口

type SubagentRunOutcome

type SubagentRunOutcome struct {
	Status string `json:"status"` // ok, error, timeout, unknown
	Error  string `json:"error,omitempty"`
}

SubagentRunOutcome 分身运行结果

type SubagentRunParams

type SubagentRunParams struct {
	RunID               string
	ChildSessionKey     string
	RequesterSessionKey string
	RequesterOrigin     *DeliveryContext
	RequesterDisplayKey string
	Task                string
	Cleanup             string
	Label               string
	ArchiveAfterMinutes int
}

SubagentRunParams 分身运行参数

type SubagentSpawnResult

type SubagentSpawnResult struct {
	Status            string `json:"status"` // accepted, forbidden, error
	ChildSessionKey   string `json:"child_session_key,omitempty"`
	RunID             string `json:"run_id,omitempty"`
	Error             string `json:"error,omitempty"`
	ModelApplied      bool   `json:"model_applied,omitempty"`
	Warning           string `json:"warning,omitempty"`
	ChildSystemPrompt string `json:"child_system_prompt,omitempty"` // System prompt for the child agent
}

SubagentSpawnResult 分身生成结果

type SubagentSpawnTool

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

SubagentSpawnTool 分身生成工具

func NewSubagentSpawnTool

func NewSubagentSpawnTool(registry SubagentRegistryInterface) *SubagentSpawnTool

NewSubagentSpawnTool 创建分身生成工具

func (*SubagentSpawnTool) Description

func (t *SubagentSpawnTool) Description() string

Description 返回工具描述

func (*SubagentSpawnTool) Execute

func (t *SubagentSpawnTool) Execute(ctx context.Context, params map[string]interface{}) (string, error)

Execute 执行工具

func (*SubagentSpawnTool) Name

func (t *SubagentSpawnTool) Name() string

Name 返回工具名称

func (*SubagentSpawnTool) Parameters

func (t *SubagentSpawnTool) Parameters() map[string]interface{}

Parameters 返回工具参数定义

func (*SubagentSpawnTool) SetAgentConfigGetter

func (t *SubagentSpawnTool) SetAgentConfigGetter(getter func(agentID string) *config.AgentConfig)

SetAgentConfigGetter 设置 Agent 配置获取器

func (*SubagentSpawnTool) SetAgentIDGetter

func (t *SubagentSpawnTool) SetAgentIDGetter(getter func(sessionKey string) string)

SetAgentIDGetter 设置 Agent ID 获取器

func (*SubagentSpawnTool) SetDefaultConfigGetter

func (t *SubagentSpawnTool) SetDefaultConfigGetter(getter func() *config.AgentDefaults)

SetDefaultConfigGetter 设置默认配置获取器

func (*SubagentSpawnTool) SetOnSpawn

func (t *SubagentSpawnTool) SetOnSpawn(fn func(spawnParams *SubagentSpawnResult) error)

SetOnSpawn 设置分身生成回调

type SubagentSpawnToolParams

type SubagentSpawnToolParams struct {
	Task              string `json:"task"`                          // 任务描述(必填)
	Label             string `json:"label,omitempty"`               // 可选标签
	AgentID           string `json:"agent_id,omitempty"`            // 目标 Agent ID
	Model             string `json:"model,omitempty"`               // 模型覆盖
	Thinking          string `json:"thinking,omitempty"`            // 思考级别
	RunTimeoutSeconds int    `json:"run_timeout_seconds,omitempty"` // 超时时间
	Cleanup           string `json:"cleanup,omitempty"`             // 清理策略
}

SubagentSpawnToolParams 分身生成工具参数

type SubagentSystemPromptParams

type SubagentSystemPromptParams struct {
	RequesterSessionKey string
	RequesterOrigin     *DeliveryContext
	ChildSessionKey     string
	Label               string
	Task                string
}

SubagentSystemPromptParams 系统提示词参数

type TextContent

type TextContent struct {
	Text string `json:"text"`
}

TextContent represents text content

func (TextContent) ContentType

func (t TextContent) ContentType() string

type Tool

type Tool interface {
	// Name 工具名称
	Name() string

	// Description 工具描述
	Description() string

	// Parameters JSON Schema 参数定义
	Parameters() map[string]interface{}

	// Execute 执行工具
	Execute(ctx context.Context, params map[string]interface{}) (string, error)
}

Tool 工具接口

type ToolCall

type ToolCall struct {
	ID       string                 `json:"id"`
	Name     string                 `json:"name"`
	Params   map[string]interface{} `json:"params"`
	Response string                 `json:"response,omitempty"`
	Error    string                 `json:"error,omitempty"`
}

ToolCall 工具调用

type ToolResult

type ToolResult struct {
	Content []ContentBlock `json:"content"`
	Details map[string]any `json:"details"`
	Error   error          `json:"error,omitempty"`
}

ToolResult represents the result of a tool execution

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError 参数验证错误

func (*ValidationError) Error

func (e *ValidationError) Error() string

type WebTool

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

WebTool Web 工具

func NewWebTool

func NewWebTool(searchAPIKey, searchEngine string, timeout int) *WebTool

NewWebTool 创建 Web 工具

func (*WebTool) GetTools

func (t *WebTool) GetTools() []Tool

GetTools 获取所有 Web 工具

func (*WebTool) WebFetch

func (t *WebTool) WebFetch(ctx context.Context, params map[string]interface{}) (string, error)

WebFetch 抓取网页

func (*WebTool) WebSearch

func (t *WebTool) WebSearch(ctx context.Context, params map[string]interface{}) (string, error)

WebSearch 网络搜索

Jump to

Keyboard shortcuts

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