engine

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

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) GetCompactionOptions added in v1.10.0

func (ae *AgentEngine) GetCompactionOptions() *CompactionOptions

GetCompactionOptions returns the current compaction options under the read lock (nil when disabled). The Enabled/CacheAnchorTokens switches live on types.AgentConfig; the SummaryGenerator lives only here. Exported so the constructor (dino/factory.go) and tests can verify the wiring.

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) MemoryTurnCounter added in v1.8.11

func (ae *AgentEngine) MemoryTurnCounter() uint32

func (*AgentEngine) RestoreMemoryTurnCounter added in v1.8.11

func (ae *AgentEngine) RestoreMemoryTurnCounter(v uint32)

func (*AgentEngine) RestoreTotalUsage added in v1.8.11

func (ae *AgentEngine) RestoreTotalUsage(u types.Usage)

func (*AgentEngine) SetCompactionOptions added in v1.10.0

func (ae *AgentEngine) SetCompactionOptions(opts *CompactionOptions)

SetCompactionOptions wires prefix-preserving compaction (P3.1). The summary generator must come from the constructor (dino/factory.go injects chatstore.DeterministicCompact as a closure); the engine itself never imports dino (review BLOCKER B1). Pass nil to disable.

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) SetTracer added in v1.10.0

func (ae *AgentEngine) SetTracer(t hooks.Tracer)

SetTracer injects (or clears, with nil) the trace handle. Called by the dino layer at session construction; the engine stays ignorant of dino.

func (*AgentEngine) Stop

func (ae *AgentEngine) Stop(ctx context.Context)

Stop stops the agent engine Safely stops the agent engine and releases resources

type CompactionOptions added in v1.10.0

type CompactionOptions struct {
	SummaryGenerator func(existingSummary string, mid []types.Message) string
}

CompactionOptions carries the prefix-preserving compaction behavior (P3.1 · prompt caching Step 4). The engine only reads the fields; the summary generator is wired at construction time so agent/engine never imports dino (review BLOCKER B1).

SummaryGenerator is the P3.4 hook: replace deterministic compaction with an LLM summary. The closure is injected by the constructor (dino/factory passes chatstore.DeterministicCompact). nil means "drop the middle and keep head+tail" — the budget-safe fallback (B1).

The Enabled / CacheAnchorTokens switches live on types.AgentConfig (REC-4c: fields go through config, the function goes through injection); the engine gates the three-phase path on config.CompactionPrefix and reads the anchor budget from config.CacheAnchorTokens.

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

Jump to

Keyboard shortcuts

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