builder

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentExecutor added in v0.6.0

func AgentExecutor(agent agentcore.Agent, config *ExecutorConfig) *executor.AgentExecutor

AgentExecutor 创建一个 Agent 执行器

AgentExecutor 提供高级执行逻辑:

  • 记忆管理、对话历史
  • 工具管理
  • 错误处理、重试和早停机制

参数:

  • agent: 要包装的 Agent 实例
  • config: 可选配置,为 nil 时使用默认值

示例:

exec := builder.AgentExecutor(reactAgent, &builder.ExecutorConfig{
    MaxIterations: 15,
    Verbose: true,
})

func CoTAgent added in v0.6.0

func CoTAgent(llmClient llm.Client, config *CoTAgentConfig) *cot.CoTAgent

CoTAgent 创建一个 Chain-of-Thought 推理 Agent

CoT Agent 通过分步骤推理来解决复杂问题:

  • 鼓励模型逐步分解问题
  • 展示中间推理过程
  • 提高复杂任务的准确性
  • 支持 Zero-Shot 和 Few-Shot 提示

参数:

  • llmClient: LLM 客户端
  • config: 可选配置,为 nil 时使用默认值

示例:

agent := builder.CoTAgent(llmClient, &builder.CoTAgentConfig{
    MaxSteps: 10,
    ZeroShot: true,
})

func GetOutputFormatPrompt added in v0.6.0

func GetOutputFormatPrompt(format OutputFormat) string

GetOutputFormatPrompt 获取输出格式对应的提示词 如果格式为 Default 或未定义,返回空字符串

func GoTAgent added in v0.6.0

func GoTAgent(llmClient llm.Client, config *GoTAgentConfig) *got.GoTAgent

GoTAgent 创建一个 Graph-of-Thought Agent

GoT Agent 构建有向无环图(DAG)的思想依赖关系:

  • 支持复杂的多路径推理
  • 包含循环检测和并行执行
  • 合并多条路径的见解

参数:

  • llmClient: LLM 客户端
  • config: 可选配置,为 nil 时使用默认值

示例:

agent := builder.GoTAgent(llmClient, &builder.GoTAgentConfig{
    MaxNodes: 50,
    ParallelExecution: true,
})

func GoTAgentForSlowAPI added in v0.6.0

func GoTAgentForSlowAPI(llmClient llm.Client) *got.GoTAgent

GoTAgentForSlowAPI 创建一个针对慢速 API(如 DeepSeek)优化的 GoT Agent

此预设专为响应较慢的 API 提供商优化:

  • 使用极简模式,仅 2 次 LLM 调用
  • 一次生成多个思考路径
  • 一次合成最终答案

参数:

  • llmClient: LLM 客户端

示例:

agent := builder.GoTAgentForSlowAPI(llmClient)

func MetaCoTAgent added in v0.6.0

func MetaCoTAgent(llmClient llm.Client, config *MetaCoTAgentConfig) *metacot.MetaCoTAgent

MetaCoTAgent 创建一个 Meta Chain-of-Thought / Self-Ask Agent

MetaCoT Agent 实现自我提问和问题分解:

  • 递归回答子问题来构建完整答案
  • 支持自我批判和答案验证
  • 适合需要深度分析的复杂问题

参数:

  • llmClient: LLM 客户端
  • config: 可选配置,为 nil 时使用默认值

示例:

agent := builder.MetaCoTAgent(llmClient, &builder.MetaCoTAgentConfig{
    MaxQuestions: 5,
    SelfCritique: true,
})

func PoTAgent added in v0.6.0

func PoTAgent(llmClient llm.Client, config *PoTAgentConfig) *pot.PoTAgent

PoTAgent 创建一个 Program-of-Thought Agent

PoT Agent 生成可执行代码来解决问题:

  • 支持多语言:Python、JavaScript、Go
  • 包含代码验证、执行、调试
  • 迭代优化直到获得正确答案

参数:

  • llmClient: LLM 客户端
  • config: 可选配置,为 nil 时使用默认值

示例:

agent := builder.PoTAgent(llmClient, &builder.PoTAgentConfig{
    Language: "python",
    ExecutionTimeout: 30 * time.Second,
})

func QuickCoTAgent added in v0.6.0

func QuickCoTAgent(llmClient llm.Client) *cot.CoTAgent

QuickCoTAgent 快速创建一个简单的 CoT Agent

func QuickGoTAgent added in v0.6.0

func QuickGoTAgent(llmClient llm.Client) *got.GoTAgent

QuickGoTAgent 快速创建一个简单的 GoT Agent

func QuickMetaCoTAgent added in v0.6.0

func QuickMetaCoTAgent(llmClient llm.Client) *metacot.MetaCoTAgent

