aster

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSessionAborted = chat.ErrSessionAborted

ErrSessionAborted is an alias for chat.ErrSessionAborted for backward compatibility.

Functions

This section is empty.

Types

type AsterChat

type AsterChat struct {
	// contains filtered or unexported fields
}

AsterChat implements chat.Strategy with parallel task execution.

func New

func New(repo interfaces.Repository, llmClient gollem.LLMClient, opts ...Option) *AsterChat

New creates a new AsterChat with the given dependencies and options.

func (*AsterChat) Execute

func (c *AsterChat) Execute(ctx context.Context, rc *chat.RunContext) error

Execute implements chat.Strategy. It receives a RunContext with a pre-initialized Warren session and delegates to the aster execution loop.

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(*AsterChat)

Option configures a AsterChat.

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 WithHITLTools

func WithHITLTools(tools []string) Option

WithHITLTools sets the tool names that require human approval before execution.

func WithKnowledgeService

func WithKnowledgeService(svc *svcknowledge.Service) Option

WithKnowledgeService sets the knowledge v2 service for reflection.

func WithMaxPhases

func WithMaxPhases(n int) Option

WithMaxPhases sets the maximum number of execution phases.

func WithMonitorPollInterval

func WithMonitorPollInterval(d time.Duration) Option

WithMonitorPollInterval sets the session monitor polling interval.

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

func WithStoragePrefix(prefix string) Option

WithStoragePrefix sets the storage prefix for history paths.

func WithTools

func WithTools(tools []interfaces.ToolSet) Option

WithTools sets the tool sets available to the agent.

func WithTraceRepository

func WithTraceRepository(repo trace.Repository) Option

WithTraceRepository sets the trace repository for execution tracing.

func WithUserSystemPrompt

func WithUserSystemPrompt(prompt string) Option

WithUserSystemPrompt sets the user system prompt.

type PlanResult

type PlanResult struct {
	Message string     `json:"message"`
	Tasks   []TaskPlan `json:"tasks"`
}

PlanResult represents the LLM planning response.

type Question

type Question struct {
	Question string   `json:"question"` // The question text
	Options  []string `json:"options"`  // Answer choices (required)
	Reason   string   `json:"reason"`   // Why this question is needed
}

Question represents a question to ask the security operator.

type ReplanResult

type ReplanResult struct {
	Message  string     `json:"message,omitempty"`
	Tasks    []TaskPlan `json:"tasks"`
	Question *Question  `json:"question,omitempty"`
}

ReplanResult represents the LLM replan response. If Question is non-nil, it takes priority over Tasks (Tasks are ignored).

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"`
}

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.

type ToolRecord

type ToolRecord struct {
	Name      string
	Cost      float64
	Timestamp time.Time
}

ToolRecord records a single tool execution for handover information.

Jump to

Keyboard shortcuts

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