agent

package
v0.0.0-...-bcaad4a Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoGoal              = errors.New("agent: no goal is set")
	ErrGoalAlreadyComplete = errors.New("agent: goal is already complete")
)

Functions

func SteeringSignal

func SteeringSignal(ctx context.Context) <-chan struct{}

Types

type Checkpoint

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

func (Checkpoint) Initialized

func (checkpoint Checkpoint) Initialized() bool

func (Checkpoint) MarshalJSON

func (checkpoint Checkpoint) MarshalJSON() ([]byte, error)

func (*Checkpoint) UnmarshalJSON

func (checkpoint *Checkpoint) UnmarshalJSON(encoded []byte) error

type CompactResponse

type CompactResponse struct {
	State []byte
	Usage Usage
}

type CompactionErrorPolicy

type CompactionErrorPolicy interface {
	ShouldCompactAfterError(Request, error) bool
}

CompactionErrorPolicy decides whether a failed generation should be retried after compacting its request.

type Compactor

type Compactor interface {
	ShouldCompact(Request, Usage) bool
	Compact(context.Context, Request) (CompactResponse, error)
}

type ContentPart

type ContentPart struct {
	Kind  ContentPartKind `json:"kind"`
	Text  string          `json:"text,omitempty"`
	Image *Image          `json:"image,omitempty"`
}

type ContentPartKind

type ContentPartKind string
const (
	ContentPartText  ContentPartKind = "text"
	ContentPartImage ContentPartKind = "image"
)

type Engine

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

func New

func New(provider Provider, tools Toolbox, options Options) *Engine

func (*Engine) Checkpoint

func (e *Engine) Checkpoint() (Checkpoint, error)

func (*Engine) ClearGoal

func (e *Engine) ClearGoal()

func (*Engine) ClearSteering

func (e *Engine) ClearSteering() [][]ContentPart

func (*Engine) Compact

func (e *Engine) Compact(ctx context.Context, sink EventSink) error

func (*Engine) CompleteGoal

func (e *Engine) CompleteGoal() error

func (*Engine) Goal

func (e *Engine) Goal() (GoalState, bool)

func (*Engine) Reset

func (e *Engine) Reset() error

func (*Engine) RestoreCheckpoint

func (e *Engine) RestoreCheckpoint(checkpoint Checkpoint) error

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, userText string, sink EventSink) (RunResult, error)

func (*Engine) RunContent

func (e *Engine) RunContent(ctx context.Context, content []ContentPart, sink EventSink) (RunResult, error)

func (*Engine) SetFastMode

func (e *Engine) SetFastMode(enabled bool)

func (*Engine) SetGoal

func (e *Engine) SetGoal(objective string) error

func (*Engine) SetSessionID

func (e *Engine) SetSessionID(sessionID string)

func (*Engine) SetThinkingLevel

func (e *Engine) SetThinkingLevel(level ThinkingLevel) error

func (*Engine) Steer

func (e *Engine) Steer(content []ContentPart) bool

type Event

type Event struct {
	Kind         EventKind
	Text         string
	Content      []ContentPart
	Call         ToolCall
	Presentation ToolPresentation
	Result       ToolResult
	Usage        Usage
	Attempt      int
	Checkpoint   *Checkpoint
}

type EventKind

type EventKind string
const (
	EventAssistantText      EventKind = "assistant_text"
	EventAssistantReasoning EventKind = "assistant_reasoning"
	EventCompactionStart    EventKind = "compaction_start"
	EventCompactionEnd      EventKind = "compaction_end"
	EventContextUsage       EventKind = "context_usage"
	EventGenerationRetry    EventKind = "generation_retry"
	EventCheckpoint         EventKind = "checkpoint"
	EventSteering           EventKind = "steering"
	EventGoalContinuation   EventKind = "goal_continuation"
	EventToolStart          EventKind = "tool_start"
	EventToolUpdate         EventKind = "tool_update"
	EventToolExecute        EventKind = "tool_execute"
	EventToolEnd            EventKind = "tool_end"
)