QuickMetaCoTAgent 快速创建一个简单的 MetaCoT Agent

func QuickPoTAgent added in v0.6.0

func QuickPoTAgent(llmClient llm.Client) *pot.PoTAgent

QuickPoTAgent 快速创建一个简单的 PoT Agent(Python)

func QuickReActAgent added in v0.6.0

func QuickReActAgent(llmClient llm.Client, tools []interfaces.Tool) *react.ReActAgent

QuickReActAgent 快速创建一个简单的 ReAct Agent

func QuickSoTAgent added in v0.6.0

func QuickSoTAgent(llmClient llm.Client) *sot.SoTAgent

QuickSoTAgent 快速创建一个简单的 SoT Agent

func QuickToTAgent added in v0.6.0

func QuickToTAgent(llmClient llm.Client) *tot.ToTAgent

QuickToTAgent 快速创建一个简单的 ToT Agent

func ReActAgent added in v0.6.0

func ReActAgent(llmClient llm.Client, tools []interfaces.Tool, config *ReActAgentConfig) *react.ReActAgent

ReActAgent 创建一个 ReAct (Reasoning + Acting) Agent

ReAct Agent 实现思考-行动-观察循环:

  • Thought: 分析当前情况
  • Action: 决定使用哪个工具
  • Observation: 执行工具并观察结果
  • 循环直到得出最终答案

参数:

  • llmClient: LLM 客户端
  • tools: 可用工具列表
  • config: 可选配置,为 nil 时使用默认值

示例:

agent := builder.ReActAgent(llmClient, tools, &builder.ReActAgentConfig{
    MaxSteps: 15,
})

func SoTAgent added in v0.6.0

func SoTAgent(llmClient llm.Client, config *SoTAgentConfig) *sot.SoTAgent

SoTAgent 创建一个 Skeleton-of-Thought Agent

SoT Agent 先生成高层骨架,再并行详细阐述:

  • 优化推理延迟,提高效率
  • 支持依赖管理和并行执行
  • 适合需要结构化输出的任务

参数:

  • llmClient: LLM 客户端
  • config: 可选配置,为 nil 时使用默认值

示例:

agent := builder.SoTAgent(llmClient, &builder.SoTAgentConfig{
    MaxSkeletonPoints: 10,
    MaxConcurrency: 5,
})

func SupervisorAgent added in v0.6.0

func SupervisorAgent(llmClient llm.Client, subAgents map[string]agentcore.Agent, config *SupervisorAgentConfig) *agents.SupervisorAgent

SupervisorAgent 创建一个 Supervisor Agent

Supervisor Agent 协调多个子 Agent 来处理复杂任务:

  • 任务分解、路由、结果聚合
  • 支持缓存、指标、重试策略
  • 适合需要多 Agent 协作的场景

参数:

  • llmClient: LLM 客户端
  • subAgents: 子 Agent 映射 (名称 -> Agent)
  • config: 可选配置,为 nil 时使用默认值

示例:

supervisor := builder.SupervisorAgent(llmClient, map[string]core.Agent{
    "researcher": researchAgent,
    "analyzer": analysisAgent,
}, &builder.SupervisorAgentConfig{
    MaxConcurrentAgents: 5,
})

func ToTAgent added in v0.6.0

func ToTAgent(llmClient llm.Client, config *ToTAgentConfig) *tot.ToTAgent

ToTAgent 创建一个 Tree-of-Thought 推理 Agent

ToT Agent 探索多条推理路径的树形结构:

  • 支持 BFS、DFS、Beam Search、Monte Carlo 搜索策略
  • 动态评估和剪枝低分支
  • 选择最优推理路径

参数:

  • llmClient: LLM 客户端
  • config: 可选配置,为 nil 时使用默认值

示例:

agent := builder.ToTAgent(llmClient, &builder.ToTAgentConfig{
    MaxDepth: 5,
    BranchingFactor: 3,
    SearchStrategy: interfaces.StrategyBeamSearch,
})

Types

type AgentBuilder

type AgentBuilder[C any, S core.State] struct {
	// contains filtered or unexported fields
}

AgentBuilder 提供用于构建 Agent 的 fluent API

受 LangChain 的 create_agent 函数启发,它集成了:

  • LLM 客户端配置
  • 工具注册
  • 状态管理
  • 运行时上下文
  • Store 和 Checkpointer
  • 中间件栈
  • 系统提示词
  • 对话记忆管理

func NewAgentBuilder

func NewAgentBuilder[C any, S core.State](llmClient llm.Client) *AgentBuilder[C, S]

NewAgentBuilder 创建一个新的 Agent 构建器

func (*AgentBuilder[C, S]) Build

func (b *AgentBuilder[C, S]) Build() (*ConfigurableAgent[C, S], error)

