Documentation
¶
Overview ¶
Package agent implements ub's headless provider/tool loop.
Index ¶
- Variables
- func SummarizeToolInput(name string, raw json.RawMessage) string
- type ActivityKind
- type Agent
- type CompactRequest
- type CompactResult
- type Event
- type EventSink
- type EventType
- type LimitAsker
- type LimitExtensionRequest
- type LimitExtensionResponse
- type Options
- type Request
- type Result
- type RuntimeContext
Constants ¶
This section is empty.
Variables ¶
var ErrMaxTurns = errors.New("agent: max turns reached")
ErrMaxTurns is returned when a run exceeds its provider/tool loop limit.
Functions ¶
func SummarizeToolInput ¶ added in v0.1.2
func SummarizeToolInput(name string, raw json.RawMessage) string
Types ¶
type ActivityKind ¶
type ActivityKind string
ActivityKind identifies a structured Agent activity event.
const ( ActivityThinking ActivityKind = "thinking" ActivityTool ActivityKind = "tool" ActivityPermission ActivityKind = "permission" ActivityNotice ActivityKind = "notice" )
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent runs a single headless agent loop.
func (*Agent) Compact ¶
func (a *Agent) Compact(ctx context.Context, req CompactRequest) (CompactResult, error)
Compact manually summarizes earlier history without checking the automatic trigger threshold.
type CompactRequest ¶
CompactRequest is one manual context compact request.
type CompactResult ¶
type CompactResult struct {
Messages []message.Message
Summary string
CompactedMessages int
KeptMessages int
EstimatedTokens int
Noop bool
Reason string
}
CompactResult reports the result of a manual context compact request.
type Event ¶
type Event struct {
Type EventType
Text string
ToolUseID string
ToolName string
Content string
ActivityKind ActivityKind
Status string
Summary string
Decision string
Source string
Reason string
Allowed bool
IsError bool
Err error
ContextUsedTokens int
ContextMaxTokens int
ContextRatio float64
ContextReset bool
ContextKind string
}
Event reports Agent progress to interactive callers such as the TUI.
type EventSink ¶
type EventSink func(Event)
EventSink receives Agent runtime events in emission order.
type EventType ¶
type EventType string
EventType identifies an Agent runtime event.
const ( EventDeltaText EventType = "delta_text" EventActivity EventType = "activity" EventContext EventType = "context" EventToolCallStart EventType = "tool_call_start" EventToolCallEnd EventType = "tool_call_end" EventPermission EventType = "permission" EventDone EventType = "done" EventError EventType = "error" )
type LimitAsker ¶ added in v0.1.2
type LimitAsker interface {
// AskExtension blocks until the host responds. Return ExtraTurns > 0 to
// extend the loop; return 0 (or zero-value response) to fall through to
// the no-tool finalize path. An error aborts the run.
AskExtension(ctx context.Context, req LimitExtensionRequest) (LimitExtensionResponse, error)
}
LimitAsker lets the agent pause when a tool-loop run hits the max-turns cap and ask the host for permission to keep going. Without it the loop silently falls through to finalizeWithoutTools, which is awkward for reasoning models that still want to call tools.
type LimitExtensionRequest ¶ added in v0.1.2
LimitExtensionRequest describes the limit-extension prompt.
type LimitExtensionResponse ¶ added in v0.1.2
type LimitExtensionResponse struct {
ExtraTurns int
}
LimitExtensionResponse carries the host's decision.
type Options ¶
type Options struct {
Provider provider.Provider
Tools *tool.Registry
Permission *permission.Manager
Rollout rollout.Writer
Model string
Mode execution.Mode
ModeFunc func() execution.Mode
MaxTurns int
LimitAsker LimitAsker
Events EventSink
Reasoning *reasoning.Config
MaxContextTokens int
SummaryProvider provider.Provider
SummaryModel string
Context config.ContextConfig
Runtime RuntimeContext
ToolOutputState string
}
Options configures an Agent.
type RuntimeContext ¶
RuntimeContext describes the local execution environment for one agent run. It is sent to providers on every request but is not persisted in rollout history.