Documentation
¶
Index ¶
- Constants
- type Agent
- type AgentEngine
- func (ae *AgentEngine) AddTool(ctx context.Context, tool types.Tool)
- func (ae *AgentEngine) AddTools(ctx context.Context, tools []types.Tool)
- func (ae *AgentEngine) Execute(ctx context.Context, input string, previousRequests []types.ToolCallData) (*AgentResult, error)
- func (ae *AgentEngine) ExecuteStream(ctx context.Context, input string, previousRequests []types.ToolCallData) (<-chan StreamResult, error)
- func (ae *AgentEngine) SetConfig(ctx context.Context, config *types.AgentConfig)
- func (ae *AgentEngine) SetEnableToolRetry(ctx context.Context, enable bool)
- func (ae *AgentEngine) SetFrequencyPenalty(ctx context.Context, penalty float32)
- func (ae *AgentEngine) SetMaxTokens(ctx context.Context, maxTokens int)
- func (ae *AgentEngine) SetMemory(ctx context.Context, memory types.MemoryProvider)
- func (ae *AgentEngine) SetOutputParser(ctx context.Context, parser types.OutputParser)
- func (ae *AgentEngine) SetPresencePenalty(ctx context.Context, penalty float32)
- func (ae *AgentEngine) SetRateLimiter(ctx context.Context, limiter ratelimit.RateLimiter)
- func (ae *AgentEngine) SetRetryAttempts(ctx context.Context, attempts int)
- func (ae *AgentEngine) SetRetryDelay(ctx context.Context, delay time.Duration)
- func (ae *AgentEngine) SetStopSequences(ctx context.Context, sequences []string)
- func (ae *AgentEngine) SetTemperature(ctx context.Context, temperature float32)
- func (ae *AgentEngine) SetTimeout(ctx context.Context, timeout time.Duration)
- func (ae *AgentEngine) SetTopP(ctx context.Context, topP float32)
- func (ae *AgentEngine) Stop(ctx context.Context)
- type AgentResult
- type LangChainAgentEngine
- func (e *LangChainAgentEngine) AddTool(ctx context.Context, tool types.Tool)
- func (e *LangChainAgentEngine) AddTools(ctx context.Context, tools []types.Tool)
- func (e *LangChainAgentEngine) BuildAgent() error
- func (e *LangChainAgentEngine) ClearMemory()
- func (e *LangChainAgentEngine) Execute(ctx context.Context, input string, previousRequests []types.ToolCallData) (*AgentResult, error)
- func (e *LangChainAgentEngine) ExecuteSimple(ctx context.Context, input string) (string, error)
- func (e *LangChainAgentEngine) ExecuteStream(ctx context.Context, input string, previousRequests []types.ToolCallData) (<-chan StreamResult, error)
- func (e *LangChainAgentEngine) ExecuteStreamSimple(ctx context.Context, input string) (<-chan string, error)
- func (e *LangChainAgentEngine) GetMemory() []types.Message
- func (e *LangChainAgentEngine) SetConfig(ctx context.Context, config *types.AgentConfig)
- func (e *LangChainAgentEngine) SetEnableToolRetry(ctx context.Context, enable bool)
- func (e *LangChainAgentEngine) SetFrequencyPenalty(ctx context.Context, penalty float32)
- func (e *LangChainAgentEngine) SetMaxTokens(ctx context.Context, maxTokens int)
- func (e *LangChainAgentEngine) SetMemory(ctx context.Context, memory types.MemoryProvider)
- func (e *LangChainAgentEngine) SetOutputParser(ctx context.Context, parser types.OutputParser)
- func (e *LangChainAgentEngine) SetPresencePenalty(ctx context.Context, penalty float32)
- func (e *LangChainAgentEngine) SetRateLimiter(ctx context.Context, limiter ratelimit.RateLimiter)
- func (e *LangChainAgentEngine) SetRetryAttempts(ctx context.Context, attempts int)
- func (e *LangChainAgentEngine) SetRetryDelay(ctx context.Context, delay time.Duration)
- func (e *LangChainAgentEngine) SetStopSequences(ctx context.Context, sequences []string)
- func (e *LangChainAgentEngine) SetTemperature(ctx context.Context, temperature float32)
- func (e *LangChainAgentEngine) SetTimeout(ctx context.Context, timeout time.Duration)
- func (e *LangChainAgentEngine) SetTools(tools []types.Tool)
- func (e *LangChainAgentEngine) SetTopP(ctx context.Context, topP float32)
- func (e *LangChainAgentEngine) Stop(ctx context.Context)
- type StreamResult
Constants ¶
const ( // Cache-related constants DefaultCacheSize = 100 // default tool cache size CacheExpirationTime = 5 * time.Minute // cache expiration time // Execution-related constants DefaultChannelBuffer = 50 // default channel buffer size MaxTruncationLength = 2048 // maximum truncation length MinChannelBuffer = 10 // minimum channel buffer size // Performance-related constants DefaultBufferPoolSize = 1024 // default buffer pool size (1KB) IterationDelay = 100 * time.Millisecond // inter-iteration delay )
Constant definitions
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent interface {
// Configuration setting methods
SetMemory(ctx context.Context, memory types.MemoryProvider)
SetOutputParser(ctx context.Context, parser types.OutputParser)
SetTemperature(ctx context.Context, temperature float32)
SetMaxTokens(ctx context.Context, maxTokens int)
SetTopP(ctx context.Context, topP float32)
SetFrequencyPenalty(ctx context.Context, penalty float32)
SetPresencePenalty(ctx context.Context, penalty float32)
SetStopSequences(ctx context.Context, sequences []string)
SetTimeout(ctx context.Context, timeout time.Duration)
SetRetryAttempts(ctx context.Context, attempts int)
SetRetryDelay(ctx context.Context, delay time.Duration)
SetEnableToolRetry(ctx context.Context, enable bool)
SetConfig(ctx context.Context, config *types.AgentConfig)
SetRateLimiter(ctx context.Context, limiter ratelimit.RateLimiter)
// Tool management methods
AddTool(ctx context.Context, tool types.Tool)
AddTools(ctx context.Context, tools []types.Tool)
// Execution methods
Execute(ctx context.Context, input string, previousRequests []types.ToolCallData) (*AgentResult, error)
ExecuteStream(ctx context.Context, input string, previousRequests []types.ToolCallData) (<-chan StreamResult, error)
// Lifecycle management
Stop(ctx context.Context)
}
Agent agent engine interface
func NewAgent ¶
func NewAgent(model types.LLMProvider, config *types.AgentConfig) Agent
NewAgent creates a new agent instance (via interface)
func NewLangChainAgent ¶
func NewLangChainAgent(llm types.LLMProvider, systemPrompt string) Agent
NewLangChainAgent creates a new LangChain agent instance (via interface)
type AgentEngine ¶
type AgentEngine struct {
// contains filtered or unexported fields
}
AgentEngine agent engine Provides intelligent agent functionality with tool calling, streaming, caching, and memory systems
func NewAgentEngine ¶
func NewAgentEngine(model types.LLMProvider, config *types.AgentConfig) *AgentEngine
NewAgentEngine creates a new agent engine Parameters:
- model: LLM model provider
- config: agent configuration (if nil, uses default configuration)
Returns:
- initialized AgentEngine instance
func (*AgentEngine) AddTool ¶
func (ae *AgentEngine) AddTool(ctx context.Context, tool types.Tool)
AddTool adds a tool
func (*AgentEngine) AddTools ¶
func (ae *AgentEngine) AddTools(ctx context.Context, tools []types.Tool)
AddTools adds multiple tools
func (*AgentEngine) Execute ¶
func (ae *AgentEngine) Execute(ctx context.Context, input string, previousRequests []types.ToolCallData) (*AgentResult, error)
Execute executes the agent task (supports multi-round iteration) Processes user input with tool calling and multi-round iteration, returning the complete execution result Parameters:
- ctx: context for cancellation
- input: user input text
- previousRequests: previous tool call request history
Returns:
- execution result containing output, tool calls, and intermediate steps
- error information
func (*AgentEngine) ExecuteStream ¶
func (ae *AgentEngine) ExecuteStream(ctx context.Context, input string, previousRequests []types.ToolCallData) (<-chan StreamResult, error)
ExecuteStream executes the agent task with streaming (supports multi-round iteration) Processes user input with real-time streaming output and multi-round tool calling Parameters:
- ctx: context for cancellation
- input: user input text
- previousRequests: previous tool call request history
Returns:
- streaming result channel for real-time content delivery during execution
- error information (only during initialization)
func (*AgentEngine) SetConfig ¶
func (ae *AgentEngine) SetConfig(ctx context.Context, config *types.AgentConfig)
SetConfig sets the complete configuration
func (*AgentEngine) SetEnableToolRetry ¶
func (ae *AgentEngine) SetEnableToolRetry(ctx context.Context, enable bool)
SetEnableToolRetry sets whether to enable tool retry
func (*AgentEngine) SetFrequencyPenalty ¶
func (ae *AgentEngine) SetFrequencyPenalty(ctx context.Context, penalty float32)
SetFrequencyPenalty sets frequency penalty
func (*AgentEngine) SetMaxTokens ¶
func (ae *AgentEngine) SetMaxTokens(ctx context.Context, maxTokens int)
SetMaxTokens sets the maximum tokens
func (*AgentEngine) SetMemory ¶
func (ae *AgentEngine) SetMemory(ctx context.Context, memory types.MemoryProvider)
SetMemory sets the memory system
func (*AgentEngine) SetOutputParser ¶
func (ae *AgentEngine) SetOutputParser(ctx context.Context, parser types.OutputParser)
SetOutputParser sets the output parser
func (*AgentEngine) SetPresencePenalty ¶
func (ae *AgentEngine) SetPresencePenalty(ctx context.Context, penalty float32)
SetPresencePenalty sets presence penalty
func (*AgentEngine) SetRateLimiter ¶ added in v1.4.7
func (ae *AgentEngine) SetRateLimiter(ctx context.Context, limiter ratelimit.RateLimiter)
SetRateLimiter sets the rate limiter
func (*AgentEngine) SetRetryAttempts ¶
func (ae *AgentEngine) SetRetryAttempts(ctx context.Context, attempts int)
SetRetryAttempts sets retry attempts
func (*AgentEngine) SetRetryDelay ¶
func (ae *AgentEngine) SetRetryDelay(ctx context.Context, delay time.Duration)
SetRetryDelay sets retry delay
func (*AgentEngine) SetStopSequences ¶
func (ae *AgentEngine) SetStopSequences(ctx context.Context, sequences []string)
SetStopSequences sets stop sequences
func (*AgentEngine) SetTemperature ¶
func (ae *AgentEngine) SetTemperature(ctx context.Context, temperature float32)
SetTemperature sets the temperature parameter
func (*AgentEngine) SetTimeout ¶
func (ae *AgentEngine) SetTimeout(ctx context.Context, timeout time.Duration)
SetTimeout sets timeout duration
func (*AgentEngine) SetTopP ¶
func (ae *AgentEngine) SetTopP(ctx context.Context, topP float32)
SetTopP sets Top P sampling
func (*AgentEngine) Stop ¶
func (ae *AgentEngine) Stop(ctx context.Context)
Stop stops the agent engine Safely stops the agent engine and releases resources
type AgentResult ¶
type AgentResult struct {
Output string `json:"output"`
ToolCalls []types.ToolCallRequest `json:"tool_calls"`
IntermediateSteps []types.ToolCallData `json:"intermediate_steps"`
}
AgentResult agent execution result
type LangChainAgentEngine ¶
type LangChainAgentEngine struct {
// contains filtered or unexported fields
}
LangChainAgentEngine LangChain agent engine
func NewLangChainAgentEngine ¶
func NewLangChainAgentEngine(llm types.LLMProvider, systemPrompt string) *LangChainAgentEngine
NewLangChainAgentEngine creates a new LangChain agent engine
func (*LangChainAgentEngine) AddTool ¶
func (e *LangChainAgentEngine) AddTool(ctx context.Context, tool types.Tool)
AddTool adds a tool
func (*LangChainAgentEngine) AddTools ¶
func (e *LangChainAgentEngine) AddTools(ctx context.Context, tools []types.Tool)
AddTools adds tools in batch
func (*LangChainAgentEngine) BuildAgent ¶
func (e *LangChainAgentEngine) BuildAgent() error
BuildAgent builds the agent (simplified version)
func (*LangChainAgentEngine) ClearMemory ¶
func (e *LangChainAgentEngine) ClearMemory()
ClearMemory clears memory
func (*LangChainAgentEngine) Execute ¶
func (e *LangChainAgentEngine) Execute(ctx context.Context, input string, previousRequests []types.ToolCallData) (*AgentResult, error)
Execute executes the agent (implements Agent interface)
func (*LangChainAgentEngine) ExecuteSimple ¶
ExecuteSimple simple execution method (for backward compatibility)
func (*LangChainAgentEngine) ExecuteStream ¶
func (e *LangChainAgentEngine) ExecuteStream(ctx context.Context, input string, previousRequests []types.ToolCallData) (<-chan StreamResult, error)
ExecuteStream streams agent execution (implements Agent interface)
func (*LangChainAgentEngine) ExecuteStreamSimple ¶
func (e *LangChainAgentEngine) ExecuteStreamSimple(ctx context.Context, input string) (<-chan string, error)
ExecuteStreamSimple simple streaming execution (for backward compatibility)
func (*LangChainAgentEngine) GetMemory ¶
func (e *LangChainAgentEngine) GetMemory() []types.Message
GetMemory gets memory
func (*LangChainAgentEngine) SetConfig ¶
func (e *LangChainAgentEngine) SetConfig(ctx context.Context, config *types.AgentConfig)
SetConfig sets complete configuration
func (*LangChainAgentEngine) SetEnableToolRetry ¶
func (e *LangChainAgentEngine) SetEnableToolRetry(ctx context.Context, enable bool)
SetEnableToolRetry sets whether to enable tool retry
func (*LangChainAgentEngine) SetFrequencyPenalty ¶
func (e *LangChainAgentEngine) SetFrequencyPenalty(ctx context.Context, penalty float32)
SetFrequencyPenalty sets frequency penalty
func (*LangChainAgentEngine) SetMaxTokens ¶
func (e *LangChainAgentEngine) SetMaxTokens(ctx context.Context, maxTokens int)
SetMaxTokens sets maximum tokens
func (*LangChainAgentEngine) SetMemory ¶
func (e *LangChainAgentEngine) SetMemory(ctx context.Context, memory types.MemoryProvider)
SetMemory sets memory system (LangChain engine uses internal memory management)
func (*LangChainAgentEngine) SetOutputParser ¶
func (e *LangChainAgentEngine) SetOutputParser(ctx context.Context, parser types.OutputParser)
SetOutputParser sets output parser
func (*LangChainAgentEngine) SetPresencePenalty ¶
func (e *LangChainAgentEngine) SetPresencePenalty(ctx context.Context, penalty float32)
SetPresencePenalty sets presence penalty
func (*LangChainAgentEngine) SetRateLimiter ¶ added in v1.4.7
func (e *LangChainAgentEngine) SetRateLimiter(ctx context.Context, limiter ratelimit.RateLimiter)
SetRateLimiter sets the rate limiter (not implemented for LangChain engine)
func (*LangChainAgentEngine) SetRetryAttempts ¶
func (e *LangChainAgentEngine) SetRetryAttempts(ctx context.Context, attempts int)
SetRetryAttempts sets retry attempts
func (*LangChainAgentEngine) SetRetryDelay ¶
func (e *LangChainAgentEngine) SetRetryDelay(ctx context.Context, delay time.Duration)
SetRetryDelay sets retry delay
func (*LangChainAgentEngine) SetStopSequences ¶
func (e *LangChainAgentEngine) SetStopSequences(ctx context.Context, sequences []string)
SetStopSequences sets stop sequences
func (*LangChainAgentEngine) SetTemperature ¶
func (e *LangChainAgentEngine) SetTemperature(ctx context.Context, temperature float32)
SetTemperature sets temperature parameter
func (*LangChainAgentEngine) SetTimeout ¶
func (e *LangChainAgentEngine) SetTimeout(ctx context.Context, timeout time.Duration)
SetTimeout sets timeout duration
func (*LangChainAgentEngine) SetTools ¶
func (e *LangChainAgentEngine) SetTools(tools []types.Tool)
SetTools sets tools
func (*LangChainAgentEngine) SetTopP ¶
func (e *LangChainAgentEngine) SetTopP(ctx context.Context, topP float32)
SetTopP sets Top P sampling
func (*LangChainAgentEngine) Stop ¶
func (e *LangChainAgentEngine) Stop(ctx context.Context)
Stop stops the agent engine (LangChain engine requires no special stop operation)
type StreamResult ¶
type StreamResult struct {
Type string
Content string
Result *AgentResult
Error error
}
StreamResult streaming result