Build 构建最终的 Agent

func (*AgentBuilder[C, S]) BuildReasoningAgent

func (b *AgentBuilder[C, S]) BuildReasoningAgent() core.Agent

BuildReasoningAgent builds an agent based on the configured reasoning pattern

This method is called internally by Build() when a reasoning pattern is configured

func (*AgentBuilder[C, S]) ConfigureForAnalysis

func (b *AgentBuilder[C, S]) ConfigureForAnalysis() *AgentBuilder[C, S]

ConfigureForAnalysis 添加用于数据分析任务的组件

func (*AgentBuilder[C, S]) ConfigureForChatbot

func (b *AgentBuilder[C, S]) ConfigureForChatbot() *AgentBuilder[C, S]

ConfigureForChatbot 添加常用的聊天机器人组件

func (*AgentBuilder[C, S]) ConfigureForRAG

func (b *AgentBuilder[C, S]) ConfigureForRAG() *AgentBuilder[C, S]

ConfigureForRAG 添加常用的 RAG (检索增强生成) 组件

func (*AgentBuilder[C, S]) WithAutoSaveEnabled added in v0.2.0

func (b *AgentBuilder[C, S]) WithAutoSaveEnabled(enabled bool) *AgentBuilder[C, S]

WithAutoSaveEnabled 设置是否启用自动保存

[Advanced] 高级配置,控制是否自动保存 Agent 状态(默认 true)。

func (*AgentBuilder[C, S]) WithBeamSearchToT

func (b *AgentBuilder[C, S]) WithBeamSearchToT(beamWidth, maxDepth int) *AgentBuilder[C, S]

WithBeamSearchToT creates a Tree-of-Thought agent with beam search

Example:

agent := NewAgentBuilder(llm).
  WithBeamSearchToT(beamWidth, maxDepth).
  Build()

func (*AgentBuilder[C, S]) WithCallbacks

func (b *AgentBuilder[C, S]) WithCallbacks(callbacks ...core.Callback) *AgentBuilder[C, S]

WithCallbacks 添加回调函数用于监控

[Core] 标准配置,用于监控 Agent 执行过程(日志、指标、调试)。

示例:

agent, _ := builder.NewSimpleBuilder(llm).
    WithSystemPrompt("...").
    WithCallbacks(core.NewStdoutCallback(true)).
    Build()

func (*AgentBuilder[C, S]) WithChainOfThought

func (b *AgentBuilder[C, S]) WithChainOfThought(config ...cot.CoTConfig) *AgentBuilder[C, S]

WithChainOfThought creates a Chain-of-Thought agent

Example:

agent := NewAgentBuilder(llm).
  WithChainOfThought(cot.CoTConfig{
    ZeroShot: true,
    ShowStepNumbers: true,
  }).
  Build()

func (*AgentBuilder[C, S]) WithCheckpointer

func (b *AgentBuilder[C, S]) WithCheckpointer(checkpointer checkpoint.Checkpointer) *AgentBuilder[C, S]

WithCheckpointer 设置会话检查点器

func (*AgentBuilder[C, S]) WithCommunicator

func (b *AgentBuilder[C, S]) WithCommunicator(communicator interface{}) *AgentBuilder[C, S]

WithCommunicator 添加通信器

[Advanced] 高级配置,用于 Agent 间通信(多 Agent 系统)。

func (*AgentBuilder[C, S]) WithContext

func (b *AgentBuilder[C, S]) WithContext(context C) *AgentBuilder[C, S]

WithContext 设置应用上下文

[Advanced] 高级配置,用于自定义上下文类型(需要泛型知识)。 大多数情况下使用默认的 any 即可。

func (*AgentBuilder[C, S]) WithCustomOutputFormat added in v0.6.0

func (b *AgentBuilder[C, S]) WithCustomOutputFormat(prompt string) *AgentBuilder[C, S]

WithCustomOutputFormat 设置自定义输出格式提示词

[Simple] 常用配置,允许用户指定任意格式提示词。 此方法会自动将 OutputFormat 设置为 OutputFormatCustom。

使用示例:

agent, err := builder.NewSimpleBuilder(llmClient).
    WithSystemPrompt("你是一个助手").
    WithCustomOutputFormat("请用表格格式回复,每行一个条目").
    Build()

func (*AgentBuilder[C, S]) WithErrorHandler

func (b *AgentBuilder[C, S]) WithErrorHandler(handler func(error) error) *AgentBuilder[C, S]

WithErrorHandler 设置自定义错误处理函数

[Core] 标准配置,用于自定义错误处理逻辑(例如重试、降级)。

func (*AgentBuilder[C, S]) WithFewShotCoT

