Documentation
¶
Index ¶
- type AgentBuilder
- func (b *AgentBuilder[C, S]) Build() (*ConfigurableAgent[C, S], error)
- func (b *AgentBuilder[C, S]) BuildReasoningAgent() core.Agent
- func (b *AgentBuilder[C, S]) ConfigureForAnalysis() *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) ConfigureForChatbot() *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) ConfigureForRAG() *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithAutoSaveEnabled(enabled bool) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithBeamSearchToT(beamWidth, maxDepth int) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithCallbacks(callbacks ...core.Callback) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithChainOfThought(config ...cot.CoTConfig) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithCheckpointer(checkpointer checkpoint.Checkpointer) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithCommunicator(communicator interface{}) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithContext(context C) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithErrorHandler(handler func(error) error) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithFewShotCoT(examples []cot.CoTExample) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithGraphOfThought(config ...got.GoTConfig) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithMaxIterations(max int) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithMaxTokens(max int) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithMetaCoT(config ...metacot.MetaCoTConfig) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithMetadata(key string, value interface{}) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithMiddleware(mw ...middleware.Middleware) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithMonteCarloToT() *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithProgramOfThought(config ...pot.PoTConfig) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithReAct(config ...react.ReActConfig) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithSaveInterval(interval time.Duration) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithSessionID(sessionID string) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithSkeletonOfThought(config ...sot.SoTConfig) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithState(state S) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithStore(st store.Store) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithStreamingEnabled(enabled bool) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithSystemPrompt(prompt string) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithTelemetry(provider interface{}) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithTemperature(temp float64) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithTimeout(timeout time.Duration) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithTools(tools ...interfaces.Tool) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithTreeOfThought(config ...tot.ToTConfig) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithVerbose(verbose bool) *AgentBuilder[C, S]
- func (b *AgentBuilder[C, S]) WithZeroShotCoT() *AgentBuilder[C, S]
- type AgentConfig
- type AgentOutput
- type ConfigurableAgent
- func AnalysisAgent(llmClient llm.Client, dataSource interface{}) (*ConfigurableAgent[any, *core.AgentState], error)
- func ChatAgent(llmClient llm.Client, userName string) (*ConfigurableAgent[any, *core.AgentState], error)
- func MonitoringAgent(llmClient llm.Client, checkInterval time.Duration) (*ConfigurableAgent[any, *core.AgentState], error)
- func QuickAgent(llmClient llm.Client, systemPrompt string) (*ConfigurableAgent[any, *core.AgentState], error)
- func RAGAgent(llmClient llm.Client, retriever interface{}) (*ConfigurableAgent[any, *core.AgentState], error)
- func ResearchAgent(llmClient llm.Client, sources []string) (*ConfigurableAgent[any, *core.AgentState], error)
- func WorkflowAgent(llmClient llm.Client, workflows map[string]interface{}) (*ConfigurableAgent[any, *core.AgentState], error)
- func (a *ConfigurableAgent[C, S]) Execute(ctx context.Context, input interface{}) (*AgentOutput, error)
- func (a *ConfigurableAgent[C, S]) ExecuteWithTools(ctx context.Context, input interface{}) (*AgentOutput, error)
- func (a *ConfigurableAgent[C, S]) GetMetrics() map[string]interface{}
- func (a *ConfigurableAgent[C, S]) GetState() S
- func (a *ConfigurableAgent[C, S]) Initialize(ctx context.Context) error
- func (a *ConfigurableAgent[C, S]) Shutdown(ctx context.Context) error
- type ToolCall
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentBuilder ¶
AgentBuilder 提供用于构建 Agent 的 fluent API
受 LangChain 的 create_agent 函数启发,它集成了:
- LLM 客户端配置
- 工具注册
- 状态管理
- 运行时上下文
- Store 和 Checkpointer
- 中间件栈
- 系统提示词
func NewAgentBuilder ¶
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 设置是否启用自动保存
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 添加回调函数用于监控
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 添加通信器
func (*AgentBuilder[C, S]) WithContext ¶
func (b *AgentBuilder[C, S]) WithContext(context C) *AgentBuilder[C, S]
WithContext 设置应用上下文
func (*AgentBuilder[C, S]) WithErrorHandler ¶
func (b *AgentBuilder[C, S]) WithErrorHandler(handler func(error) error) *AgentBuilder[C, S]
WithErrorHandler 设置自定义错误处理函数
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]) WithMaxIterations ¶ added in v0.2.0
func (b *AgentBuilder[C, S]) WithMaxIterations(max int) *AgentBuilder[C, S]
WithMaxIterations 设置最大迭代次数
func (*AgentBuilder[C, S]) WithMaxTokens ¶ added in v0.2.0
func (b *AgentBuilder[C, S]) WithMaxTokens(max int) *AgentBuilder[C, S]
WithMaxTokens 设置最大 token 数
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
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]) 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 设置自动保存间隔
func (*AgentBuilder[C, S]) WithSessionID ¶ added in v0.2.0
func (b *AgentBuilder[C, S]) WithSessionID(sessionID string) *AgentBuilder[C, S]
WithSessionID 设置会话 ID
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 状态
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 设置是否启用流式响应
func (*AgentBuilder[C, S]) WithSystemPrompt ¶
func (b *AgentBuilder[C, S]) WithSystemPrompt(prompt string) *AgentBuilder[C, S]
WithSystemPrompt 设置系统提示词
func (*AgentBuilder[C, S]) WithTelemetry ¶
func (b *AgentBuilder[C, S]) WithTelemetry(provider interface{}) *AgentBuilder[C, S]
WithTelemetry 添加 OpenTelemetry 支持
func (*AgentBuilder[C, S]) WithTemperature ¶ added in v0.2.0
func (b *AgentBuilder[C, S]) WithTemperature(temp float64) *AgentBuilder[C, S]
WithTemperature 设置温度参数(控制随机性)
func (*AgentBuilder[C, S]) WithTimeout ¶ added in v0.2.0
func (b *AgentBuilder[C, S]) WithTimeout(timeout time.Duration) *AgentBuilder[C, S]
WithTimeout 设置超时时间
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 设置是否启用详细日志
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
}
AgentConfig 保存 Agent 配置选项
type AgentOutput ¶
type AgentOutput struct {
Result interface{}
State core.State
Metadata map[string]interface{}
Duration time.Duration
Timestamp time.Time
}
AgentOutput 表示 Agent 执行结果
type ConfigurableAgent ¶
ConfigurableAgent 是具有完整配置的已构建 Agent
func AnalysisAgent ¶
func AnalysisAgent(llmClient llm.Client, dataSource interface{}) (*ConfigurableAgent[any, *core.AgentState], error)
AnalysisAgent 创建一个预配置的数据分析 Agent
此 Agent 优化用于:
- 数据分析和报告生成
- 一致的、事实性的输出
- 结构化数据转换
- 扩展的推理迭代
配置:
- Temperature: 0.1 (非常低用于一致性)
- MaxIterations: 20 (更多迭代用于复杂分析)
- Middleware: Timing, Transform (用于结构化输出)
func ChatAgent ¶
func ChatAgent(llmClient llm.Client, userName string) (*ConfigurableAgent[any, *core.AgentState], error)
ChatAgent 创建一个预配置的聊天机器人 Agent
func MonitoringAgent ¶
func MonitoringAgent(llmClient llm.Client, checkInterval time.Duration) (*ConfigurableAgent[any, *core.AgentState], error)
MonitoringAgent 创建一个预配置的监控 Agent
此 Agent 优化用于:
- 持续系统监控
- 异常检测
- 警报生成
- 定期健康检查
配置:
- 持续操作模式
- 速率限制以防止过载
- 缓存用于高效监控
- 警报中间件用于通知
func QuickAgent ¶
func QuickAgent(llmClient llm.Client, systemPrompt string) (*ConfigurableAgent[any, *core.AgentState], error)
QuickAgent 创建一个简单的 Agent,使用最小配置
func RAGAgent ¶
func RAGAgent(llmClient llm.Client, retriever interface{}) (*ConfigurableAgent[any, *core.AgentState], error)
RAGAgent 创建一个预配置的 RAG Agent
func ResearchAgent ¶
func ResearchAgent(llmClient llm.Client, sources []string) (*ConfigurableAgent[any, *core.AgentState], error)
ResearchAgent 创建一个预配置的研究和信息收集 Agent
此 Agent 优化用于:
- 从多个来源收集信息
- 研究报告生成
- 来源综合和引用
- 事实核查和验证
配置:
- MaxTokens: 4000 (更大上下文用于综合报告)
- Temperature: 0.5 (平衡创造性和准确性)
- Middleware: ToolSelector (用于搜索/抓取), Cache
func WorkflowAgent ¶
func WorkflowAgent(llmClient llm.Client, workflows map[string]interface{}) (*ConfigurableAgent[any, *core.AgentState], error)
WorkflowAgent 创建一个预配置的工作流编排 Agent
此 Agent 优化用于:
- 多步骤工作流执行
- 任务编排和协调
- 错误处理和验证
- 跨步骤的状态持久化
配置:
- MaxIterations: 15 (平衡的工作流步骤)
- EnableAutoSave: true (跨步骤持久化状态)
- Middleware: Logging, CircuitBreaker, Validation
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 执行