Documentation
¶
Index ¶
- 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 types.AgentInput, ...) (*types.AgentResult, error)
- func (ae *AgentEngine) ExecuteStream(ctx context.Context, input types.AgentInput, ...) (<-chan types.StreamResult, error)
- func (ae *AgentEngine) GetMemory() types.MemoryProvider
- func (ae *AgentEngine) GetTotalUsage() types.Usage
- 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) SetHooks(ctx context.Context, h hooks.Hooks)
- 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 utils.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) SetToolCallback(ctx context.Context, callback types.ToolCallback)
- func (ae *AgentEngine) SetTopP(ctx context.Context, topP float32)
- func (ae *AgentEngine) Stop(ctx context.Context)
- 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 types.AgentInput, ...) (*types.AgentResult, error)
- func (e *LangChainAgentEngine) ExecuteSimple(ctx context.Context, input types.AgentInput) (string, error)
- func (e *LangChainAgentEngine) ExecuteStream(ctx context.Context, input types.AgentInput, ...) (<-chan types.StreamResult, error)
- func (e *LangChainAgentEngine) ExecuteStreamSimple(ctx context.Context, input types.AgentInput) (<-chan string, error)
- func (e *LangChainAgentEngine) GetMemory() []types.Message
- func (e *LangChainAgentEngine) GetTotalUsage() types.Usage
- 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) SetHooks(ctx context.Context, h hooks.Hooks)
- 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 utils.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) SetToolCallback(ctx context.Context, callback types.ToolCallback)
- func (e *LangChainAgentEngine) SetTools(tools []types.Tool)
- func (e *LangChainAgentEngine) SetTopP(ctx context.Context, topP float32)
- func (e *LangChainAgentEngine) Stop(ctx context.Context)
- type ResultSender
Constants ¶
This section is empty.
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 utils.RateLimiter)
SetToolCallback(ctx context.Context, callback types.ToolCallback)
SetHooks(ctx context.Context, h hooks.Hooks)
// Tool management methods
AddTool(ctx context.Context, tool types.Tool)
AddTools(ctx context.Context, tools []types.Tool)
// Execution methods
Execute(ctx context.Context, input types.AgentInput, previousRequests []types.ToolCallData) (*types.AgentResult, error)
ExecuteStream(ctx context.Context, input types.AgentInput, previousRequests []types.ToolCallData) (<-chan types.StreamResult, error)
// Lifecycle management
Stop(ctx context.Context)
// Usage tracking
GetTotalUsage() types.Usage
}
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 types.AgentInput, previousRequests []types.ToolCallData) (*types.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
- 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 types.AgentInput, previousRequests []types.ToolCallData) (<-chan types.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
- previousRequests: previous tool call request history
Returns:
- streaming result channel for real-time content delivery during execution
- error information (only during initialization)
func (*AgentEngine) GetMemory ¶ added in v1.8.1
func (ae *AgentEngine) GetMemory() types.MemoryProvider
GetMemory returns the memory provider
func (*AgentEngine) GetTotalUsage ¶ added in v1.6.10
func (ae *AgentEngine) GetTotalUsage() types.Usage
GetTotalUsage gets the total token usage
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) SetHooks ¶ added in v1.7.3
func (ae *AgentEngine) SetHooks(ctx context.Context, h hooks.Hooks)
SetHooks sets the hooks for lifecycle events
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 utils.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) SetToolCallback ¶ added in v1.7.3
func (ae *AgentEngine) SetToolCallback(ctx context.Context, callback types.ToolCallback)
SetToolCallback sets the tool callback for real-time tool execution events
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 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 types.AgentInput, previousRequests []types.ToolCallData) (*types.AgentResult, error)
Execute executes the agent (implements Agent interface)
func (*LangChainAgentEngine) ExecuteSimple ¶
func (e *LangChainAgentEngine) ExecuteSimple(ctx context.Context, input types.AgentInput) (string, error)
ExecuteSimple simple execution method (for backward compatibility)
func (*LangChainAgentEngine) ExecuteStream ¶
func (e *LangChainAgentEngine) ExecuteStream(ctx context.Context, input types.AgentInput, previousRequests []types.ToolCallData) (<-chan types.StreamResult, error)
ExecuteStream streams agent execution (implements Agent interface)
func (*LangChainAgentEngine) ExecuteStreamSimple ¶
func (e *LangChainAgentEngine) ExecuteStreamSimple(ctx context.Context, input types.AgentInput) (<-chan string, error)
ExecuteStreamSimple simple streaming execution (for backward compatibility)
func (*LangChainAgentEngine) GetMemory ¶
func (e *LangChainAgentEngine) GetMemory() []types.Message
GetMemory gets memory
func (*LangChainAgentEngine) GetTotalUsage ¶ added in v1.6.10
func (e *LangChainAgentEngine) GetTotalUsage() types.Usage
GetTotalUsage gets total token usage
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) SetHooks ¶ added in v1.7.3
func (e *LangChainAgentEngine) SetHooks(ctx context.Context, h hooks.Hooks)
SetHooks sets the hooks (not implemented for LangChain engine)
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 utils.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) SetToolCallback ¶ added in v1.7.3
func (e *LangChainAgentEngine) SetToolCallback(ctx context.Context, callback types.ToolCallback)
SetToolCallback sets the tool callback (not implemented for LangChain engine)
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 ResultSender ¶ added in v1.7.3
type ResultSender func(types.StreamResult)
ResultSender is a function type for sending stream results