Documentation
¶
Index ¶
- Constants
- Variables
- func ExtractMessages(messages []types.Message, limit int) []types.Message
- func IsolateContext(parentState map[string]interface{}, includeKeys []string) map[string]interface{}
- func NewExperimentalUpdateWorkingMemoryTool(manager *memory.WorkingMemoryManager) tools.Tool
- func NewMemorySearchTool(manager *memory.Manager, baseNamespace string) tools.Tool
- func NewMemoryWriteTool(manager *memory.Manager, baseNamespace string) tools.Tool
- func NewUpdateWorkingMemoryTool(manager *memory.WorkingMemoryManager) tools.Tool
- type ActionRequest
- type AgentMemoryMiddleware
- func (m *AgentMemoryMiddleware) GetConfig() map[string]interface{}
- func (m *AgentMemoryMiddleware) GetMemoryContent() string
- func (m *AgentMemoryMiddleware) IsMemoryLoaded() bool
- func (m *AgentMemoryMiddleware) OnAgentStart(ctx context.Context, agentID string) error
- func (m *AgentMemoryMiddleware) ReloadMemory(ctx context.Context) error
- func (m *AgentMemoryMiddleware) Tools() []tools.Tool
- func (m *AgentMemoryMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
- type AgentMemoryMiddlewareConfig
- type ApprovalHandler
- type BaseMiddleware
- func (m *BaseMiddleware) Name() string
- func (m *BaseMiddleware) OnAgentStart(ctx context.Context, agentID string) error
- func (m *BaseMiddleware) OnAgentStop(ctx context.Context, agentID string) error
- func (m *BaseMiddleware) Priority() int
- func (m *BaseMiddleware) Tools() []tools.Tool
- func (m *BaseMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
- func (m *BaseMiddleware) WrapToolCall(ctx context.Context, req *ToolCallRequest, handler ToolCallHandler) (*ToolCallResponse, error)
- type Decision
- type DecisionType
- type EditTool
- type ExperimentalUpdateWorkingMemoryTool
- func (t *ExperimentalUpdateWorkingMemoryTool) Description() string
- func (t *ExperimentalUpdateWorkingMemoryTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (t *ExperimentalUpdateWorkingMemoryTool) InputSchema() map[string]interface{}
- func (t *ExperimentalUpdateWorkingMemoryTool) Name() string
- func (t *ExperimentalUpdateWorkingMemoryTool) Prompt() string
- type FailedToolCall
- type FilesystemMiddleware
- func (m *FilesystemMiddleware) Tools() []tools.Tool
- func (m *FilesystemMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
- func (m *FilesystemMiddleware) WrapToolCall(ctx context.Context, req *ToolCallRequest, handler ToolCallHandler) (*ToolCallResponse, error)
- type FilesystemMiddlewareConfig
- type GlobTool
- type GrepTool
- type HumanInTheLoopMiddleware
- func (m *HumanInTheLoopMiddleware) GetInterruptConfig(toolName string) (*InterruptConfig, bool)
- func (m *HumanInTheLoopMiddleware) IsToolInterruptible(toolName string) bool
- func (m *HumanInTheLoopMiddleware) ListInterruptibleTools() []string
- func (m *HumanInTheLoopMiddleware) SetApprovalHandler(handler ApprovalHandler)
- func (m *HumanInTheLoopMiddleware) WrapToolCall(ctx context.Context, req *ToolCallRequest, handler ToolCallHandler) (*ToolCallResponse, error)
- type HumanInTheLoopMiddlewareConfig
- type InterruptConfig
- type ListSubagentsTool
- func (t *ListSubagentsTool) Description() string
- func (t *ListSubagentsTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (t *ListSubagentsTool) InputSchema() map[string]interface{}
- func (t *ListSubagentsTool) Name() string
- func (t *ListSubagentsTool) Prompt() string
- type LsTool
- type MemorySearchTool
- func (t *MemorySearchTool) Description() string
- func (t *MemorySearchTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (t *MemorySearchTool) InputSchema() map[string]interface{}
- func (t *MemorySearchTool) Name() string
- func (t *MemorySearchTool) Prompt() string
- type MemoryWriteTool
- func (t *MemoryWriteTool) Description() string
- func (t *MemoryWriteTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (t *MemoryWriteTool) InputSchema() map[string]interface{}
- func (t *MemoryWriteTool) Name() string
- func (t *MemoryWriteTool) Prompt() string
- type Middleware
- type MiddlewareFactory
- type MiddlewareFactoryConfig
- type ModelCallHandler
- type ModelRequest
- type ModelResponse
- type PatchToolCallsMiddleware
- func (m *PatchToolCallsMiddleware) ClearFailedCalls()
- func (m *PatchToolCallsMiddleware) GetFailedCallCount() int
- func (m *PatchToolCallsMiddleware) GetFailedCalls() []FailedToolCall
- func (m *PatchToolCallsMiddleware) GetFailedCallsByTool(toolName string) []FailedToolCall
- func (m *PatchToolCallsMiddleware) WrapToolCall(ctx context.Context, req *ToolCallRequest, handler ToolCallHandler) (*ToolCallResponse, error)
- type PatchToolCallsMiddlewareConfig
- type QuerySubagentTool
- func (t *QuerySubagentTool) Description() string
- func (t *QuerySubagentTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (t *QuerySubagentTool) InputSchema() map[string]interface{}
- func (t *QuerySubagentTool) Name() string
- func (t *QuerySubagentTool) Prompt() string
- type ReasoningMiddleware
- type ReasoningMiddlewareConfig
- type ReasoningTool
- func (rt *ReasoningTool) Description() string
- func (rt *ReasoningTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (rt *ReasoningTool) InputSchema() map[string]interface{}
- func (rt *ReasoningTool) Name() string
- func (rt *ReasoningTool) Prompt() string
- type Registry
- type ResumeSubagentTool
- func (t *ResumeSubagentTool) Description() string
- func (t *ResumeSubagentTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (t *ResumeSubagentTool) InputSchema() map[string]interface{}
- func (t *ResumeSubagentTool) Name() string
- func (t *ResumeSubagentTool) Prompt() string
- type ReviewRequest
- type SimpleSubAgent
- type Stack
- func (s *Stack) ExecuteModelCall(ctx context.Context, req *ModelRequest, finalHandler ModelCallHandler) (*ModelResponse, error)
- func (s *Stack) ExecuteToolCall(ctx context.Context, req *ToolCallRequest, finalHandler ToolCallHandler) (*ToolCallResponse, error)
- func (s *Stack) Middlewares() []Middleware
- func (s *Stack) OnAgentStart(ctx context.Context, agentID string) error
- func (s *Stack) OnAgentStop(ctx context.Context, agentID string) error
- func (s *Stack) Tools() []tools.Tool
- type StopSubagentTool
- func (t *StopSubagentTool) Description() string
- func (t *StopSubagentTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (t *StopSubagentTool) InputSchema() map[string]interface{}
- func (t *StopSubagentTool) Name() string
- func (t *StopSubagentTool) Prompt() string
- type StructuredOutputMiddleware
- type StructuredOutputMiddlewareConfig
- type SubAgent
- type SubAgentFactory
- type SubAgentMiddleware
- func (m *SubAgentMiddleware) GetMiddlewareForSubAgent(spec SubAgentSpec, parentMiddlewares []Middleware) []Middleware
- func (m *SubAgentMiddleware) GetSubAgent(name string) (SubAgent, error)
- func (m *SubAgentMiddleware) ListSubAgents() []string
- func (m *SubAgentMiddleware) OnAgentStop(ctx context.Context, agentID string) error
- func (m *SubAgentMiddleware) Tools() []tools.Tool
- type SubAgentMiddlewareConfig
- type SubAgentResult
- type SubAgentSpec
- type SummarizationMiddleware
- func (m *SummarizationMiddleware) GetConfig() map[string]interface{}
- func (m *SummarizationMiddleware) GetSummarizationCount() int
- func (m *SummarizationMiddleware) ResetSummarizationCount()
- func (m *SummarizationMiddleware) UpdateConfig(maxTokens, messagesToKeep int)
- func (m *SummarizationMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
- type SummarizationMiddlewareConfig
- type SummarizerFunc
- type TaskTool
- type TodoItem
- type TodoListMiddleware
- type TodoListMiddlewareConfig
- type TodoStatus
- type TokenCounterFunc
- type ToolCallHandler
- type ToolCallRequest
- type ToolCallResponse
- type UpdateWorkingMemoryTool
- func (t *UpdateWorkingMemoryTool) Description() string
- func (t *UpdateWorkingMemoryTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (t *UpdateWorkingMemoryTool) InputSchema() map[string]interface{}
- func (t *UpdateWorkingMemoryTool) Name() string
- func (t *UpdateWorkingMemoryTool) Prompt() string
- type WorkingMemoryMiddleware
- func (m *WorkingMemoryMiddleware) GetConfig() map[string]interface{}
- func (m *WorkingMemoryMiddleware) GetManager() *memory.WorkingMemoryManager
- func (m *WorkingMemoryMiddleware) Tools() []tools.Tool
- func (m *WorkingMemoryMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
- type WorkingMemoryMiddlewareConfig
- type WriteTodosTool
- func (t *WriteTodosTool) Description() string
- func (t *WriteTodosTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
- func (t *WriteTodosTool) InputSchema() map[string]interface{}
- func (t *WriteTodosTool) Name() string
- func (t *WriteTodosTool) Prompt() string
Constants ¶
const (
// AGENT_MEMORY_FILE_PATH Agent 记忆文件的默认路径
AGENT_MEMORY_FILE_PATH = "/agent.md"
)
const FILESYSTEM_SYSTEM_PROMPT = `` /* 531-byte string literal not displayed */
FILESYSTEM_SYSTEM_PROMPT 文件系统提示词
const HITL_SYSTEM_PROMPT = `` /* 587-byte string literal not displayed */
HITL_SYSTEM_PROMPT HITL 系统提示词(可选)
const TODO_LIST_SYSTEM_PROMPT = `` /* 1993-byte string literal not displayed */
TODO_LIST_SYSTEM_PROMPT 任务列表系统提示词
const TODO_TOOL_DESCRIPTION = `` /* 1720-byte string literal not displayed */
TODO_TOOL_DESCRIPTION write_todos 工具详细描述
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry 全局默认注册表
Functions ¶
func ExtractMessages ¶
ExtractMessages 从父代理状态提取消息 用于子代理继承部分上下文
func IsolateContext ¶
func IsolateContext(parentState map[string]interface{}, includeKeys []string) map[string]interface{}
IsolateContext 隔离上下文 从父代理状态中提取必要信息,创建干净的子代理上下文
func NewExperimentalUpdateWorkingMemoryTool ¶
func NewExperimentalUpdateWorkingMemoryTool(manager *memory.WorkingMemoryManager) tools.Tool
NewExperimentalUpdateWorkingMemoryTool 创建实验性 Working Memory 更新工具
func NewMemorySearchTool ¶
NewMemorySearchTool 创建搜索工具
func NewMemoryWriteTool ¶
NewMemoryWriteTool 创建写入工具
func NewUpdateWorkingMemoryTool ¶
func NewUpdateWorkingMemoryTool(manager *memory.WorkingMemoryManager) tools.Tool
NewUpdateWorkingMemoryTool 创建 Working Memory 更新工具
Types ¶
type ActionRequest ¶
type ActionRequest struct {
ToolCallID string // 工具调用ID
ToolName string // 工具名称
Input map[string]interface{} // 工具输入参数
Message string // 审核提示信息
}
ActionRequest 待审核的操作请求
type AgentMemoryMiddleware ¶
type AgentMemoryMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
AgentMemoryMiddleware Agent 记忆中间件 功能: 1. 从 backend 加载 agent.md 文件内容 2. 将内容注入到 system prompt 开头 3. 提供长期记忆使用指南
func NewAgentMemoryMiddleware ¶
func NewAgentMemoryMiddleware(config *AgentMemoryMiddlewareConfig) (*AgentMemoryMiddleware, error)
NewAgentMemoryMiddleware 创建中间件
func (*AgentMemoryMiddleware) GetConfig ¶
func (m *AgentMemoryMiddleware) GetConfig() map[string]interface{}
GetConfig 获取配置信息
func (*AgentMemoryMiddleware) GetMemoryContent ¶
func (m *AgentMemoryMiddleware) GetMemoryContent() string
GetMemoryContent 获取当前加载的记忆内容
func (*AgentMemoryMiddleware) IsMemoryLoaded ¶
func (m *AgentMemoryMiddleware) IsMemoryLoaded() bool
IsMemoryLoaded 检查记忆是否已加载
func (*AgentMemoryMiddleware) OnAgentStart ¶
func (m *AgentMemoryMiddleware) OnAgentStart(ctx context.Context, agentID string) error
OnAgentStart Agent 启动时加载记忆
func (*AgentMemoryMiddleware) ReloadMemory ¶
func (m *AgentMemoryMiddleware) ReloadMemory(ctx context.Context) error
ReloadMemory 重新加载记忆(用于动态更新)
func (*AgentMemoryMiddleware) Tools ¶
func (m *AgentMemoryMiddleware) Tools() []tools.Tool
Tools 返回由 AgentMemoryMiddleware 注入的长期记忆相关工具 这些工具专门针对 memoryPath 下的记忆文件,提供搜索与写入能力
func (*AgentMemoryMiddleware) WrapModelCall ¶
func (m *AgentMemoryMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
WrapModelCall 包装模型调用,注入记忆到 system prompt
type AgentMemoryMiddlewareConfig ¶
type AgentMemoryMiddlewareConfig struct {
Backend backends.BackendProtocol // 存储后端
MemoryPath string // 长期记忆路径前缀,如 "/memories/"
SystemPromptTemplate string // 可选,自定义模板
// BaseNamespace 为所有记忆操作提供一个基础命名空间前缀,用于多租户隔离
// 例如: "users/alice"、"tenants/acme"。memory_* 工具的 namespace 参数会在此基础上再追加。
BaseNamespace string
}
AgentMemoryMiddlewareConfig 配置
type ApprovalHandler ¶
type ApprovalHandler func(ctx context.Context, request *ReviewRequest) ([]Decision, error)
ApprovalHandler 人工审核处理器 用于获取人工决策
type BaseMiddleware ¶
type BaseMiddleware struct {
// contains filtered or unexported fields
}
BaseMiddleware 基础中间件实现 提供默认的空实现,子类只需覆盖需要的方法
func NewBaseMiddleware ¶
func NewBaseMiddleware(name string, priority int) *BaseMiddleware
NewBaseMiddleware 创建基础中间件
func (*BaseMiddleware) Name ¶
func (m *BaseMiddleware) Name() string
func (*BaseMiddleware) OnAgentStart ¶
func (m *BaseMiddleware) OnAgentStart(ctx context.Context, agentID string) error
func (*BaseMiddleware) OnAgentStop ¶
func (m *BaseMiddleware) OnAgentStop(ctx context.Context, agentID string) error
func (*BaseMiddleware) Priority ¶
func (m *BaseMiddleware) Priority() int
func (*BaseMiddleware) Tools ¶
func (m *BaseMiddleware) Tools() []tools.Tool
func (*BaseMiddleware) WrapModelCall ¶
func (m *BaseMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
func (*BaseMiddleware) WrapToolCall ¶
func (m *BaseMiddleware) WrapToolCall(ctx context.Context, req *ToolCallRequest, handler ToolCallHandler) (*ToolCallResponse, error)
type Decision ¶
type Decision struct {
Type DecisionType // 决策类型
EditedInput map[string]interface{} // 编辑后的参数(仅 type=edit 时有效)
Reason string // 决策理由(可选)
}
Decision 人工决策
type DecisionType ¶
type DecisionType string
DecisionType 审核决策类型
const ( DecisionApprove DecisionType = "approve" // 批准执行 DecisionReject DecisionType = "reject" // 拒绝执行 DecisionEdit DecisionType = "edit" // 编辑参数后执行 )
type EditTool ¶
type EditTool struct {
// contains filtered or unexported fields
}
EditTool 文件编辑工具
func (*EditTool) Description ¶
func (*EditTool) InputSchema ¶
type ExperimentalUpdateWorkingMemoryTool ¶
type ExperimentalUpdateWorkingMemoryTool struct {
// contains filtered or unexported fields
}
ExperimentalUpdateWorkingMemoryTool Working Memory 更新工具(实验性,支持 find/replace) 对标 Mastra 的 __experimental_updateWorkingMemoryToolVNext
func (*ExperimentalUpdateWorkingMemoryTool) Description ¶
func (t *ExperimentalUpdateWorkingMemoryTool) Description() string
func (*ExperimentalUpdateWorkingMemoryTool) Execute ¶
func (t *ExperimentalUpdateWorkingMemoryTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
func (*ExperimentalUpdateWorkingMemoryTool) InputSchema ¶
func (t *ExperimentalUpdateWorkingMemoryTool) InputSchema() map[string]interface{}
func (*ExperimentalUpdateWorkingMemoryTool) Name ¶
func (t *ExperimentalUpdateWorkingMemoryTool) Name() string
func (*ExperimentalUpdateWorkingMemoryTool) Prompt ¶
func (t *ExperimentalUpdateWorkingMemoryTool) Prompt() string
type FailedToolCall ¶
type FailedToolCall struct {
Timestamp time.Time
ToolName string
ToolCallID string
Input map[string]interface{}
Error string
}
FailedToolCall 失败的工具调用记录
type FilesystemMiddleware ¶
type FilesystemMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
FilesystemMiddleware 文件系统中间件 功能: 1. 注入文件系统工具 (ls, read, write, edit, glob, grep) 2. 自动驱逐大结果到文件 3. 增强系统提示词 4. 路径安全验证
func NewFilesystemMiddleware ¶
func NewFilesystemMiddleware(config *FilesystemMiddlewareConfig) *FilesystemMiddleware
NewFilesystemMiddleware 创建文件系统中间件
func (*FilesystemMiddleware) Tools ¶
func (m *FilesystemMiddleware) Tools() []tools.Tool
Tools 返回文件系统工具
func (*FilesystemMiddleware) WrapModelCall ¶
func (m *FilesystemMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
WrapModelCall 包装模型调用
func (*FilesystemMiddleware) WrapToolCall ¶
func (m *FilesystemMiddleware) WrapToolCall(ctx context.Context, req *ToolCallRequest, handler ToolCallHandler) (*ToolCallResponse, error)
WrapToolCall 包装工具调用
type FilesystemMiddlewareConfig ¶
type FilesystemMiddlewareConfig struct {
Backend backends.BackendProtocol // 后端存储
TokenLimit int // 大结果驱逐阈值(tokens)
EnableEviction bool // 是否启用自动驱逐
AllowedPathPrefixes []string // 允许的路径前缀列表(用于路径安全验证)
EnablePathValidation bool // 是否启用路径验证(默认: true)
CustomToolDescriptions map[string]string // 自定义工具描述
SystemPromptOverride string // 覆盖默认系统提示词
}
FilesystemMiddlewareConfig 文件系统中间件配置
type GlobTool ¶
type GlobTool struct {
// contains filtered or unexported fields
}
GlobTool Glob 模式匹配工具
func (*GlobTool) Description ¶
func (*GlobTool) InputSchema ¶
type GrepTool ¶
type GrepTool struct {
// contains filtered or unexported fields
}
GrepTool 正则搜索工具
func (*GrepTool) Description ¶
func (*GrepTool) InputSchema ¶
type HumanInTheLoopMiddleware ¶
type HumanInTheLoopMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
HumanInTheLoopMiddleware 人工审核中间件 功能: 1. 拦截敏感工具调用 2. 请求人工批准/拒绝/编辑 3. 支持批量审核 4. 灵活的审核配置
func NewHumanInTheLoopMiddleware ¶
func NewHumanInTheLoopMiddleware(config *HumanInTheLoopMiddlewareConfig) (*HumanInTheLoopMiddleware, error)
NewHumanInTheLoopMiddleware 创建 HITL 中间件
func (*HumanInTheLoopMiddleware) GetInterruptConfig ¶
func (m *HumanInTheLoopMiddleware) GetInterruptConfig(toolName string) (*InterruptConfig, bool)
GetInterruptConfig 获取工具的审核配置
func (*HumanInTheLoopMiddleware) IsToolInterruptible ¶
func (m *HumanInTheLoopMiddleware) IsToolInterruptible(toolName string) bool
IsToolInterruptible 检查工具是否需要审核
func (*HumanInTheLoopMiddleware) ListInterruptibleTools ¶
func (m *HumanInTheLoopMiddleware) ListInterruptibleTools() []string
ListInterruptibleTools 列出所有需要审核的工具
func (*HumanInTheLoopMiddleware) SetApprovalHandler ¶
func (m *HumanInTheLoopMiddleware) SetApprovalHandler(handler ApprovalHandler)
SetApprovalHandler 设置审核处理器
func (*HumanInTheLoopMiddleware) WrapToolCall ¶
func (m *HumanInTheLoopMiddleware) WrapToolCall(ctx context.Context, req *ToolCallRequest, handler ToolCallHandler) (*ToolCallResponse, error)
WrapToolCall 拦截工具调用,请求人工审核
type HumanInTheLoopMiddlewareConfig ¶
type HumanInTheLoopMiddlewareConfig struct {
// InterruptOn 配置哪些工具需要审核
// key: 工具名称, value: 审核配置
// 支持三种格式:
// 1. true: 启用默认审核配置
// 2. false: 禁用审核
// 3. InterruptConfig: 自定义审核配置
InterruptOn map[string]interface{}
// ApprovalHandler 人工审核处理器
// 如果为 nil, 默认自动批准所有请求
ApprovalHandler ApprovalHandler
// DefaultAllowedDecisions 默认允许的决策类型
DefaultAllowedDecisions []DecisionType
}
HumanInTheLoopMiddlewareConfig HITL 中间件配置
type InterruptConfig ¶
type InterruptConfig struct {
Enabled bool // 是否启用审核
AllowedDecisions []DecisionType // 允许的决策类型(默认: approve, edit, reject)
Message string // 自定义审核提示信息
}
InterruptConfig 工具审核配置
type ListSubagentsTool ¶ added in v0.13.0
type ListSubagentsTool struct {
// contains filtered or unexported fields
}
ListSubagentsTool 列出所有子代理工具
func (*ListSubagentsTool) Description ¶ added in v0.13.0
func (t *ListSubagentsTool) Description() string
func (*ListSubagentsTool) Execute ¶ added in v0.13.0
func (t *ListSubagentsTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
func (*ListSubagentsTool) InputSchema ¶ added in v0.13.0
func (t *ListSubagentsTool) InputSchema() map[string]interface{}
func (*ListSubagentsTool) Name ¶ added in v0.13.0
func (t *ListSubagentsTool) Name() string
func (*ListSubagentsTool) Prompt ¶ added in v0.13.0
func (t *ListSubagentsTool) Prompt() string
type LsTool ¶
type LsTool struct {
// contains filtered or unexported fields
}
LsTool 目录列表工具
func (*LsTool) Description ¶
func (*LsTool) InputSchema ¶
type MemorySearchTool ¶
type MemorySearchTool struct {
// contains filtered or unexported fields
}
MemorySearchTool 基于 Manager 的记忆搜索工具 特点: - 仅在 memoryPath 下搜索,避免扫描整个文件系统 - 默认使用大小写不敏感的字面量匹配
func (*MemorySearchTool) Description ¶
func (t *MemorySearchTool) Description() string
func (*MemorySearchTool) Execute ¶
func (t *MemorySearchTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
func (*MemorySearchTool) InputSchema ¶
func (t *MemorySearchTool) InputSchema() map[string]interface{}
func (*MemorySearchTool) Name ¶
func (t *MemorySearchTool) Name() string
func (*MemorySearchTool) Prompt ¶
func (t *MemorySearchTool) Prompt() string
type MemoryWriteTool ¶
type MemoryWriteTool struct {
// contains filtered or unexported fields
}
MemoryWriteTool 记忆写入/追加工具 通过普通文本写入而不是向量数据库,保持可读可编辑
func (*MemoryWriteTool) Description ¶
func (t *MemoryWriteTool) Description() string
func (*MemoryWriteTool) Execute ¶
func (t *MemoryWriteTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
func (*MemoryWriteTool) InputSchema ¶
func (t *MemoryWriteTool) InputSchema() map[string]interface{}
func (*MemoryWriteTool) Name ¶
func (t *MemoryWriteTool) Name() string
func (*MemoryWriteTool) Prompt ¶
func (t *MemoryWriteTool) Prompt() string
type Middleware ¶
type Middleware interface {
// Name 返回中间件名称
Name() string
// Priority 返回优先级 (数值越小优先级越高,越早执行)
// 建议范围: 0-1000
// 0-100: 系统核心中间件
// 100-500: 功能中间件
// 500-1000: 用户自定义中间件
Priority() int
// Tools 注入工具列表
// 返回中间件提供的工具,会被合并到 Agent 的工具集中
Tools() []tools.Tool
// WrapModelCall 包装模型调用
// 在模型调用前后执行自定义逻辑
// handler: 下一层处理器(可能是下一个中间件或最终的模型调用)
WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
// WrapToolCall 包装工具调用
// 在工具调用前后执行自定义逻辑
// handler: 下一层处理器(可能是下一个中间件或最终的工具执行)
WrapToolCall(ctx context.Context, req *ToolCallRequest, handler ToolCallHandler) (*ToolCallResponse, error)
// OnAgentStart Agent 启动时回调
OnAgentStart(ctx context.Context, agentID string) error
// OnAgentStop Agent 停止时回调
OnAgentStop(ctx context.Context, agentID string) error
}
Middleware 中间件接口 中间件采用洋葱模型,支持请求和响应的拦截处理
func BuildSubAgentMiddlewareStack ¶
func BuildSubAgentMiddlewareStack(spec SubAgentSpec, parentMiddlewares []Middleware) []Middleware
BuildSubAgentMiddlewareStack 构建子代理的中间件栈 根据子代理规格决定是否继承父代理中间件
type MiddlewareFactory ¶
type MiddlewareFactory func(config *MiddlewareFactoryConfig) (Middleware, error)
MiddlewareFactory 中间件工厂函数 config参数可用于传递Provider等依赖
type MiddlewareFactoryConfig ¶
type MiddlewareFactoryConfig struct {
Provider provider.Provider
AgentID string
Metadata map[string]interface{}
CustomConfig map[string]interface{} // 自定义配置
Sandbox sandbox.Sandbox // 可选: 需要访问沙箱文件系统的中间件
}
MiddlewareFactoryConfig 工厂配置
type ModelCallHandler ¶
type ModelCallHandler func(ctx context.Context, req *ModelRequest) (*ModelResponse, error)
ModelCallHandler 模型调用处理器
type ModelRequest ¶
type ModelRequest struct {
Messages []types.Message
SystemPrompt string
Tools []tools.Tool
Metadata map[string]interface{}
}
ModelRequest 模型请求
type ModelResponse ¶
ModelResponse 模型响应
type PatchToolCallsMiddleware ¶
type PatchToolCallsMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
PatchToolCallsMiddleware 工具调用错误恢复中间件 功能: 1. 捕获工具调用异常,防止崩溃 2. 提供友好的错误响应 3. 记录失败的工具调用供调试
func NewPatchToolCallsMiddleware ¶
func NewPatchToolCallsMiddleware(config *PatchToolCallsMiddlewareConfig) *PatchToolCallsMiddleware
NewPatchToolCallsMiddleware 创建中间件
func (*PatchToolCallsMiddleware) ClearFailedCalls ¶
func (m *PatchToolCallsMiddleware) ClearFailedCalls()
ClearFailedCalls 清空失败记录
func (*PatchToolCallsMiddleware) GetFailedCallCount ¶
func (m *PatchToolCallsMiddleware) GetFailedCallCount() int
GetFailedCallCount 获取失败次数
func (*PatchToolCallsMiddleware) GetFailedCalls ¶
func (m *PatchToolCallsMiddleware) GetFailedCalls() []FailedToolCall
GetFailedCalls 获取失败的工具调用记录
func (*PatchToolCallsMiddleware) GetFailedCallsByTool ¶
func (m *PatchToolCallsMiddleware) GetFailedCallsByTool(toolName string) []FailedToolCall
GetFailedCallsByTool 获取特定工具的失败记录
func (*PatchToolCallsMiddleware) WrapToolCall ¶
func (m *PatchToolCallsMiddleware) WrapToolCall(ctx context.Context, req *ToolCallRequest, handler ToolCallHandler) (*ToolCallResponse, error)
WrapToolCall 包装工具调用,捕获异常
type PatchToolCallsMiddlewareConfig ¶
type PatchToolCallsMiddlewareConfig struct {
EnableLogging bool // 是否记录失败调用
MaxFailedCalls int // 最多保留多少条失败记录
ProvideHints bool // 是否在错误响应中提供修复提示
}
PatchToolCallsMiddlewareConfig 配置
type QuerySubagentTool ¶ added in v0.13.0
type QuerySubagentTool struct {
// contains filtered or unexported fields
}
QuerySubagentTool 查询子代理状态工具
func (*QuerySubagentTool) Description ¶ added in v0.13.0
func (t *QuerySubagentTool) Description() string
func (*QuerySubagentTool) Execute ¶ added in v0.13.0
func (t *QuerySubagentTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
func (*QuerySubagentTool) InputSchema ¶ added in v0.13.0
func (t *QuerySubagentTool) InputSchema() map[string]interface{}
func (*QuerySubagentTool) Name ¶ added in v0.13.0
func (t *QuerySubagentTool) Name() string
func (*QuerySubagentTool) Prompt ¶ added in v0.13.0
func (t *QuerySubagentTool) Prompt() string
type ReasoningMiddleware ¶ added in v0.13.0
type ReasoningMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
ReasoningMiddleware 推理中间件
func NewReasoningMiddleware ¶ added in v0.13.0
func NewReasoningMiddleware(config *ReasoningMiddlewareConfig) *ReasoningMiddleware
NewReasoningMiddleware 创建推理中间件
func (*ReasoningMiddleware) Tools ¶ added in v0.13.0
func (rm *ReasoningMiddleware) Tools() []tools.Tool
Tools 返回中间件提供的工具
func (*ReasoningMiddleware) WrapModelCall ¶ added in v0.13.0
func (rm *ReasoningMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
WrapModelCall 包装模型调用(实现 Middleware 接口)
type ReasoningMiddlewareConfig ¶ added in v0.13.0
type ReasoningMiddlewareConfig struct {
Provider provider.Provider
MinSteps int
MaxSteps int
MinConfidence float64
UseJSON bool
Temperature float64
Enabled bool
Priority int
}
ReasoningMiddlewareConfig 推理中间件配置
type ReasoningTool ¶ added in v0.13.0
type ReasoningTool struct {
// contains filtered or unexported fields
}
ReasoningTool 推理工具
func NewReasoningTool ¶ added in v0.13.0
func NewReasoningTool(engine *reasoning.Engine) *ReasoningTool
NewReasoningTool 创建推理工具
func (*ReasoningTool) Description ¶ added in v0.13.0
func (rt *ReasoningTool) Description() string
Description 返回工具描述
func (*ReasoningTool) Execute ¶ added in v0.13.0
func (rt *ReasoningTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
Execute 执行工具
func (*ReasoningTool) InputSchema ¶ added in v0.13.0
func (rt *ReasoningTool) InputSchema() map[string]interface{}
InputSchema 返回输入 Schema
func (*ReasoningTool) Prompt ¶ added in v0.13.0
func (rt *ReasoningTool) Prompt() string
Prompt 返回工具提示
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 中间件注册表
func (*Registry) Create ¶
func (r *Registry) Create(name string, config *MiddlewareFactoryConfig) (Middleware, error)
Create 创建中间件实例
func (*Registry) Register ¶
func (r *Registry) Register(name string, factory MiddlewareFactory)
Register 注册中间件工厂
type ResumeSubagentTool ¶ added in v0.13.0
type ResumeSubagentTool struct {
// contains filtered or unexported fields
}
ResumeSubagentTool 恢复子代理工具
func (*ResumeSubagentTool) Description ¶ added in v0.13.0
func (t *ResumeSubagentTool) Description() string
func (*ResumeSubagentTool) Execute ¶ added in v0.13.0
func (t *ResumeSubagentTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
func (*ResumeSubagentTool) InputSchema ¶ added in v0.13.0
func (t *ResumeSubagentTool) InputSchema() map[string]interface{}
func (*ResumeSubagentTool) Name ¶ added in v0.13.0
func (t *ResumeSubagentTool) Name() string
func (*ResumeSubagentTool) Prompt ¶ added in v0.13.0
func (t *ResumeSubagentTool) Prompt() string
type ReviewRequest ¶
type ReviewRequest struct {
ActionRequests []ActionRequest // 待审核的操作列表
ReviewConfigs []InterruptConfig // 每个操作的审核配置
}
ReviewRequest 审核请求
type SimpleSubAgent ¶
type SimpleSubAgent struct {
// contains filtered or unexported fields
}
SimpleSubAgent 简单子代理实现 用于测试和演示
func NewSimpleSubAgent ¶
func (*SimpleSubAgent) Close ¶
func (a *SimpleSubAgent) Close() error
func (*SimpleSubAgent) Name ¶
func (a *SimpleSubAgent) Name() string
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack 中间件栈 管理多个中间件,构建洋葱模型的调用链
func (*Stack) ExecuteModelCall ¶
func (s *Stack) ExecuteModelCall( ctx context.Context, req *ModelRequest, finalHandler ModelCallHandler, ) (*ModelResponse, error)
ExecuteModelCall 执行模型调用(通过中间件栈)
func (*Stack) ExecuteToolCall ¶
func (s *Stack) ExecuteToolCall( ctx context.Context, req *ToolCallRequest, finalHandler ToolCallHandler, ) (*ToolCallResponse, error)
ExecuteToolCall 执行工具调用(通过中间件栈)
func (*Stack) OnAgentStart ¶
OnAgentStart 通知所有中间件 Agent 启动
func (*Stack) OnAgentStop ¶
OnAgentStop 通知所有中间件 Agent 停止
type StopSubagentTool ¶ added in v0.13.0
type StopSubagentTool struct {
// contains filtered or unexported fields
}
StopSubagentTool 停止子代理工具
func (*StopSubagentTool) Description ¶ added in v0.13.0
func (t *StopSubagentTool) Description() string
func (*StopSubagentTool) Execute ¶ added in v0.13.0
func (t *StopSubagentTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
func (*StopSubagentTool) InputSchema ¶ added in v0.13.0
func (t *StopSubagentTool) InputSchema() map[string]interface{}
func (*StopSubagentTool) Name ¶ added in v0.13.0
func (t *StopSubagentTool) Name() string
func (*StopSubagentTool) Prompt ¶ added in v0.13.0
func (t *StopSubagentTool) Prompt() string
type StructuredOutputMiddleware ¶ added in v0.13.0
type StructuredOutputMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
StructuredOutputMiddleware 在模型响应后尝试解析结构化输出,并将结果写入 Metadata。 - 若解析成功: Metadata["structured_data"] = 解析后的对象,Metadata["structured_raw_json"] = 原始 JSON 文本 - 若解析失败: 根据配置决定是否回退;错误记录在 Metadata["structured_error"]
func NewStructuredOutputMiddleware ¶ added in v0.13.0
func NewStructuredOutputMiddleware(cfg *StructuredOutputMiddlewareConfig) (*StructuredOutputMiddleware, error)
NewStructuredOutputMiddleware 创建中间件实例
func (*StructuredOutputMiddleware) WrapModelCall ¶ added in v0.13.0
func (m *StructuredOutputMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
WrapModelCall 尝试解析结构化输出
type StructuredOutputMiddlewareConfig ¶ added in v0.13.0
type StructuredOutputMiddlewareConfig struct {
Spec structured.OutputSpec
Parser structured.Parser // 可选,默认 JSONParser
AllowError bool // 解析失败时是否忽略错误并回退到原始文本
Priority int // 可选,默认 60
}
StructuredOutputMiddlewareConfig 配置
type SubAgent ¶
type SubAgent interface {
// Name 返回子代理名称
Name() string
// Execute 执行任务
// description: 任务描述
// context: 父代理上下文(可选)
Execute(ctx context.Context, description string, parentContext map[string]interface{}) (string, error)
// Close 关闭子代理
Close() error
}
SubAgent 子代理接口
type SubAgentFactory ¶
type SubAgentFactory func(ctx context.Context, spec SubAgentSpec) (SubAgent, error)
SubAgentFactory 子代理工厂函数 用于创建子代理实例
type SubAgentMiddleware ¶
type SubAgentMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
SubAgentMiddleware 子代理中间件 功能: 1. 管理多个子代理实例 2. 提供 task 工具启动子代理 3. 支持任务上下文隔离 4. 支持并发执行 5. 支持异步执行和状态查询 6. 支持 Resume 机制 7. 支持资源监控和限制
func NewSubAgentMiddleware ¶
func NewSubAgentMiddleware(config *SubAgentMiddlewareConfig) (*SubAgentMiddleware, error)
NewSubAgentMiddleware 创建子代理中间件
func (*SubAgentMiddleware) GetMiddlewareForSubAgent ¶
func (m *SubAgentMiddleware) GetMiddlewareForSubAgent(spec SubAgentSpec, parentMiddlewares []Middleware) []Middleware
GetMiddlewareForSubAgent 获取子代理应该使用的中间件栈 这是一个辅助函数,供 SubAgentFactory 实现使用
func (*SubAgentMiddleware) GetSubAgent ¶
func (m *SubAgentMiddleware) GetSubAgent(name string) (SubAgent, error)
GetSubAgent 获取子代理
func (*SubAgentMiddleware) ListSubAgents ¶
func (m *SubAgentMiddleware) ListSubAgents() []string
ListSubAgents 列出所有子代理
func (*SubAgentMiddleware) OnAgentStop ¶
func (m *SubAgentMiddleware) OnAgentStop(ctx context.Context, agentID string) error
OnAgentStop 清理子代理
func (*SubAgentMiddleware) Tools ¶
func (m *SubAgentMiddleware) Tools() []tools.Tool
Tools 返回 task 工具和管理工具
type SubAgentMiddlewareConfig ¶
type SubAgentMiddlewareConfig struct {
Specs []SubAgentSpec // 子代理规格列表
Factory SubAgentFactory // 子代理工厂
Manager builtin.SubagentManager // 子代理管理器(可选,默认使用 FileSubagentManager)
EnableParallel bool // 是否支持并行执行
EnableGeneralPurpose bool // 是否启用通用子代理(默认 true)
EnableAsync bool // 是否启用异步执行(默认 false)
EnableProcessIsolation bool // 是否启用进程级隔离(默认 false)
DefaultTimeout time.Duration // 默认超时时间(默认 1 小时)
ParentMiddlewareGetter func() []Middleware
}
SubAgentMiddlewareConfig 子代理中间件配置
type SubAgentResult ¶
type SubAgentResult struct {
Success bool `json:"success"`
SubAgentType string `json:"subagent_type"`
Result string `json:"result"`
Error string `json:"error,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
SubAgentResult 子代理执行结果
type SubAgentSpec ¶
type SubAgentSpec struct {
Name string // 子代理名称
Description string // 子代理描述
Prompt string // 子代理专用提示词
Tools []string // 工具名称列表(可选,默认继承父代理)
Config map[string]interface{} // 自定义配置
InheritMiddlewares bool // 是否继承父代理的中间件栈(默认 false)
MiddlewareOverrides []Middleware // 子代理专用中间件(覆盖或追加)
}
SubAgentSpec 子代理规格
type SummarizationMiddleware ¶
type SummarizationMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
SummarizationMiddleware 自动总结对话历史以管理上下文窗口 功能: 1. 监控消息历史的 token 数量 2. 当超过阈值时,自动总结旧消息 3. 保留最近的 N 条消息 4. 用总结消息替换旧的历史记录
func NewSummarizationMiddleware ¶
func NewSummarizationMiddleware(config *SummarizationMiddlewareConfig) (*SummarizationMiddleware, error)
NewSummarizationMiddleware 创建中间件
func (*SummarizationMiddleware) GetConfig ¶
func (m *SummarizationMiddleware) GetConfig() map[string]interface{}
GetConfig 获取当前配置
func (*SummarizationMiddleware) GetSummarizationCount ¶
func (m *SummarizationMiddleware) GetSummarizationCount() int
GetSummarizationCount 获取总结触发次数
func (*SummarizationMiddleware) ResetSummarizationCount ¶
func (m *SummarizationMiddleware) ResetSummarizationCount()
ResetSummarizationCount 重置计数器
func (*SummarizationMiddleware) UpdateConfig ¶
func (m *SummarizationMiddleware) UpdateConfig(maxTokens, messagesToKeep int)
UpdateConfig 动态更新配置
func (*SummarizationMiddleware) WrapModelCall ¶
func (m *SummarizationMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
WrapModelCall 包装模型调用,在调用前检查是否需要总结
type SummarizationMiddlewareConfig ¶
type SummarizationMiddlewareConfig struct {
Summarizer SummarizerFunc // 用于生成总结的函数
MaxTokensBeforeSummary int // 触发总结的 token 阈值
MessagesToKeep int // 总结后保留的最近消息数量
SummaryPrefix string // 总结消息的前缀
TokenCounter TokenCounterFunc // 自定义 token 计数器
}
SummarizationMiddlewareConfig 配置
type SummarizerFunc ¶
SummarizerFunc 总结生成函数类型 接收要总结的消息列表,返回总结内容字符串
type TaskTool ¶
type TaskTool struct {
// contains filtered or unexported fields
}
TaskTool task 工具实现
func (*TaskTool) Description ¶
func (*TaskTool) InputSchema ¶
type TodoItem ¶
type TodoItem struct {
Content string `json:"content"` // 任务内容描述
Status TodoStatus `json:"status"` // 任务状态
ActiveForm string `json:"activeForm"` // 进行时描述
}
TodoItem 任务项
type TodoListMiddleware ¶
type TodoListMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
TodoListMiddleware 任务列表中间件 功能: 1. 提供 write_todos 工具,允许 Agent 进行任务规划 2. 管理任务列表的状态 3. 引导 Agent 使用任务分解策略
func NewTodoListMiddleware ¶
func NewTodoListMiddleware(config *TodoListMiddlewareConfig) *TodoListMiddleware
NewTodoListMiddleware 创建任务列表中间件
func (*TodoListMiddleware) GetTodos ¶
func (m *TodoListMiddleware) GetTodos() []TodoItem
GetTodos 获取当前任务列表
func (*TodoListMiddleware) SetTodos ¶
func (m *TodoListMiddleware) SetTodos(todos []TodoItem)
SetTodos 设置任务列表
func (*TodoListMiddleware) Tools ¶
func (m *TodoListMiddleware) Tools() []tools.Tool
Tools 返回 write_todos 工具
func (*TodoListMiddleware) WrapModelCall ¶
func (m *TodoListMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
WrapModelCall 包装模型调用,注入系统提示词
type TodoListMiddlewareConfig ¶
type TodoListMiddlewareConfig struct {
// StoreGetter 从外部状态获取任务列表
// 如果为 nil, 使用内部存储
StoreGetter func() interface{}
// StoreSetter 保存任务列表到外部状态
// 如果为 nil, 使用内部存储
StoreSetter func([]TodoItem)
// EnableSystemPrompt 是否注入系统提示词
EnableSystemPrompt bool
}
TodoListMiddlewareConfig 任务列表中间件配置
type TodoStatus ¶
type TodoStatus string
TodoStatus 任务状态
const ( TodoStatusPending TodoStatus = "pending" TodoStatusInProgress TodoStatus = "in_progress" TodoStatusCompleted TodoStatus = "completed" )
type TokenCounterFunc ¶
TokenCounterFunc 自定义 token 计数函数类型
type ToolCallHandler ¶
type ToolCallHandler func(ctx context.Context, req *ToolCallRequest) (*ToolCallResponse, error)
ToolCallHandler 工具调用处理器
type ToolCallRequest ¶
type ToolCallRequest struct {
ToolCallID string
ToolName string
ToolInput map[string]interface{}
Tool tools.Tool
Context *tools.ToolContext
Metadata map[string]interface{}
}
ToolCallRequest 工具调用请求
type ToolCallResponse ¶
type ToolCallResponse struct {
Result interface{}
Metadata map[string]interface{}
}
ToolCallResponse 工具调用响应
type UpdateWorkingMemoryTool ¶
type UpdateWorkingMemoryTool struct {
// contains filtered or unexported fields
}
UpdateWorkingMemoryTool Working Memory 更新工具 特点: - 自动从 ToolContext 获取 threadID 和 resourceID - 支持 JSON Schema 验证(如果配置) - 支持 Markdown 或 JSON 格式的内容
func (*UpdateWorkingMemoryTool) Description ¶
func (t *UpdateWorkingMemoryTool) Description() string
func (*UpdateWorkingMemoryTool) Execute ¶
func (t *UpdateWorkingMemoryTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
func (*UpdateWorkingMemoryTool) InputSchema ¶
func (t *UpdateWorkingMemoryTool) InputSchema() map[string]interface{}
func (*UpdateWorkingMemoryTool) Name ¶
func (t *UpdateWorkingMemoryTool) Name() string
func (*UpdateWorkingMemoryTool) Prompt ¶
func (t *UpdateWorkingMemoryTool) Prompt() string
type WorkingMemoryMiddleware ¶
type WorkingMemoryMiddleware struct {
*BaseMiddleware
// contains filtered or unexported fields
}
WorkingMemoryMiddleware Working Memory 中间件 功能: 1. 根据 threadID/resourceID 加载 Working Memory 2. 将 Working Memory 内容注入到 system prompt 3. 提供 update_working_memory 工具
func NewWorkingMemoryMiddleware ¶
func NewWorkingMemoryMiddleware(config *WorkingMemoryMiddlewareConfig) (*WorkingMemoryMiddleware, error)
NewWorkingMemoryMiddleware 创建 Working Memory 中间件
func (*WorkingMemoryMiddleware) GetConfig ¶
func (m *WorkingMemoryMiddleware) GetConfig() map[string]interface{}
GetConfig 获取配置信息
func (*WorkingMemoryMiddleware) GetManager ¶
func (m *WorkingMemoryMiddleware) GetManager() *memory.WorkingMemoryManager
GetManager 获取 Working Memory 管理器(用于测试或高级用法)
func (*WorkingMemoryMiddleware) Tools ¶
func (m *WorkingMemoryMiddleware) Tools() []tools.Tool
Tools 返回 Working Memory 相关工具
func (*WorkingMemoryMiddleware) WrapModelCall ¶
func (m *WorkingMemoryMiddleware) WrapModelCall(ctx context.Context, req *ModelRequest, handler ModelCallHandler) (*ModelResponse, error)
WrapModelCall 包装模型调用,注入 Working Memory 到 system prompt
type WorkingMemoryMiddlewareConfig ¶
type WorkingMemoryMiddlewareConfig struct {
Backend backends.BackendProtocol // 存储后端
BasePath string // 存储根路径,默认 "/working_memory/"
Scope memory.WorkingMemoryScope // "thread" | "resource"
Schema *memory.JSONSchema // 可选的 JSON Schema
Template string // 可选的 Markdown 模板
TTL time.Duration // 可选的过期时间(0 表示不过期)
SystemPromptTemplate string // 可选,自定义 system prompt 模板
Experimental bool // 是否启用实验性功能
}
WorkingMemoryMiddlewareConfig 配置
type WriteTodosTool ¶
type WriteTodosTool struct {
// contains filtered or unexported fields
}
WriteTodosTool write_todos 工具实现
func (*WriteTodosTool) Description ¶
func (t *WriteTodosTool) Description() string
func (*WriteTodosTool) Execute ¶
func (t *WriteTodosTool) Execute(ctx context.Context, input map[string]interface{}, tc *tools.ToolContext) (interface{}, error)
func (*WriteTodosTool) InputSchema ¶
func (t *WriteTodosTool) InputSchema() map[string]interface{}
func (*WriteTodosTool) Name ¶
func (t *WriteTodosTool) Name() string
func (*WriteTodosTool) Prompt ¶
func (t *WriteTodosTool) Prompt() string