Documentation
¶
Index ¶
- Variables
- type BudgetState
- type BudgetStatus
- type BudgetStrategy
- type BudgetTracker
- func (t *BudgetTracker) AfterToolCall(toolName string, elapsed time.Duration, result map[string]any, err error)
- func (t *BudgetTracker) BeforeToolCall(toolName string, elapsed time.Duration) BudgetStatus
- func (t *BudgetTracker) GenerateHandoverInfo() string
- func (t *BudgetTracker) Remaining() float64
- type DefaultBudgetStrategy
- type Option
- func WithBudgetStrategy(s BudgetStrategy) Option
- func WithFrontendURL(url string) Option
- func WithMaxPhases(n int) Option
- func WithMemoryService(svc *memory.Service) Option
- func WithMonitorPollInterval(d time.Duration) Option
- func WithNoAuthorization(noAuthz bool) Option
- func WithSlackService(svc *slackService.Service) Option
- func WithStorageClient(client interfaces.StorageClient) Option
- func WithStoragePrefix(prefix string) Option
- func WithSubAgents(subAgents []*agent.SubAgent) Option
- func WithTools(tools []gollem.ToolSet) Option
- func WithTraceRepository(repo trace.Repository) Option
- func WithUserSystemPrompt(prompt string) Option
- type PlanResult
- type ReplanResult
- type SwarmChat
- type TaskPlan
- type TaskResult
- type ToolCallContext
- type ToolRecord
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSessionAborted is returned when a session is aborted by user request ErrSessionAborted = goerr.New("session aborted by user") )
Functions ¶
This section is empty.
Types ¶
type BudgetState ¶
type BudgetState struct {
CallsAfterSoft int
TotalCalls int
Remaining float64
Elapsed time.Duration
}
BudgetState holds a snapshot of the current budget state for strategy decisions.
type BudgetStatus ¶
type BudgetStatus int
BudgetStatus represents the current state of the action budget.
const ( // BudgetOK indicates budget is still available. BudgetOK BudgetStatus = iota // BudgetSoftLimit indicates budget is exhausted but a few more calls are allowed. BudgetSoftLimit // BudgetHardLimit indicates the hard limit has been reached and tool execution must stop. BudgetHardLimit )
type BudgetStrategy ¶
type BudgetStrategy interface {
// InitialBudget returns the total budget for a task.
InitialBudget() float64
// BeforeToolCall returns the budget cost to consume before executing a tool.
BeforeToolCall(ctx ToolCallContext) float64
// AfterToolCall returns additional budget cost based on the tool execution result.
AfterToolCall(ctx ToolCallContext) float64
// ShouldExit determines whether tool execution must be forcibly stopped.
// Called after the soft limit has been hit to decide if the task should be terminated.
ShouldExit(state BudgetState) bool
}
BudgetStrategy defines the budget consumption logic.
type BudgetTracker ¶
type BudgetTracker struct {
// contains filtered or unexported fields
}
BudgetTracker tracks the budget state for a single task execution.
func (*BudgetTracker) AfterToolCall ¶
func (t *BudgetTracker) AfterToolCall(toolName string, elapsed time.Duration, result map[string]any, err error)
AfterToolCall consumes additional budget after tool execution based on results.
func (*BudgetTracker) BeforeToolCall ¶
func (t *BudgetTracker) BeforeToolCall(toolName string, elapsed time.Duration) BudgetStatus
BeforeToolCall consumes budget before tool execution and returns the current status.
func (*BudgetTracker) GenerateHandoverInfo ¶
func (t *BudgetTracker) GenerateHandoverInfo() string
GenerateHandoverInfo generates handover information from the tool execution history.
func (*BudgetTracker) Remaining ¶
func (t *BudgetTracker) Remaining() float64
Remaining returns the remaining budget.
type DefaultBudgetStrategy ¶
type DefaultBudgetStrategy struct{}
DefaultBudgetStrategy implements BudgetStrategy with sensible defaults. Target: ~16 tool calls or ~3.5 minutes per task.
func NewDefaultBudgetStrategy ¶
func NewDefaultBudgetStrategy() *DefaultBudgetStrategy
NewDefaultBudgetStrategy creates a new DefaultBudgetStrategy.
func (*DefaultBudgetStrategy) AfterToolCall ¶
func (s *DefaultBudgetStrategy) AfterToolCall(_ ToolCallContext) float64
AfterToolCall always returns 0 for the default strategy.
func (*DefaultBudgetStrategy) BeforeToolCall ¶
func (s *DefaultBudgetStrategy) BeforeToolCall(ctx ToolCallContext) float64
BeforeToolCall calculates the cost before tool execution. Cost = tool fixed cost + time cost delta.
func (*DefaultBudgetStrategy) InitialBudget ¶
func (s *DefaultBudgetStrategy) InitialBudget() float64
InitialBudget returns 100.0 as the total budget.
func (*DefaultBudgetStrategy) ShouldExit ¶
func (s *DefaultBudgetStrategy) ShouldExit(state BudgetState) bool
ShouldExit returns true when more than 3 tool calls have been made after the soft limit.
type Option ¶
type Option func(*SwarmChat)
Option configures a SwarmChat.
func WithBudgetStrategy ¶
func WithBudgetStrategy(s BudgetStrategy) Option
WithBudgetStrategy sets the budget strategy for task execution. When nil (default), budget tracking is disabled and tools execute without limits.
func WithFrontendURL ¶
WithFrontendURL sets the frontend URL for session links.
func WithMaxPhases ¶
WithMaxPhases sets the maximum number of execution phases.
func WithMemoryService ¶
WithMemoryService sets the memory service for agent memory integration.
func WithMonitorPollInterval ¶
WithMonitorPollInterval sets the session monitor polling interval.
func WithNoAuthorization ¶
WithNoAuthorization disables policy-based authorization checks.
func WithSlackService ¶
func WithSlackService(svc *slackService.Service) Option
WithSlackService sets the Slack service for message routing.
func WithStorageClient ¶
func WithStorageClient(client interfaces.StorageClient) Option
WithStorageClient sets the storage client for history persistence.
func WithStoragePrefix ¶
WithStoragePrefix sets the storage prefix for history paths.
func WithSubAgents ¶
WithSubAgents sets the sub-agents available to the agent.
func WithTraceRepository ¶
func WithTraceRepository(repo trace.Repository) Option
WithTraceRepository sets the trace repository for execution tracing.
func WithUserSystemPrompt ¶
WithUserSystemPrompt sets the user system prompt.
type PlanResult ¶
PlanResult represents the LLM planning response.
type ReplanResult ¶
type ReplanResult struct {
Message string `json:"message,omitempty"`
Tasks []TaskPlan `json:"tasks"`
Question string `json:"question,omitempty"`
}
ReplanResult represents the LLM replan response.
type SwarmChat ¶
type SwarmChat struct {
// contains filtered or unexported fields
}
SwarmChat implements interfaces.ChatUseCase with parallel task execution.
func New ¶
func New(repo interfaces.Repository, llmClient gollem.LLMClient, policyClient interfaces.PolicyClient, opts ...Option) *SwarmChat
New creates a new SwarmChat with the given dependencies and options.
type TaskPlan ¶
type TaskPlan struct {
ID string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
AcceptanceCriteria string `json:"acceptance_criteria"`
Tools []string `json:"tools"`
SubAgents []string `json:"sub_agents"`
}
TaskPlan represents a single task in the parallel execution plan.
type TaskResult ¶
type TaskResult struct {
TaskID string
Title string
Result string
Error error
BudgetExceeded bool // true if the task was terminated due to budget exhaustion
}
TaskResult holds the outcome of a single task execution.
type ToolCallContext ¶
type ToolCallContext struct {
ToolName string
Elapsed time.Duration
PrevElapsed time.Duration // Elapsed time at the previous tool call (for time cost delta)
CallCount int
Result map[string]any
Error error
}
ToolCallContext holds all information about a tool call for cost calculation.