agent

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxTurns         = 100
	DefaultMaxParallelTools = 8
	DefaultToolTimeout      = 10 * time.Minute

	DefaultContextWindow = 400_000

	DefaultReserveTokens = 32_000
)

Variables

View Source
var ErrEmptyInput = errors.New("agent input is empty")

ErrEmptyInput means Send was called without any content.

View Source
var ErrMaxTurnsExceeded = errors.New("agent: internal turn-loop safety bound exceeded — likely a runaway tool-call cycle")
View Source
var ErrTurnInProgress = errors.New("agent turn already in progress")

ErrTurnInProgress means Send was called while another turn was active.

Functions

func ContextWindowFor added in v0.9.3

func ContextWindowFor(model string, largeContext bool) int

func DefaultEffort added in v0.10.5

func DefaultEffort() string

DefaultEffort returns the reasoning effort requested via WINGMAN_EFFORT. Empty (or "auto") leaves the provider default in place. Unrecognized values are ignored so a typo cannot silently pin an unexpected effort.

func DefaultModel added in v0.9.4

func DefaultModel() string

DefaultModel returns the model requested via environment; WINGMAN_MODEL takes priority over the OpenAI-standard OPENAI_DEFAULT_MODEL.

func SandboxDisabled added in v0.10.6

func SandboxDisabled() bool

Types

type Agent

type Agent struct {
	*Config

	Messages []Message
	Usage    Usage
	Revision uint64
	// contains filtered or unexported fields
}

func (*Agent) MessagesSnapshot added in v0.10.3

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

func (*Agent) QueueInput added in v0.10.9

func (a *Agent) QueueInput(input []Content) bool

QueueInput adds guidance to the active run. The agent consumes queued input at the next safe model boundary. It returns false when no run is active so callers can preserve the input as a normal follow-up instead.

func (*Agent) Send

func (a *Agent) Send(ctx context.Context, input []Content) (iter.Seq2[Message, error], error)

Send starts exactly one turn. It never queues implicitly: callers that want to guide the active turn must use QueueInput, while FIFO follow-ups belong in a caller-owned session orchestrator. Setup errors are returned immediately; failures after the turn starts are yielded by the returned stream.

func (*Agent) StateSnapshot added in v0.10.3

func (a *Agent) StateSnapshot() State

func (*Agent) UsageSnapshot added in v0.10.3

func (a *Agent) UsageSnapshot() Usage

type Config

type Config struct {
	Model        func() string
	Effort       func() string
	Tools        func() []tool.Tool
	Instructions func() string

	// CacheKey routes provider-side prompt caching; keep it stable per
	// conversation (e.g. the session ID) to maximize prefix-cache hits.
	CacheKey string

	Hooks hook.Hooks

	// MaxTurns caps successful model invocations in one Send run. Stream
	// retries and tool calls do not consume turns. Zero uses the default;
	// negative disables the safety bound.
	MaxTurns int

	// MaxParallelTools bounds concurrently executing read-only tool calls.
	// Zero uses the default; negative allows the whole emitted batch.
	MaxParallelTools int

	// ToolTimeout is a hard ceiling on every tool call. When zero, tools may
	// extend the default via tool.Tool.Timeout; negative disables deadlines.
	ToolTimeout time.Duration

	ContextWindow int

	// LargeContext compacts against the model's full hardware window instead
	// of stopping at the provider's long-context price threshold (e.g. 2x
	// input pricing on GPT-5.4/5.5 beyond 272k input tokens).
	LargeContext bool

	ReserveTokens int
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() (*Config, error)

func (*Config) Derive added in v0.6.2

func (c *Config) Derive() *Config

func (*Config) Models added in v0.6.9

func (c *Config) Models(ctx context.Context) ([]ModelInfo, error)

type Content

type Content struct {
	Text    string `json:"text,omitempty"`
	Refusal string `json:"refusal,omitempty"`

	File *File `json:"file,omitempty"`

	Reasoning *Reasoning `json:"reasoning,omitempty"`

	ToolCall   *ToolCall   `json:"tool_call,omitempty"`
	ToolResult *ToolResult `json:"tool_result,omitempty"`
}

func CloneContent added in v0.10.9

func CloneContent(in []Content) []Content

CloneContent returns an independent copy suitable for retaining after an API call. Content only contains value fields and one level of pointer fields.

type File

type File struct {
	Name string `json:"name,omitempty"`
	Data string `json:"data,omitempty"`
}

type Message

type Message struct {
	Role MessageRole `json:"role"`

	Content []Content `json:"content"`
	Hidden  bool      `json:"hidden,omitempty"`
}

type MessageRole

type MessageRole string
const (
	RoleUser      MessageRole = "user"
	RoleAssistant MessageRole = "assistant"
	RoleSystem    MessageRole = "system"
)

type ModelInfo added in v0.6.2

type ModelInfo struct {
	ID string
}

type Reasoning added in v0.6.2

type Reasoning struct {
	ID string `json:"id,omitempty"`

	Summary string `json:"summary,omitempty"`

	// Content is the provider's opaque (encrypted) reasoning payload, only
	// replayable to the model that produced it. Model tags the producer so the
	// agent loop can purge stale payloads when the session model changes.
	Content string `json:"content,omitempty"`
	Model   string `json:"model,omitempty"`
}

type State added in v0.6.2

type State struct {
	Usage    Usage     `json:"usage"`
	Messages []Message `json:"messages,omitempty"`
	Revision uint64    `json:"-"`
}

func (*State) Load added in v0.6.2

func (s *State) Load(path string) error

func (*State) Save added in v0.6.2

func (s *State) Save(path string) error

type ToolCall

type ToolCall struct {
	ID string `json:"id"`

	Name string `json:"name"`
	Args string `json:"args,omitempty"`
}

type ToolResult

type ToolResult struct {
	ID string `json:"id,omitempty"`

	Name string `json:"name"`
	Args string `json:"args,omitempty"`

	Content string `json:"content,omitempty"`
}

type Usage

type Usage struct {
	InputTokens  int64 `json:"input_tokens"`
	CachedTokens int64 `json:"cached_tokens"`
	OutputTokens int64 `json:"output_tokens"`

	// LastInputTokens is the input size of the most recent request — the
	// current context occupancy, unlike the cumulative counters above.
	LastInputTokens int64 `json:"last_input_tokens,omitempty"`
}

Directories

Path Synopsis
fs
lsp
mcp

Jump to

Keyboard shortcuts

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