func (b *AgentBuilder[C, S]) WithFewShotCoT(examples []cot.CoTExample) *AgentBuilder[C, S]

WithFewShotCoT creates a few-shot Chain-of-Thought agent with examples

Example:

agent := NewAgentBuilder(llm).
  WithFewShotCoT(examples).
  Build()

func (*AgentBuilder[C, S]) WithGraphOfThought

func (b *AgentBuilder[C, S]) WithGraphOfThought(config ...got.GoTConfig) *AgentBuilder[C, S]

WithGraphOfThought creates a Graph-of-Thought agent

Example:

agent := NewAgentBuilder(llm).
  WithGraphOfThought(got.GoTConfig{
    MaxNodes: 50,
    ParallelExecution: true,
  }).
  Build()

func (*AgentBuilder[C, S]) WithMaxConversationHistory added in v0.6.0

func (b *AgentBuilder[C, S]) WithMaxConversationHistory(max int) *AgentBuilder[C, S]

WithMaxConversationHistory 设置加载的最大历史对话轮数

[Core] 标准配置,控制对话记忆的上下文窗口大小(默认 20)。 用于限制发送给 LLM 的历史对话数量,避免超出 token 限制。 设置为 0 或负数表示不限制(加载全部历史)。

注意:此设置仅在使用 WithMemory 配置了 MemoryManager 时生效。

func (*AgentBuilder[C, S]) WithMaxIterations added in v0.2.0

func (b *AgentBuilder[C, S]) WithMaxIterations(max int) *AgentBuilder[C, S]

WithMaxIterations 设置最大迭代次数

[Simple] 常用配置,控制 Agent 推理的最大步骤数(默认 10)。 推荐根据任务复杂度调整:简单任务 5-10,复杂任务 15-30。

func (*AgentBuilder[C, S]) WithMaxTokens added in v0.2.0

func (b *AgentBuilder[C, S]) WithMaxTokens(max int) *AgentBuilder[C, S]

WithMaxTokens 设置最大 token 数

[Core] 标准配置,限制 LLM 响应的最大 token 数(默认 2000)。 用于控制成本和响应长度。

func (*AgentBuilder[C, S]) WithMemory added in v0.6.0

func (b *AgentBuilder[C, S]) WithMemory(memMgr interfaces.MemoryManager) *AgentBuilder[C, S]

WithMemory 设置对话记忆管理器

MemoryManager 用于管理多轮对话的历史记录,使 Agent 能够"记住"之前的对话内容。 每次执行时,Agent 会从 MemoryManager 加载历史对话,并在执行后保存新的对话。

注意:WithStore 是键值存储,用于保存任意数据; WithMemory 是专门的对话记忆管理,用于实现多轮对话能力。

使用示例:

memMgr := memory.NewInMemoryManager(memory.DefaultConfig())
agent, err := builder.NewSimpleBuilder(llmClient).
    WithSystemPrompt("你是一个助手").
    WithMemory(memMgr).
    WithSessionID("user-session-123").
    Build()

func (*AgentBuilder[C, S]) WithMetaCoT

func (b *AgentBuilder[C, S]) WithMetaCoT(config ...metacot.MetaCoTConfig) *AgentBuilder[C, S]

WithMetaCoT creates a Meta-CoT / Self-Ask agent

Example:

agent := NewAgentBuilder(llm).
  WithMetaCoT(metacot.MetaCoTConfig{
    MaxQuestions: 5,
    SelfCritique: true,
  }).
  Build()

func (*AgentBuilder[C, S]) WithMetadata

func (b *AgentBuilder[C, S]) WithMetadata(key string, value interface{}) *AgentBuilder[C, S]

WithMetadata 添加元数据到 Agent

[Advanced] 高级配置,用于存储自定义键值对数据。

func (*AgentBuilder[C, S]) WithMiddleware

func (b *AgentBuilder[C, S]) WithMiddleware(mw ...middleware.Middleware) *AgentBuilder[C, S]

WithMiddleware 添加中间件到链中

func (*AgentBuilder[C, S]) WithMonteCarloToT

func (b *AgentBuilder[C, S]) WithMonteCarloToT() *AgentBuilder[C, S]

WithMonteCarloToT creates a Tree-of-Thought agent with Monte Carlo Tree Search

Example:

agent := NewAgentBuilder(llm).WithMonteCarloToT().Build()

func (*AgentBuilder[C, S]) WithOutputFormat added in v0.6.0

func (b *AgentBuilder[C, S]) WithOutputFormat(format OutputFormat) *AgentBuilder[C, S]

WithOutputFormat 设置 LLM 输出格式

