agent

package
v0.102.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeatureWorkflows = "workflows"
)
View Source
const GoalFromContextDefaultWindow = 8

Variables

This section is empty.

Functions

func BuildGoalFromContextPrompt

func BuildGoalFromContextPrompt(tail []ai.Message) string

func EstimateTokens

func EstimateTokens(msgs []ai.Message) int

func GoalFromContextMessages

func GoalFromContextMessages(msgs []ai.Message, n int) ([]ai.Message, error)

Types

type Agent

type Agent struct {
	Client    ai.Client
	Model     string
	ModelName string
	Provider  string
	MaxTokens int
	Effort    string

	Temperature *float64
	TopP        *float64
	Tools       []tools.Tool
	Messages    []ai.Message

	ContextLimit int

	CompactClient ai.Client
	CompactModel  string

	CompactThreshold float64

	TaskDefault SubModel

	ResolveModel func(model, provider string) (SubModel, error)

	MaxTurns int

	WorktreeSubagents bool

	Todos []Todo

	BrowserDisabled bool

	ComputerDisabled bool

	OnOrphanedSteer func(text string)
	// contains filtered or unexported fields
}

func New

func New(client ai.Client, model string, maxTokens int, systemPrompt string, opts ...Option) *Agent

func (*Agent) AddSubUsage

func (a *Agent) AddSubUsage(model string, u ai.Usage)

func (*Agent) AddUsage

func (a *Agent) AddUsage(u ai.Usage)

func (*Agent) AllTools

func (a *Agent) AllTools() []tools.Tool

func (*Agent) AppendUser

func (a *Agent) AppendUser(content string)

func (*Agent) Experimental

func (a *Agent) Experimental() []string

func (*Agent) FollowupTask

func (a *Agent) FollowupTask(ctx context.Context, id, text string, ev Events) (string, error)

func (*Agent) LaunchBackground

func (a *Agent) LaunchBackground(t *BackgroundTask, worktreePath string)

func (*Agent) LoadTodosJSON

func (a *Agent) LoadTodosJSON(s string)

func (*Agent) ManualCompact

func (a *Agent) ManualCompact(ctx context.Context, ev Events) error

func (*Agent) MessagesSnapshot

func (a *Agent) MessagesSnapshot() []ai.Message

func (*Agent) RegisterBackground

func (a *Agent) RegisterBackground(description, prompt string, o SubModel) *BackgroundTask

func (*Agent) ResetUsage

func (a *Agent) ResetUsage()

func (*Agent) RestoreTask

func (a *Agent) RestoreTask(t BackgroundTask)

func (*Agent) SessionIDValue

func (a *Agent) SessionIDValue() string

func (*Agent) SetCacheKey

func (a *Agent) SetCacheKey(key string)

func (*Agent) SetMCPTools

func (a *Agent) SetMCPTools(ts []tools.Tool)

func (*Agent) SetOnTodos

func (a *Agent) SetOnTodos(fn func(items []Todo))

func (*Agent) SetSessionID

func (a *Agent) SetSessionID(id string)

func (*Agent) SetSubUsage

func (a *Agent) SetSubUsage(m map[string]ai.Usage)

func (*Agent) SetUsage

func (a *Agent) SetUsage(u ai.Usage)

func (*Agent) StartBackground

func (a *Agent) StartBackground(description, prompt string, o SubModel) *BackgroundTask

func (*Agent) StartWait

func (a *Agent) StartWait(spec WaitTaskSpec) (*waitTask, error)

func (*Agent) Steer

func (a *Agent) Steer(text string)

func (*Agent) SteerImages

func (a *Agent) SteerImages(text string, parts []ai.ContentPart)

func (*Agent) SteerTask

func (a *Agent) SteerTask(id, text string) error

func (*Agent) SubUsage

func (a *Agent) SubUsage() map[string]ai.Usage

func (*Agent) Tasks

func (a *Agent) Tasks() *taskRegistry

func (*Agent) TodosJSON

func (a *Agent) TodosJSON() string

func (*Agent) TotalUsage

func (a *Agent) TotalUsage() ai.Usage

func (*Agent) Turn

func (a *Agent) Turn(ctx context.Context, input string, ev Events) (string, error)

func (*Agent) TurnAuthored

func (a *Agent) TurnAuthored(ctx context.Context, input string, ev Events) (string, error)

func (*Agent) TurnParts

func (a *Agent) TurnParts(ctx context.Context, input string, parts []ai.ContentPart, ev Events) (string, error)

func (*Agent) TurnRunning

func (a *Agent) TurnRunning() bool

func (*Agent) TurnWithImages

func (a *Agent) TurnWithImages(ctx context.Context, input string, parts []ai.ContentPart, ev Events) (string, error)

func (*Agent) Usage

func (a *Agent) Usage() ai.Usage

func (*Agent) WaitingOnSubagents

func (a *Agent) WaitingOnSubagents() bool

func (*Agent) Waits

func (a *Agent) Waits() *waitRegistry

func (*Agent) Workflows

func (a *Agent) Workflows() *workflow.Manager

type BackgroundTask

type BackgroundTask struct {
	ID          string
	Description string
	Prompt      string
	Status      TaskStatus
	Report      string
	StartedAt   time.Time
	EndedAt     time.Time

	Restored bool

	Done chan struct{}

	SubMessages []ai.Message

	SubUsage    ai.Usage
	SubSubUsage map[string]ai.Usage

	SubModel string
	// contains filtered or unexported fields
}

type CompactInfo

type CompactInfo struct {
	Model string
	Usage ai.Usage
}

type Events

type Events struct {
	OnText      func(delta string)
	OnThink     func(delta string)
	OnToolStart func(id, name, args string)
	OnToolEnd   func(id, name, result string)

	OnToolCall func(id, name, args string)

	OnToolOutput func(id, outputSoFar string)
	OnSteer      func(text string)
	OnCompact    func(took, kept int)

	OnCompacted func(summary string, cutoff int, info CompactInfo)

	OnCompactStart func(took, estTokens int)
	OnUsage        func(u ai.Usage)
	OnRetry        func(ev ai.RetryEvent)

	OnDecay func(n int)
}

func FanIn

func FanIn(evs ...Events) Events

type JournaledEvent

type JournaledEvent struct {
	Kind  int
	S, S2 string
}

type Option

type Option func(*Agent)

func WithExperimental

func WithExperimental(features []string) Option

type SubModel

type SubModel struct {
	Client       ai.Client
	Model        string
	ContextLimit int
	MaxTokens    int
	Effort       string
}

type TaskStatus

type TaskStatus string
const (
	TaskRunning   TaskStatus = "running"
	TaskDone      TaskStatus = "done"
	TaskError     TaskStatus = "error"
	TaskCancelled TaskStatus = "cancelled"
)

type Todo

type Todo struct {
	ID      string `json:"id"`
	Content string `json:"content"`
	Status  string `json:"status"`
}

type WaitStatus

type WaitStatus string
const (
	WaitRunning WaitStatus = "running"
	WaitMet     WaitStatus = "condition met"
	WaitTimeout WaitStatus = "timed out"
	WaitFailed  WaitStatus = "command failing"
	WaitKilled  WaitStatus = "cancelled"
)

type WaitTaskSpec

type WaitTaskSpec struct {
	Command  string
	Until    string
	Interval time.Duration
	Timeout  time.Duration
}

Jump to

Keyboard shortcuts

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