builder

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentBuilder

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

AgentBuilder provides a fluent API for building agents with all features

Inspired by LangChain's create_agent function, it integrates:

  • LLM client configuration
  • Tools registration
  • State management
  • Runtime context
  • Store and Checkpointer
  • Middleware stack
  • System prompts

func NewAgentBuilder

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

NewAgentBuilder creates a new agent builder

func (*AgentBuilder[C, S]) Build

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

Build constructs the final 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 adds components for data analysis tasks

func (*AgentBuilder[C, S]) ConfigureForChatbot

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

ConfigureForChatbot adds common chatbot components

func (*AgentBuilder[C, S]) ConfigureForRAG

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

ConfigureForRAG adds common RAG (Retrieval-Augmented Generation) components

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 adds callbacks for monitoring

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 sets the session checkpointer

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 sets the application context

func (*AgentBuilder[C, S]) WithErrorHandler

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

WithErrorHandler sets custom error handling

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 adds metadata to the agent

func (*AgentBuilder[C, S]) WithMiddleware

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

WithMiddleware adds middleware to the chain

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 sets the agent state

func (*AgentBuilder[C, S]) WithStore

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

WithStore sets the long-term storage

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 sets the system prompt

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 adds tools to the 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 limits the number of reasoning steps
	MaxIterations int

	// Timeout for agent execution
	Timeout time.Duration

	// EnableStreaming enables streaming responses
	EnableStreaming bool

	// EnableAutoSave automatically saves state after each step
	EnableAutoSave bool

	// SaveInterval for auto-save
	SaveInterval time.Duration

	// MaxTokens limits LLM response tokens
	MaxTokens int

	// Temperature for LLM sampling
	Temperature float64

	// SessionID for checkpointing
	SessionID string

	// Verbose enables detailed logging
	Verbose bool
}

AgentConfig holds agent configuration options

func DefaultAgentConfig

func DefaultAgentConfig() *AgentConfig

DefaultAgentConfig returns default configuration

type AgentOutput

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

AgentOutput represents the agent execution result

type ConfigurableAgent

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

ConfigurableAgent is the built agent with full configuration

func AnalysisAgent

func AnalysisAgent(llmClient llm.Client, dataSource interface{}) (*ConfigurableAgent[any, *core.AgentState], error)

AnalysisAgent creates a pre-configured data analysis agent

This agent is optimized for:

  • Data analysis and report generation
  • Consistent, factual outputs
  • Structured data transformations
  • Extended reasoning iterations

Configuration:

  • Temperature: 0.1 (very low for consistency)
  • MaxIterations: 20 (more iterations for complex analysis)
  • Middleware: Timing, Transform (for structured output)

func ChatAgent

func ChatAgent(llmClient llm.Client, userName string) (*ConfigurableAgent[any, *core.AgentState], error)

ChatAgent creates a pre-configured chatbot agent

func MonitoringAgent

func MonitoringAgent(llmClient llm.Client, checkInterval time.Duration) (*ConfigurableAgent[any, *core.AgentState], error)

MonitoringAgent creates a pre-configured monitoring agent

This agent is optimized for:

  • Continuous system monitoring
  • Anomaly detection
  • Alert generation
  • Periodic health checks

Configuration:

  • Continuous operation mode
  • Rate limiting to prevent overwhelming
  • Caching for efficient monitoring
  • Alert middleware for notifications

func QuickAgent

func QuickAgent(llmClient llm.Client, systemPrompt string) (*ConfigurableAgent[any, *core.AgentState], error)

QuickAgent creates a simple agent with minimal configuration

func RAGAgent

func RAGAgent(llmClient llm.Client, retriever interface{}) (*ConfigurableAgent[any, *core.AgentState], error)

RAGAgent creates a pre-configured RAG agent

func ResearchAgent

func ResearchAgent(llmClient llm.Client, sources []string) (*ConfigurableAgent[any, *core.AgentState], error)

ResearchAgent creates a pre-configured research and information gathering agent

This agent is optimized for:

  • Information collection from multiple sources
  • Research report generation
  • Source synthesis and citation
  • Fact-checking and verification

Configuration:

  • MaxTokens: 4000 (larger context for comprehensive reports)
  • Temperature: 0.5 (balanced for creativity and accuracy)
  • Middleware: ToolSelector (for search/scrape), Cache

func WorkflowAgent

func WorkflowAgent(llmClient llm.Client, workflows map[string]interface{}) (*ConfigurableAgent[any, *core.AgentState], error)

WorkflowAgent creates a pre-configured workflow orchestration agent

This agent is optimized for:

  • Multi-step workflow execution
  • Task orchestration and coordination
  • Error handling and validation
  • State persistence across steps

Configuration:

  • MaxIterations: 15 (balanced for workflow steps)
  • EnableAutoSave: true (persist state across steps)
  • Middleware: Logging, CircuitBreaker, Validation

func (*ConfigurableAgent[C, S]) Execute

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

Execute runs the agent with the given input

func (*ConfigurableAgent[C, S]) ExecuteWithTools

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

ExecuteWithTools runs the agent with tool execution capability

func (*ConfigurableAgent[C, S]) GetMetrics

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

GetMetrics returns agent metrics

func (*ConfigurableAgent[C, S]) GetState

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

GetState returns the current state

func (*ConfigurableAgent[C, S]) Initialize

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

Initialize prepares the agent for execution

func (*ConfigurableAgent[C, S]) Shutdown

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

Shutdown gracefully shuts down the agent

type ToolCall

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

ToolCall represents a tool invocation request

Jump to

Keyboard shortcuts

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