[Simple] 常用配置,控制 LLM 响应的输出格式。 支持以下格式:

  • OutputFormatDefault: 不指定格式,由 LLM 自行决定
  • OutputFormatPlainText: 纯文本格式,不使用 Markdown 语法(适合终端显示)
  • OutputFormatMarkdown: Markdown 格式(适合富文本显示)
  • OutputFormatJSON: JSON 格式(适合程序解析)

使用示例:

agent, err := builder.NewSimpleBuilder(llmClient).
    WithSystemPrompt("你是一个助手").
    WithOutputFormat(builder.OutputFormatPlainText).
    Build()

func (*AgentBuilder[C, S]) WithProgramOfThought

func (b *AgentBuilder[C, S]) WithProgramOfThought(config ...pot.PoTConfig) *AgentBuilder[C, S]

WithProgramOfThought creates a Program-of-Thought agent

Example:

agent := NewAgentBuilder(llm).
  WithProgramOfThought(pot.PoTConfig{
    Language: "python",
    SafeMode: true,
  }).
  Build()

func (*AgentBuilder[C, S]) WithReAct

func (b *AgentBuilder[C, S]) WithReAct(config ...react.ReActConfig) *AgentBuilder[C, S]

WithReAct creates a ReAct agent (existing pattern)

Example:

agent := NewAgentBuilder(llm).
  WithReAct(react.ReActConfig{
    MaxSteps: 10,
    StopPattern: []string{"Final Answer:"},
  }).
  Build()

func (*AgentBuilder[C, S]) WithSaveInterval added in v0.2.0

func (b *AgentBuilder[C, S]) WithSaveInterval(interval time.Duration) *AgentBuilder[C, S]

WithSaveInterval 设置自动保存间隔

[Advanced] 高级配置,控制自动保存的时间间隔(默认 30 秒)。

func (*AgentBuilder[C, S]) WithSessionID added in v0.2.0

func (b *AgentBuilder[C, S]) WithSessionID(sessionID string) *AgentBuilder[C, S]

WithSessionID 设置会话 ID

[Advanced] 高级配置,用于检查点保存和会话恢复(自动生成)。

func (*AgentBuilder[C, S]) WithSkeletonOfThought

func (b *AgentBuilder[C, S]) WithSkeletonOfThought(config ...sot.SoTConfig) *AgentBuilder[C, S]

WithSkeletonOfThought creates a Skeleton-of-Thought agent

Example:

agent := NewAgentBuilder(llm).
  WithSkeletonOfThought(sot.SoTConfig{
    MaxConcurrency: 5,
    AggregationStrategy: "hierarchical",
  }).
  Build()

func (*AgentBuilder[C, S]) WithState

func (b *AgentBuilder[C, S]) WithState(state S) *AgentBuilder[C, S]

WithState 设置 Agent 状态

[Advanced] 高级配置,用于自定义状态类型(需要泛型知识)。 大多数情况下使用默认的 *core.AgentState 即可。

func (*AgentBuilder[C, S]) WithStore

func (b *AgentBuilder[C, S]) WithStore(st store.Store) *AgentBuilder[C, S]

WithStore 设置长期存储

func (*AgentBuilder[C, S]) WithStreamingEnabled added in v0.2.0

func (b *AgentBuilder[C, S]) WithStreamingEnabled(enabled bool) *AgentBuilder[C, S]

WithStreamingEnabled 设置是否启用流式响应

[Advanced] 高级配置,用于实时流式输出 LLM 响应(需要 LLM 支持)。

func (*AgentBuilder[C, S]) WithSystemPrompt

func (b *AgentBuilder[C, S]) WithSystemPrompt(prompt string) *AgentBuilder[C, S]

WithSystemPrompt 设置系统提示词

[Simple] 最常用的配置方法,定义 Agent 的角色和行为。

示例:

agent, _ := builder.NewSimpleBuilder(llm).
    WithSystemPrompt("你是一个友好的助手").
    Build()

func (*AgentBuilder[C, S]) WithTelemetry

func (b *AgentBuilder[C, S]) WithTelemetry(provider interface{}) *AgentBuilder[C, S]

WithTelemetry 添加 OpenTelemetry 支持

[Advanced] 高级配置,用于集成 OpenTelemetry 分布式追踪。

func (*AgentBuilder[C, S]) WithTemperature added in v0.2.0

func (b *AgentBuilder[C, S]) WithTemperature(temp float64) *AgentBuilder[C, S]

WithTemperature 设置温度参数(控制随机性)

[Simple] 常用配置,控制 LLM 输出的创造性(默认 0.7)。 - 0.0-0.3: 精确、确定性(适合事实查询、代码生成) - 0.4-0.7: 平衡(适合通用对话) - 0.8-1.0: 创造性(适合写作、头脑风暴)

func (*AgentBuilder[C, S]) WithTimeout added in v0.2.0