type EventSink

type EventSink func(Event) error

type GenerationRetryPolicy

type GenerationRetryPolicy interface {
	RetryGeneration(err error, failedAttempts int) (time.Duration, bool)
}

GenerationRetryPolicy decides whether a failed generation attempt should be retried. failedAttempts includes the attempt that returned err.

type GoalState

type GoalState struct {
	Objective string `json:"objective"`
	Complete  bool   `json:"complete"`
}

type Image

type Image struct {
	MediaType string `json:"media_type"`
	Data      []byte `json:"data"`
}

type InboxBatch

type InboxBatch struct {
	MessageIDs []uint64
	Text       string
}

type InboxSource

type InboxSource interface {
	SnapshotInbox() InboxBatch
	AcknowledgeInbox(InboxBatch) error
	InboxEmpty() bool
}

type Input

type Input struct {
	Kind    InputKind     `json:"kind"`
	Text    string        `json:"text"`
	Content []ContentPart `json:"content,omitempty"`
	CallID  string        `json:"call_id"`
	Tool    string        `json:"tool"`
	IsError bool          `json:"is_error"`
}

func NewInboxInput

func NewInboxInput(text string) Input

func NewTextInput

func NewTextInput(text string) Input

func NewToolResultInput

func NewToolResultInput(result ToolResult) Input

func NewUserInput

func NewUserInput(parts ...ContentPart) Input

func (Input) PlainText

func (input Input) PlainText() string

func (Input) Validate

func (input Input) Validate() error

type InputKind

type InputKind string
const (
	InputUser       InputKind = "user"
	InputToolResult InputKind = "tool_result"
	InputInbox      InputKind = "inbox"
)

type JSONSchema

type JSONSchema struct {
	Type                 any                   `json:"type,omitempty"`
	Description          string                `json:"description,omitempty"`
	Properties           map[string]JSONSchema `json:"properties,omitempty"`
	Required             []string              `json:"required,omitempty"`
	AdditionalProperties *bool                 `json:"additionalProperties,omitempty"`
	Items                *JSONSchema           `json:"items,omitempty"`
	AnyOf                []JSONSchema          `json:"anyOf,omitempty"`
}

func (JSONSchema) MarshalJSON

func (schema JSONSchema) MarshalJSON() ([]byte, error)

type Options

type Options struct {
	Model                  string
	WorkingDirectory       string
	ProjectInstructions    string
	Skills                 []skill.Skill
	Checkpointing          bool
	Inbox                  InboxSource
	AdditionalInstructions func() string
	Settings               *Settings
}

type Provider

type Provider interface {
	Generate(context.Context, Request, StreamObserver) (Response, error)
}

type Request

type Request struct {
	SessionID     string
	Model         string
	ThinkingLevel ThinkingLevel
	FastMode      bool
	Instructions  string
	Inputs        []Input
	Tools         []ToolDefinition
	State         []byte
}

type Response

type Response struct {
	Text      string
	ToolCalls []ToolCall
	State     []byte
	Usage     Usage
}

type RunResult

type RunResult struct {
	Text  string
	Usage Usage
}

type Settings

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

func NewSettings

func NewSettings(thinkingLevel ThinkingLevel, fastMode bool) *Settings

func (*Settings) SetFastMode

func (settings *Settings) SetFastMode(enabled bool)

func (*Settings) SetThinkingLevel

func (settings *Settings) SetThinkingLevel(level ThinkingLevel) error

func (*Settings) Snapshot

func (settings *Settings) Snapshot() (ThinkingLevel, bool)

type StreamObserver

type StreamObserver struct {
	Text      TextSink
	Reasoning TextSink
	ToolCall  ToolCallSink
}

StreamObserver callbacks may be called concurrently while Generate is running. Returning an error stops delivery and terminates generation.

type TextSink

type TextSink func(text string) error

type ThinkingLevel

