Versions in this module Expand all Collapse all v1 v1.0.3 May 3, 2026 v1.0.2 May 3, 2026 Changes in this version + func FormatPlanTasks(tasks []PlanTask) string + func MarshalPlanTasks(tasks []PlanTask) (json.RawMessage, error) + func PlanningToolDefinition() model.ToolDefinition + func QueueDeferredUserMessage(execCtx *ExecutionContext, content string) type Agent + func (a *Agent) WithDynamicToolsCallback(cb DynamicToolsCallback) *Agent + func (a *Agent) WithFinalAnswerCallbacks(callbacks ...FinalAnswerCallback) *Agent + func (a *Agent) WithLiveEventSink(sinks ...LiveEventSink) *Agent + type ChunkContextEnricher interface + EnrichChunk func(context.Context, string, string, map[string]string) (string, error) + type DynamicToolsCallback func(*ExecutionContext) []model.ToolDefinition + type EvidenceCollector interface + Evidence func() []EvidenceItem + type EvidenceItem struct + Content string + Score float64 + Source string + type EvidenceTracker struct + func NewEvidenceTracker(mapper func(model.ToolResult) (EvidenceItem, bool)) *EvidenceTracker + func (t *EvidenceTracker) AfterTool(_ context.Context, _ *ExecutionContext, result model.ToolResult) (*model.ToolResult, error) + func (t *EvidenceTracker) Evidence() []EvidenceItem + type FinalAnswerCallback interface + BeforeFinalAnswer func(ctx context.Context, execCtx *ExecutionContext, answer string) error + type HybridRetriever interface + Retrieve func(context.Context, string, int) ([]RetrievalCandidate, error) + type LiveEventSink func(AgentEvent) + type MemoryWriteDecision struct + Reason string + Score float64 + ShouldStore bool + type MemoryWritePolicy interface + Decide func(context.Context, TaskMemory) (MemoryWriteDecision, error) + type Observation struct + Content string + ToolCallID string + ToolName string + type PlanRevision struct + Index int + Plan string + TaskCount int + type PlanRevisionEvent struct + Revision PlanRevision + RunID string + Step int + type PlanTask struct + Content string + Status PlanTaskStatus + func ParsePlanTasks(data []byte) ([]PlanTask, error) + func (t PlanTask) String() string + type PlanTaskStatus string + const PlanTaskCompleted + const PlanTaskInProgress + const PlanTaskPending + type PlanningExecutor struct + func NewPlanningExecutor(delegate model.ToolExecutor) *PlanningExecutor + func (e *PlanningExecutor) Execute(ctx context.Context, calls []model.ToolCall) ([]model.ToolResult, error) + func (e *PlanningExecutor) LatestPlan() (string, bool) + func (e *PlanningExecutor) Plans() []string + func (e *PlanningExecutor) Revisions() []PlanRevision + func (e *PlanningExecutor) TaskCounts() []int + func (e *PlanningExecutor) WithObservers(observers ...PlanningObserver) *PlanningExecutor + type PlanningObserver interface + OnPlanRevision func(revision PlanRevision) + type PlanningPolicy struct + func NewPlanningPolicy(source planRevisionSource, minRevisions int) *PlanningPolicy + func (p *PlanningPolicy) BeforeFinalAnswer(_ context.Context, _ *ExecutionContext, _ string) error + type PlanningReflectionEvent struct + Content string + Kind PlanningReflectionEventKind + RunID string + Step int + type PlanningReflectionEventKind string + const PlanningReflectionEventInsufficientProgress + const PlanningReflectionEventReflectionRecorded + const PlanningReflectionEventRevisionNeeded + const PlanningReflectionEventRevisionResolved + const PlanningReflectionEventStagnationObserved + type PlanningReflectionOption func(*PlanningReflectionTracker) + func WithPlanningReflectionStagnationThreshold(n int) PlanningReflectionOption + type PlanningReflectionPolicy struct + func NewPlanningReflectionPolicy(source planRevisionSource, tracker *PlanningReflectionTracker, ...) *PlanningReflectionPolicy + func (p *PlanningReflectionPolicy) BeforeFinalAnswer(ctx context.Context, execCtx *ExecutionContext, answer string) error + type PlanningReflectionTracker struct + func NewPlanningReflectionTracker(options ...PlanningReflectionOption) *PlanningReflectionTracker + func (t *PlanningReflectionTracker) AfterTool(ctx context.Context, execCtx *ExecutionContext, result model.ToolResult) (*model.ToolResult, error) + func (t *PlanningReflectionTracker) BeforeTool(_ context.Context, execCtx *ExecutionContext, call model.ToolCall) (*model.ToolResult, error) + func (t *PlanningReflectionTracker) LatestReflection() string + func (t *PlanningReflectionTracker) NeedsReflection() bool + func (t *PlanningReflectionTracker) NeedsRevision() bool + func (t *PlanningReflectionTracker) RecordReflection(ctx context.Context, execCtx *ExecutionContext, reflection string, ...) + type PolicyDecision string + const PolicyDecisionAccept + const PolicyDecisionReject + type PolicyEvent struct + Answer string + Decision PolicyDecision + Latency time.Duration + PolicyName string + Reason string + RunID string + Step int + type RecoveryAttempt struct + Output string + ToolCallID string + ToolName string + type RecoveryEvent struct + Kind RecoveryEventKind + Reason string + RunID string + Step int + ToolCallID string + ToolName string + type RecoveryEventKind string + const RecoveryEventFailureObserved + const RecoveryEventRecovered + const RecoveryEventReflectionRecorded + type RecoveryFailure struct + Reason string + ToolCallID string + ToolName string + type RecoveryPolicy struct + func NewRecoveryPolicy(source recoveryStateSource) *RecoveryPolicy + func (p *RecoveryPolicy) BeforeFinalAnswer(ctx context.Context, execCtx *ExecutionContext, answer string) error + type RecoveryTracker struct + func NewRecoveryTracker() *RecoveryTracker + func (r *RecoveryTracker) AfterTool(ctx context.Context, execCtx *ExecutionContext, result model.ToolResult) (*model.ToolResult, error) + func (r *RecoveryTracker) Attempts() []RecoveryAttempt + func (r *RecoveryTracker) BeforeTool(_ context.Context, execCtx *ExecutionContext, call model.ToolCall) (*model.ToolResult, error) + func (r *RecoveryTracker) Failures() []RecoveryFailure + func (r *RecoveryTracker) HasUnresolvedFailures() bool + func (r *RecoveryTracker) LatestReflection() string + func (r *RecoveryTracker) RecordReflection(ctx context.Context, execCtx *ExecutionContext, reflection string) error + func (r *RecoveryTracker) RequiresReflection() bool + type Reranker interface + Rerank func(context.Context, string, []RetrievalCandidate, int) ([]RetrievalCandidate, error) + type RetrievalCandidate struct + Content string + ID string + Metadata map[string]string + Score float64 type SessionManager + func NewPersistedSessionManager(persister SessionPersister) SessionManager + type SessionPersister interface + LoadSession func(context.Context, string) (Session, error) + SaveSession func(context.Context, Session) error + type StablePrefixDetector interface + Detect func(model.Request) string + type SynthesisEvent struct + Content string + Kind SynthesisEventKind + RunID string + Step int + ToolCallID string + ToolName string + type SynthesisEventKind string + const SynthesisEventObservationRecorded + const SynthesisEventSynthesisComplete + type SynthesisPolicy struct + func NewSynthesisPolicy(source synthesisStateSource) *SynthesisPolicy + func (p *SynthesisPolicy) BeforeFinalAnswer(ctx context.Context, execCtx *ExecutionContext, _ string) error + type SynthesisRecord struct + Observations []Observation + type SynthesisTracker struct + func NewSynthesisTracker() *SynthesisTracker + func (s *SynthesisTracker) AfterTool(ctx context.Context, execCtx *ExecutionContext, result model.ToolResult) (*model.ToolResult, error) + func (s *SynthesisTracker) HasIncompleteAnalysis() bool + func (s *SynthesisTracker) MarkSynthesisComplete(ctx context.Context, execCtx *ExecutionContext) error + func (s *SynthesisTracker) Observations() []Observation + func (s *SynthesisTracker) SynthesisHistory() []SynthesisRecord type TaskMemoryManager + func (m *TaskMemoryManager) WithWritePolicy(policy MemoryWritePolicy) *TaskMemoryManager + type ThresholdMemoryWritePolicy struct + func NewThresholdMemoryWritePolicy(threshold float64) ThresholdMemoryWritePolicy + func (p ThresholdMemoryWritePolicy) Decide(_ context.Context, memory TaskMemory) (MemoryWriteDecision, error) + type VerificationGate struct + func NewVerificationGate(collector EvidenceCollector, minItems int, options ...VerificationOption) *VerificationGate + func (g *VerificationGate) BeforeFinalAnswer(_ context.Context, _ *ExecutionContext, answer string) error + func (g *VerificationGate) BeforeTool(_ context.Context, execCtx *ExecutionContext, call model.ToolCall) (*model.ToolResult, error) + func (g *VerificationGate) LatestReflection() string + func (g *VerificationGate) NeedsReflection() bool + type VerificationOption func(*VerificationGate) + func WithActionableVerificationReflection() VerificationOption v1.0.1 Apr 30, 2026 Changes in this version + var ErrInteractionRequested = errors.New("agent: interaction requested") + func Suspend(req InteractionRequest) error + type AfterToolCallback interface + AfterTool func(ctx context.Context, execCtx *ExecutionContext, result model.ToolResult) (*model.ToolResult, error) type Agent + func (a *Agent) Resume(ctx context.Context, suspended SuspendedRun, response InteractionResponse) (*Result, rxgo.Observable, error) + func (a *Agent) WithAfterToolCallbacks(callbacks ...AfterToolCallback) *Agent + func (a *Agent) WithBeforeToolCallbacks(callbacks ...BeforeToolCallback) *Agent + type ApprovalPolicy interface + RuleForTool func(name string) (ApprovalRule, bool) + type ApprovalRule struct + DeniedMessage string + MessageTemplate string + type BeforeToolCallback interface + BeforeTool func(ctx context.Context, execCtx *ExecutionContext, call model.ToolCall) (*model.ToolResult, error) + type CallbackEvent struct + Callback string + Err error + Latency time.Duration + Overrode bool + Phase CallbackPhase + RunID string + Stage CallbackStage + Step int + ToolCallID string + ToolName string + type CallbackPhase string + const CallbackPhaseAfterTool + const CallbackPhaseBeforeTool + type CallbackStage string + const CallbackStageFinish + const CallbackStageStart + type CompactionStrategy struct + func NewCompactionStrategy() CompactionStrategy + func (CompactionStrategy) Optimize(_ context.Context, req *model.Request) error + type ConfirmationCallback struct + func NewConfirmationCallback(policy ApprovalPolicy) ConfirmationCallback + func (c ConfirmationCallback) BeforeTool(_ context.Context, execCtx *ExecutionContext, call model.ToolCall) (*model.ToolResult, error) + func (c ConfirmationCallback) WithLogger(logger *slog.Logger) ConfirmationCallback + type ContextOptimizer struct + func NewContextOptimizer(counter TokenCounter, threshold int, strategies ...OptimizationStrategy) *ContextOptimizer + func (o *ContextOptimizer) Mutate(ctx context.Context, req *model.Request) error + func (o *ContextOptimizer) WithLogger(logger *slog.Logger) *ContextOptimizer + type DuplicateChecker interface + IsDuplicate func(memory TaskMemory, existing []TaskMemory) bool + type Embedder interface + Embed func(ctx context.Context, texts []string) ([][]float64, error) type ExecutionContext + func (ec *ExecutionContext) InteractionResponse(requestID string) (InteractionResponse, bool) + func (ec *ExecutionContext) PendingInteraction() (*InteractionRequest, bool) + type InMemorySessionManager struct + func NewInMemorySessionManager() *InMemorySessionManager + func (m *InMemorySessionManager) Create(sessionID, userID string) (*Session, error) + func (m *InMemorySessionManager) Get(sessionID string) (*Session, error) + func (m *InMemorySessionManager) GetOrCreate(sessionID, userID string) (*Session, error) + func (m *InMemorySessionManager) Save(session *Session) error + type InMemoryVectorStore struct + func NewInMemoryVectorStore() *InMemoryVectorStore + func (s *InMemoryVectorStore) Add(_ context.Context, docs []VectorDocument) error + func (s *InMemoryVectorStore) Search(_ context.Context, query []float64, topK int) ([]VectorDocument, error) + type InteractionRequest struct + ID string + Kind string + Payload map[string]any + Prompt string + ToolCallID string + ToolName string + type InteractionRequestedError struct + Suspended SuspendedRun + func (e *InteractionRequestedError) Error() string + func (e *InteractionRequestedError) Unwrap() error + type InteractionRequestedEvent struct + Request InteractionRequest + RunID string + Step int + type InteractionResponse struct + Approved *bool + Metadata map[string]any + RequestID string + Value string + type InteractionResumedEvent struct + Response InteractionResponse + RunID string + Step int + type MemoryInjector struct + func NewMemoryInjector(searcher MemorySearcher, topK int) MemoryInjector + func (i MemoryInjector) Mutate(ctx context.Context, req *model.Request) error + type MemorySearcher interface + Search func(ctx context.Context, query string, topK int) ([]TaskMemory, error) + type MutatingLLMClient struct + func NewMutatingLLMClient(delegate LLMClient, mutators ...RequestMutator) *MutatingLLMClient + func (c *MutatingLLMClient) Generate(ctx context.Context, req model.Request) (model.Response, error) + type OptimizationStrategy interface + Optimize func(ctx context.Context, req *model.Request) error + type RequestMutator interface + Mutate func(ctx context.Context, req *model.Request) error + func WithMutatorLogger(mutator RequestMutator, logger *slog.Logger) RequestMutator + type RequestTokenCounter struct + func NewRequestTokenCounter(modelName string) (*RequestTokenCounter, error) + func (c *RequestTokenCounter) Count(req model.Request) (int, error) + type RunResult struct + Output string + PendingInteraction *InteractionRequest + SessionID string + Status RunStatus + ToolCalled bool + type RunStatus string + const StatusComplete + const StatusPending + type Session struct + CreatedAt time.Time + Events []model.Event + SessionID string + State map[string]any + UpdatedAt time.Time + UserID string + type SessionManager interface + Create func(sessionID, userID string) (*Session, error) + Get func(sessionID string) (*Session, error) + GetOrCreate func(sessionID, userID string) (*Session, error) + Save func(session *Session) error + type SessionRunner struct + func NewSessionRunner(agent *Agent, sessions SessionManager, maxSteps int) *SessionRunner + func (r *SessionRunner) Resume(ctx context.Context, sessionID, userID string, response InteractionResponse) (*RunResult, error) + func (r *SessionRunner) Run(ctx context.Context, sessionID, userID, userInput string) (*RunResult, error) + func (r *SessionRunner) WithLogger(logger *slog.Logger) *SessionRunner + type SimpleDuplicateChecker struct + func (SimpleDuplicateChecker) IsDuplicate(memory TaskMemory, existing []TaskMemory) bool + type SlidingWindowStrategy struct + func NewSlidingWindowStrategy(windowSize int) SlidingWindowStrategy + func (s SlidingWindowStrategy) Optimize(_ context.Context, req *model.Request) error + type StaticApprovalPolicy map[string]ApprovalRule + func (p StaticApprovalPolicy) RuleForTool(name string) (ApprovalRule, bool) + type SummarizationStrategy struct + func NewSummarizationStrategy(generator SummaryGenerator, keepRecent int) SummarizationStrategy + func (s SummarizationStrategy) Optimize(ctx context.Context, req *model.Request) error + type SummaryGenerator interface + Summarize func(ctx context.Context, events []model.Event) (string, error) + type SuspendedRun struct + Context *ExecutionContext + Interaction InteractionRequest + type TaskMemory struct + Approach string + ErrorAnalysis string + FinalAnswer string + IsCorrect bool + TaskSummary string + func (m TaskMemory) EmbeddingText() string + type TaskMemoryManager struct + func NewTaskMemoryManager(embedder Embedder, store VectorStore, duplicateChecker DuplicateChecker) *TaskMemoryManager + func (m *TaskMemoryManager) Save(ctx context.Context, memory TaskMemory) (string, bool, error) + func (m *TaskMemoryManager) Search(ctx context.Context, query string, topK int) ([]TaskMemory, error) + func (m *TaskMemoryManager) WithLogger(logger *slog.Logger) *TaskMemoryManager + type TokenCounter interface + Count func(req model.Request) (int, error) + type VectorDocument struct + ID string + Memory TaskMemory + Vector []float64 + type VectorStore interface + Add func(ctx context.Context, docs []VectorDocument) error + Search func(ctx context.Context, query []float64, topK int) ([]VectorDocument, error) v1.0.0 Apr 23, 2026 Changes in this version + var ErrMaxStepsReached = errors.New("agent: max steps reached without final answer") + type Agent struct + func New(client LLMClient, defs []model.ToolDefinition, executor model.ToolExecutor) *Agent + func (a *Agent) Act(ctx context.Context, execCtx *ExecutionContext, calls []model.ToolCall) error + func (a *Agent) Run(ctx context.Context, userMessage string) (*Result, rxgo.Observable, error) + func (a *Agent) Step(ctx context.Context, execCtx *ExecutionContext) error + func (a *Agent) Think(ctx context.Context, execCtx *ExecutionContext) (model.Response, error) + func (a *Agent) WithInstructions(s string) *Agent + func (a *Agent) WithMaxSteps(n int) *Agent + type AgentEvent interface + type ExecutionContext struct + func NewExecutionContextForTest() *ExecutionContext + func (ec *ExecutionContext) AddEvent(author string, content ...model.ContentItem) + func (ec *ExecutionContext) CurrentStep() int + func (ec *ExecutionContext) Done() bool + func (ec *ExecutionContext) Events() []model.Event + func (ec *ExecutionContext) FinalResult() (string, bool) + func (ec *ExecutionContext) GetState(key string) (any, bool) + func (ec *ExecutionContext) ID() string + func (ec *ExecutionContext) IncrementStep() + func (ec *ExecutionContext) SetState(key string, value any) + type LLMCallEvent struct + Err error + Latency time.Duration + RunID string + Step int + type LLMClient interface + Generate func(ctx context.Context, req model.Request) (model.Response, error) + type LiteLLMClient struct + func NewLiteLLMClient(client *openai.Client, model openai.ChatModel) *LiteLLMClient + func (c *LiteLLMClient) Generate(ctx context.Context, req model.Request) (model.Response, error) + type Result struct + Context *ExecutionContext + Output string + ToolCalled bool + type RunEndEvent struct + Err error + Result *Result + RunID string + type RunStartEvent struct + RunID string + UserMessage string + type StepEndEvent struct + Err error + RunID string + Step int + type StepStartEvent struct + RunID string + Step int + type ToolExecEvent struct + Err error + Latency time.Duration + RunID string + Step int + ToolNames []string