func (b *AgentBuilder[C, S]) WithTimeout(timeout time.Duration) *AgentBuilder[C, S]

WithTimeout 设置超时时间

[Core] 标准配置,防止 Agent 执行时间过长(默认 5 分钟)。

func (*AgentBuilder[C, S]) WithTools

func (b *AgentBuilder[C, S]) WithTools(tools ...interfaces.Tool) *AgentBuilder[C, S]

WithTools 添加工具到 Agent

func (*AgentBuilder[C, S]) WithTreeOfThought

func (b *AgentBuilder[C, S]) WithTreeOfThought(config ...tot.ToTConfig) *AgentBuilder[C, S]

WithTreeOfThought creates a Tree-of-Thought agent

Example:

agent := NewAgentBuilder(llm).
  WithTreeOfThought(tot.ToTConfig{
    MaxDepth: 5,
    BranchingFactor: 3,
    SearchStrategy: interfaces.StrategyBeamSearch,
  }).
  Build()

func (*AgentBuilder[C, S]) WithVerbose added in v0.2.0

func (b *AgentBuilder[C, S]) WithVerbose(verbose bool) *AgentBuilder[C, S]

WithVerbose 设置是否启用详细日志

[Core] 标准配置,用于调试和开发(默认 false)。

func (*AgentBuilder[C, S]) WithZeroShotCoT

func (b *AgentBuilder[C, S]) WithZeroShotCoT() *AgentBuilder[C, S]

WithZeroShotCoT creates a zero-shot Chain-of-Thought agent

Example:

agent := NewAgentBuilder(llm).WithZeroShotCoT().Build()

type AgentConfig

type AgentConfig struct {
	// MaxIterations 限制推理步骤的最大次数
	MaxIterations int

	// Timeout 设置 Agent 执行超时时间
	Timeout time.Duration

	// EnableStreaming 启用流式响应
	EnableStreaming bool

	// EnableAutoSave 自动保存状态
	EnableAutoSave bool

	// SaveInterval 自动保存间隔
	SaveInterval time.Duration

	// MaxTokens 限制 LLM 响应的最大 token 数
	MaxTokens int

	// Temperature 控制 LLM 采样的随机性
	Temperature float64

	// SessionID 用于检查点保存和对话记忆
	SessionID string

	// Verbose 启用详细日志
	Verbose bool

	// MaxConversationHistory 限制加载的历史对话轮数
	// 用于控制上下文窗口大小,避免超出 LLM 的 token 限制
	// 0 或负数表示不限制
	MaxConversationHistory int

	// OutputFormat 指定 LLM 输出格式
	// 支持:OutputFormatDefault(默认)、OutputFormatPlainText、OutputFormatMarkdown、OutputFormatJSON、OutputFormatCustom
	OutputFormat OutputFormat

	// CustomOutputPrompt 自定义输出格式提示词
	// 仅当 OutputFormat 为 OutputFormatCustom 时生效
	CustomOutputPrompt string
}

AgentConfig 保存 Agent 配置选项

func DefaultAgentConfig

func DefaultAgentConfig() *AgentConfig

DefaultAgentConfig 返回默认配置

type AgentOutput

type AgentOutput struct {
	Result     interface{}
	State      core.State
	Metadata   map[string]interface{}
	Duration   time.Duration
	Timestamp  time.Time
	TokenUsage *interfaces.TokenUsage
}

AgentOutput 表示 Agent 执行结果

type CoTAgentConfig added in v0.6.0

type CoTAgentConfig struct {
	Name                 string
	Description          string
	Tools                []interfaces.Tool
	MaxSteps             int
	ShowStepNumbers      bool
	RequireJustification bool
	ZeroShot             bool
	FewShot              bool
	FewShotExamples      []cot.CoTExample
}

CoTAgentConfig CoT Agent 配置选项

type ConfigurableAgent

type ConfigurableAgent[C any, S core.State] struct {
	// contains filtered or unexported fields
}

ConfigurableAgent 是具有完整配置的已构建 Agent

func (*ConfigurableAgent[C, S]) Execute

func (a *ConfigurableAgent[C, S]) Execute(ctx context.Context, input interface{}) (*AgentOutput, error)

Execute 使用给定输入运行 Agent

func (*ConfigurableAgent[C, S]) ExecuteWithTools

func (a *ConfigurableAgent[C, S]) ExecuteWithTools(ctx context.Context, input interface{}) (*AgentOutput, error)

ExecuteWithTools 使用工具执行能力运行 Agent

func (*ConfigurableAgent[C, S]) GetMetrics

func (a *ConfigurableAgent[C, S]) GetMetrics() map[string]interface{}

GetMetrics 返回 Agent 指标