type ThinkingLevel string
const (
	ThinkingOff     ThinkingLevel = "off"
	ThinkingMinimal ThinkingLevel = "minimal"
	ThinkingLow     ThinkingLevel = "low"
	ThinkingMedium  ThinkingLevel = "medium"
	ThinkingHigh    ThinkingLevel = "high"
	ThinkingXHigh   ThinkingLevel = "xhigh"
	ThinkingMax     ThinkingLevel = "max"

	DefaultThinkingLevel = ThinkingMedium
)

func ClampThinkingLevel

func ClampThinkingLevel(level ThinkingLevel, supported []ThinkingLevel) ThinkingLevel

func ParseThinkingLevel

func ParseThinkingLevel(value string) (ThinkingLevel, error)

func ThinkingLevels

func ThinkingLevels() []ThinkingLevel

func (ThinkingLevel) Valid

func (level ThinkingLevel) Valid() bool

type ThinkingLevelMap

type ThinkingLevelMap map[ThinkingLevel]string

func (ThinkingLevelMap) Clamp

func (levels ThinkingLevelMap) Clamp(level ThinkingLevel) ThinkingLevel

func (ThinkingLevelMap) SupportedLevels

func (levels ThinkingLevelMap) SupportedLevels() []ThinkingLevel

type ToolCall

type ToolCall struct {
	ID        string
	Name      string
	Arguments json.RawMessage
}

type ToolCallSink

type ToolCallSink func(ToolCallSnapshot) error

type ToolCallSnapshot

type ToolCallSnapshot struct {
	ID           string
	Name         string
	RawArguments string
	Complete     bool
}

type ToolDefinition

type ToolDefinition struct {
	Name        string
	Description string
	Parameters  JSONSchema
}

type ToolDiffLine

type ToolDiffLine struct {
	Kind    ToolDiffLineKind `json:"kind"`
	OldLine int              `json:"old_line"`
	NewLine int              `json:"new_line"`
	Text    string           `json:"text"`
}

type ToolDiffLineKind

type ToolDiffLineKind uint8
const (
	ToolDiffLineContext ToolDiffLineKind = 0
	ToolDiffLineAdded   ToolDiffLineKind = 1
	ToolDiffLineRemoved ToolDiffLineKind = 2
	ToolDiffLineOmitted ToolDiffLineKind = 3
)

Values are persisted in terminal checkpoints and must remain stable.

type ToolPresentation

type ToolPresentation struct {
	Title          string         `json:"title"`
	Arguments      string         `json:"arguments"`
	Lines          []string       `json:"lines"`
	LinesTruncated bool           `json:"lines_truncated"`
	Diff           []ToolDiffLine `json:"diff"`
	Markdown       bool           `json:"markdown"`
	Outcome        string         `json:"outcome"`
	TailLines      int            `json:"tail_lines"`
	Elapsed        time.Duration  `json:"elapsed"`
	Timeout        time.Duration  `json:"timeout"`
}

func (ToolPresentation) Clone

func (presentation ToolPresentation) Clone() ToolPresentation

func (ToolPresentation) Equal

func (presentation ToolPresentation) Equal(other ToolPresentation) bool

type ToolPresenter

type ToolPresenter interface {
	Presentation(ToolCallSnapshot) ToolPresentation
}

type ToolResult

type ToolResult struct {
	CallID  string
	Tool    string
	Output  string
	IsError bool
}

type ToolUpdateSink

type ToolUpdateSink interface {
	Update(ToolPresentation) error
	// SetFinal replaces the presentation attached to the tool-end event and ignores later updates.
	SetFinal(ToolPresentation)
}

ToolUpdateSink may be called concurrently before Execute returns.

type Toolbox

type Toolbox interface {
	Definitions() []ToolDefinition
	// Execute may be called concurrently for calls from the same provider response.
	Execute(ctx context.Context, call ToolCall, updates ToolUpdateSink) (ToolResult, error)
}

type Usage

type Usage struct {
	InputTokens  int64 `json:"input_tokens"`
	OutputTokens int64 `json:"output_tokens"`
	TotalTokens  int64 `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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