Documentation
¶
Index ¶
- Constants
- Variables
- func ContextWindowFor(model string, largeContext bool) int
- func DefaultEffort() string
- func DefaultModel() string
- func DefaultPlanEffort() string
- func DefaultPlanModel() string
- func DefaultUtilityModel() string
- func EmitStreamEvent(ctx context.Context, event StreamEvent) bool
- func OutputSchemaFromContext(ctx context.Context) (map[string]any, bool)
- func SandboxDisabled() bool
- func WithOutputSchema(ctx context.Context, schema map[string]any) context.Context
- func WithStreamEventHandlers(ctx context.Context, handlers StreamEventHandlers) context.Context
- type Agent
- func (a *Agent) ContextStats() ContextStats
- func (a *Agent) MessagesSnapshot() []Message
- func (a *Agent) QueueInput(input []Content) bool
- func (a *Agent) Recap(ctx context.Context) (string, error)
- func (a *Agent) Running() bool
- func (a *Agent) Send(ctx context.Context, input []Content) (iter.Seq2[Message, error], error)
- func (a *Agent) StateSnapshot() State
- func (a *Agent) StateVersion() (messageCount int, revision uint64)
- func (a *Agent) UsageSnapshot() Usage
- type Config
- type Content
- type ContextStats
- type File
- type Message
- type MessageRole
- type ModelInfo
- type ModelOption
- type Reasoning
- type State
- type StreamEvent
- type StreamEventHandlers
- type ToolCall
- type ToolResult
- type ToolStat
- type Usage
Constants ¶
const ( DefaultMaxTurns = 400 DefaultMaxParallelTools = 8 DefaultToolTimeout = 10 * time.Minute DefaultContextWindow = 400_000 DefaultReserveTokens = 32_000 )
Variables ¶
var ErrEmptyInput = errors.New("agent input is empty")
ErrEmptyInput means Send was called without any content.
var ErrMaxTurnsExceeded = errors.New("agent: internal turn-loop safety bound exceeded — likely a runaway tool-call cycle")
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 DefaultEffort ¶ added in v0.10.5
func DefaultEffort() string
DefaultEffort returns the reasoning effort requested via WINGMAN_EFFORT. Empty (or "auto") leaves the role-based 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 DefaultPlanEffort ¶ added in v0.11.2
func DefaultPlanEffort() string
DefaultPlanEffort returns the reasoning effort for plan mode requested via WINGMAN_EFFORT_PLAN; empty uses the role-based default.
func DefaultPlanModel ¶ added in v0.11.2
func DefaultPlanModel() string
DefaultPlanModel returns the model for plan mode; empty selects the largest available model automatically.
func DefaultUtilityModel ¶ added in v0.11.2
func DefaultUtilityModel() string
DefaultUtilityModel returns the model for internal utility calls (recaps, compaction summaries); empty selects the smallest available automatically.
func EmitStreamEvent ¶ added in v0.12.9
func EmitStreamEvent(ctx context.Context, event StreamEvent) bool
EmitStreamEvent synchronously publishes a lifecycle event to the sink in ctx. It reports whether the consumer implements that exact event; agents must not retry after visible partial output unless Reset is implemented.
func OutputSchemaFromContext ¶ added in v0.12.18
OutputSchemaFromContext returns the turn's requested structured output.
func SandboxDisabled ¶ added in v0.10.6
func SandboxDisabled() bool
func WithOutputSchema ¶ added in v0.12.18
WithOutputSchema requests structured output for a turn. An empty schema uses the provider's native JSON-object mode; a non-empty schema uses strict JSON Schema output. A nil schema is treated as no structured-output request.
func WithStreamEventHandlers ¶ added in v0.12.9
func WithStreamEventHandlers(ctx context.Context, handlers StreamEventHandlers) context.Context
WithStreamEventHandlers installs synchronous lifecycle operations for an Agent.Send consumer. Handlers must return quickly.
Types ¶
type Agent ¶
type Agent struct {
*Config
Messages []Message
Usage Usage
Revision uint64
// contains filtered or unexported fields
}
func (*Agent) ContextStats ¶ added in v0.11.2
func (a *Agent) ContextStats() ContextStats
func (*Agent) MessagesSnapshot ¶ added in v0.10.3
func (*Agent) QueueInput ¶ added in v0.10.9
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) Recap ¶ added in v0.11.2
Recap produces a short user-facing briefing of the conversation so far, for returning to a resumed session.
func (*Agent) Send ¶
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 (*Agent) StateVersion ¶ added in v0.12.9
StateVersion returns retained-history metadata without cloning messages.
func (*Agent) UsageSnapshot ¶ added in v0.10.3
type Config ¶
type Config struct {
Model func() string
Effort func() string
Tools func() []tool.Tool
Instructions func() string
// UtilityModel, when set and non-empty, handles internal utility calls
// (compaction summaries, recaps) instead of the main model.
UtilityModel func() string
// SubagentModel resolves a model role for per-subagent overrides: "plan"
// and "utility" name the session's role models, "" the currently
// inherited model (consulted for effort clamping). ok=false or an empty
// ID keep the inherited model. Nil disables overrides and clamping.
SubagentModel func(role string) (ModelOption, bool)
// 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 ¶
type Content ¶
type Content struct {
Text string `json:"text,omitempty"`
// TextID is source-local identity used to reconcile streamed and retained
// UI content. It is metadata, not a provider payload to replay in requests.
TextID string `json:"text_id,omitempty"`
Refusal string `json:"refusal,omitempty"`
// Hidden marks injected context (e.g. background-task notifications) that
// the model must see but UIs must not render as user input. A user message
// whose content is entirely hidden becomes a hidden message.
Hidden bool `json:"hidden,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
CloneContent returns an independent copy suitable for retaining after an API call. Content only contains value fields and one level of pointer fields.
type ContextStats ¶ added in v0.11.2
type ContextStats struct {
Model string
Window int
InstructionsTokens int
ToolsTokens int
ToolStats []ToolStat
MessagesTokens int
MessageCount int
LastInputTokens int64
}
ContextStats estimates what occupies the model's context window, by category. Token counts are byte-based approximations (~4 bytes/token); LastInputTokens is the provider-reported figure for the latest request.
func (ContextStats) EstimatedTotal ¶ added in v0.11.2
func (s ContextStats) EstimatedTotal() int
type Message ¶
type Message struct {
Role MessageRole `json:"role"`
Content []Content `json:"content"`
Hidden bool `json:"hidden,omitempty"`
}
func CloneMessages ¶ added in v0.12.0
CloneMessages returns a deep-enough copy for handing message snapshots to callers while another goroutine may continue streaming into retained state.
type MessageRole ¶
type MessageRole string
const ( RoleUser MessageRole = "user" RoleAssistant MessageRole = "assistant" RoleSystem MessageRole = "system" )
type ModelOption ¶ added in v0.11.4
ModelOption is a resolved model for a per-subagent override. MinEffort and MaxEffort bound the reasoning efforts the model supports; empty means unbounded on that side.
type Reasoning ¶ added in v0.6.2
type Reasoning struct {
ID string `json:"id,omitempty"`
Summary string `json:"summary,omitempty"`
// Part indexes the summary part a streamed delta belongs to; renderers
// separate parts however suits their medium.
Part int `json:"part,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 StreamEvent ¶ added in v0.12.9
type StreamEvent uint8
StreamEvent describes a lifecycle boundary in an Agent.Send stream. These events are separate from Message because they are transport concerns, not conversational content that can be retained or sent back to a model.
const ( // StreamEventReset asks a consumer to discard visible deltas from the // current failed attempt before the agent retries the request. StreamEventReset StreamEvent = iota + 1 // StreamEventCommit marks the current streamed attempt as accepted into // retained history. A later retry reset must not discard its output. StreamEventCommit )
type StreamEventHandlers ¶ added in v0.12.9
type StreamEventHandlers struct {
Reset func()
Commit func()
}
StreamEventHandlers declares the lifecycle operations a stream consumer can actually perform. In particular, a non-nil Reset is a capability promise: the consumer can discard every delta from the failed attempt before Send retries it.
type ToolResult ¶
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"`
// ContextWindow is the provider-reported maximum context size when the
// transport supplies it directly.
ContextWindow int64 `json:"context_window,omitempty"`
}