func (*ConfigurableAgent[C, S]) GetState

func (a *ConfigurableAgent[C, S]) GetState() S

GetState 返回当前状态

func (*ConfigurableAgent[C, S]) Initialize

func (a *ConfigurableAgent[C, S]) Initialize(ctx context.Context) error

Initialize 准备 Agent 执行

func (*ConfigurableAgent[C, S]) Shutdown

func (a *ConfigurableAgent[C, S]) Shutdown(ctx context.Context) error

Shutdown 优雅地关闭 Agent

type ExecutorConfig added in v0.6.0

type ExecutorConfig struct {
	Tools               []interfaces.Tool
	Memory              executor.Memory
	MaxIterations       int
	MaxExecutionTime    time.Duration
	EarlyStoppingMethod string
	HandleParsingErrors bool
	ReturnIntermSteps   bool
	Verbose             bool
}

ExecutorConfig Executor 配置选项

type GoTAgentConfig added in v0.6.0

type GoTAgentConfig struct {
	Name              string
	Description       string
	Tools             []interfaces.Tool
	MaxNodes          int
	MaxEdgesPerNode   int
	ParallelExecution bool
	MergeStrategy     string
	CycleDetection    bool
	PruneThreshold    float64

	// 性能优化参数
	FastEvaluation bool          // 快速评估模式:使用启发式评分代替 LLM 评估
	NodeTimeout    time.Duration // 单节点处理超时时间

	// DeepSeek/慢速 API 优化参数
	MinimalMode     bool // 极简模式:仅使用2次LLM调用,适用于慢速API
	BatchGeneration bool // 批量生成:一次调用生成所有思考
	DirectSynthesis bool // 直接合成:跳过图执行
}

GoTAgentConfig GoT Agent 配置选项

type MetaCoTAgentConfig added in v0.6.0

type MetaCoTAgentConfig struct {
	Name                string
	Description         string
	Tools               []interfaces.Tool
	MaxQuestions        int
	MaxDepth            int
	AutoDecompose       bool
	RequireEvidence     bool
	SelfCritique        bool
	QuestionStrategy    string
	VerifyAnswers       bool
	ConfidenceThreshold float64
}

MetaCoTAgentConfig MetaCoT Agent 配置选项

type OutputFormat added in v0.6.0

type OutputFormat string

OutputFormat 定义 LLM 输出格式类型

const (
	// OutputFormatDefault 不指定格式,由 LLM 自行决定
	OutputFormatDefault OutputFormat = ""

	// OutputFormatPlainText 纯文本格式,不使用 Markdown 语法
	OutputFormatPlainText OutputFormat = "plain_text"

	// OutputFormatMarkdown Markdown 格式
	OutputFormatMarkdown OutputFormat = "markdown"

	// OutputFormatJSON JSON 格式
	OutputFormatJSON OutputFormat = "json"

	// OutputFormatCustom 自定义格式(需配合 CustomOutputPrompt 使用)
	OutputFormatCustom OutputFormat = "custom"
)

type PoTAgentConfig added in v0.6.0

type PoTAgentConfig struct {
	Name             string
	Description      string
	Tools            []interfaces.Tool
	Language         string
	AllowedLanguages []string
	MaxCodeLength    int
	ExecutionTimeout time.Duration
	SafeMode         bool
	PythonPath       string
	NodePath         string
	MaxIterations    int
}

PoTAgentConfig PoT Agent 配置选项

type ReActAgentConfig added in v0.6.0

type ReActAgentConfig struct {
	Name         string
	Description  string
	Tools        []interfaces.Tool
	MaxSteps     int
	StopPattern  []string
	PromptPrefix string
	PromptSuffix string
}

ReActAgentConfig ReAct Agent 配置选项

type SimpleAgent added in v0.6.0

type SimpleAgent = ConfigurableAgent[any, *core.AgentState]

SimpleAgent 是 ConfigurableAgent 的简化版本类型别名

使用最常见的类型参数组合,与 SimpleAgentBuilder 匹配。

func AnalysisAgent

func AnalysisAgent(llmClient llm.Client, dataSource interface{}) (*SimpleAgent, error)

AnalysisAgent 创建一个预配置的数据分析 Agent

此 Agent 优化用于:

  • 数据分析和报告生成
  • 一致的、事实性的输出
  • 结构化数据转换
  • 扩展的推理迭代

配置:

  • Temperature: 0.1 (非常低用于一致性)
  • MaxIterations: 20 (更多迭代用于复杂分析)
  • Middleware: Timing, Transform (用于结构化输出)

func ChatAgent

func ChatAgent(llmClient llm.Client, userName string) (*SimpleAgent, error)

ChatAgent 创建一个预配置的聊天机器人 Agent

func MonitoringAgent

func MonitoringAgent(llmClient llm.Client, checkInterval time.Duration) (*SimpleAgent, error)

MonitoringAgent 创建一个预配置的监控 Agent

此 Agent 优化用于:

  • 持续系统监控
  • 异常检测
  • 警报生成
  • 定期健康检查

配置:

  • 持续操作模式
  • 速率限制以防止过载
  • 缓存用于高效监控
  • 警报中间件用于通知

func QuickAgent

func QuickAgent(llmClient llm.Client, systemPrompt string) (*SimpleAgent, error)

QuickAgent 创建一个简单的 Agent,使用最小配置

func RAGAgent

func RAGAgent(llmClient llm.Client, retriever interface{}) (*SimpleAgent, error)

RAGAgent 创建一个预配置的 RAG Agent

func ResearchAgent

func ResearchAgent(llmClient llm.Client, sources []string) (*SimpleAgent, error)

ResearchAgent 创建一个预配置的研究和信息收集 Agent

此 Agent 优化用于:

  • 从多个来源收集信息
  • 研究报告生成
  • 来源综合和引用
  • 事实核查和验证

配置:

  • MaxTokens: 4000 (更大上下文用于综合报告)
  • Temperature: 0.5 (平衡创造性和准确性)
  • Middleware: ToolSelector (用于搜索/抓取), Cache

func WorkflowAgent

func WorkflowAgent(llmClient llm.Client, workflows map[string]interface{}) (*SimpleAgent, error)

WorkflowAgent 创建一个预配置的工作流编排 Agent

此 Agent 优化用于:

  • 多步骤工作流执行
  • 任务编排和协调
  • 错误处理和验证
  • 跨步骤的状态持久化

配置:

  • MaxIterations: 15 (平衡的工作流步骤)
  • EnableAutoSave: true (跨步骤持久化状态)
  • Middleware: Logging, CircuitBreaker, Validation

type SimpleAgentBuilder added in v0.6.0

type SimpleAgentBuilder = AgentBuilder[any, *core.AgentState]

SimpleAgentBuilder 是 AgentBuilder 的简化版本类型别名

使用最常见的类型参数组合:

  • Context: any (通用上下文)
  • State: *core.AgentState (标准状态实现)

这个类型别名消除了 95% 以上使用场景中的泛型复杂度。 如果需要自定义 Context 或 State,请使用原始的 NewAgentBuilder[C, S] 函数。

使用示例:

builder := builder.NewSimpleBuilder(llmClient)
agent, err := builder.
WithSystemPrompt("你是一个助手").
Build()

func NewSimpleBuilder added in v0.6.0

func NewSimpleBuilder(llmClient llm.Client) *SimpleAgentBuilder

NewSimpleBuilder 创建一个简化的 Agent 构建器

这是推荐的构建器创建方式,适用于大多数使用场景。 相比 NewAgentBuilder[any, *core.AgentState](client), 此函数无需显式指定泛型参数,使用更简洁。

参数:

  • llmClient: LLM 客户端实例

返回:

  • *SimpleAgentBuilder: 简化的构建器实例

使用示例:

client := providers.NewOpenAIClient(apiKey)
builder := builder.NewSimpleBuilder(client)
agent, err := builder.
WithSystemPrompt("你是一个助手").
WithTools(calculatorTool, searchTool).
Build()

type SoTAgentConfig added in v0.6.0

type SoTAgentConfig struct {
	Name                string
	Description         string
	Tools               []interfaces.Tool
	MaxSkeletonPoints   int
	MinSkeletonPoints   int
	MaxConcurrency      int
	ElaborationTimeout  time.Duration
	AggregationStrategy string
}

SoTAgentConfig SoT Agent 配置选项

type SupervisorAgentConfig added in v0.6.0

type SupervisorAgentConfig struct {
	MaxConcurrentAgents int
	SubAgentTimeout     time.Duration
	EnableCaching       bool
	CacheTTL            time.Duration
	EnableMetrics       bool
	RoutingStrategy     agents.RoutingStrategy
	AggregationStrategy agents.AggregationStrategy
}

SupervisorAgentConfig Supervisor Agent 配置选项

type ToTAgentConfig added in v0.6.0

type ToTAgentConfig struct {
	Name             string
	Description      string
	Tools            []interfaces.Tool
	MaxDepth         int
	BranchingFactor  int
	BeamWidth        int
	SearchStrategy   interfaces.ReasoningStrategy
	EvaluationMethod string
	PruneThreshold   float64
}

ToTAgentConfig ToT Agent 配置选项

type ToolCall

type ToolCall struct {
	Name  string
	Input map[string]interface{}
}

ToolCall 表示工具调用请求

Jump to

Keyboard shortcuts

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