Documentation
¶
Overview ¶
Package agentcore contains the host-facing Agent API and the advanced ReAct runtime used to execute it.
Most applications should use NewAgent, Agent.Run, Agent.RunDetailed, RunRequest, RunResult, options, events, budgets, skills, and module providers. The stage pipeline, RunState, ReActRunner, and individual stage types are exported for tests and specialized runtime composition, but hosts should prefer Agent unless they are intentionally replacing the default loop.
Index ¶
- Variables
- type ActStage
- type Agent
- func (a *Agent) Resume(ctx context.Context, checkpoint RunCheckpoint, ...) (*RunResult, error)
- func (a *Agent) ResumeDetailed(ctx context.Context, checkpoint RunCheckpoint, ...) (*RunResult, error)
- func (a *Agent) Run(ctx context.Context, req RunRequest) (*RunResult, error)
- func (a *Agent) RunDetailed(ctx context.Context, req RunRequest) (*RunResult, error)
- func (a *Agent) Stream(ctx context.Context, req RunRequest) *RunStream
- type ApprovalStage
- type Budget
- type BudgetDecision
- type BudgetGuard
- type BudgetStage
- type CheckpointRequest
- type ContextProjectionRequest
- type ContextProjectionResult
- type ContextProjectionStage
- type ContextProjector
- type ContextStage
- type Event
- type EventSink
- type EventType
- type ExecutionSummary
- type FinalizeStage
- type InputGuard
- type InputGuardFunc
- type InputGuardRequest
- type InputGuardStage
- type MemoryLoadStage
- type Message
- type ModelDelta
- type Module
- type MutableToolRegistry
- type ObserveStage
- type Option
- func WithBudget(budget Budget) Option
- func WithBudgetGuard(guard BudgetGuard) Option
- func WithContextProjector(projector ContextProjector) Option
- func WithEventSink(sink EventSink) Option
- func WithInputGuard(guard InputGuard) Option
- func WithLLM(llm ports.LLMClient) Option
- func WithMaxIterations(maxIterations int) Option
- func WithMaxOutputTokens(maxOutputTokens int) Option
- func WithMemoryProvider(provider ports.MemoryProvider) Option
- func WithModule(module Module) Option
- func WithOutputFormat(format OutputFormat) Option
- func WithOutputValidator(validator OutputValidator) Option
- func WithPolicyEngine(engine ports.PolicyEngine) Option
- func WithPromptBlocks(blocks []prompt.Block) Option
- func WithPromptCompiler(c ports.PromptCompiler) Option
- func WithSkillProvider(provider SkillProvider) Option
- func WithSystemPromptProvider(provider SystemPromptProvider) Option
- func WithToolApprover(approver ToolApprover) Option
- func WithToolProvider(provider ToolProvider) Option
- func WithToolRegistry(r ports.ToolRegistry) Option
- type OutputFormat
- type OutputFormatStage
- type OutputValidationRequest
- type OutputValidationResult
- type OutputValidator
- type OutputValidatorFunc
- type Pipeline
- type PolicyStage
- type PromptStage
- type ReActConfig
- type ReActRunner
- type ResolvedApprovalStage
- type RunCheckpoint
- type RunID
- type RunRequest
- type RunResult
- type RunState
- type RunStream
- type RunStreamEvent
- type Skill
- type SkillProvider
- type SkillStage
- type Stage
- type StageResult
- type SystemPromptProvider
- type SystemPromptStage
- type ThinkStage
- type ToolApprovalDecision
- type ToolApprovalInterruption
- type ToolApprovalRequest
- type ToolApprovalResolution
- type ToolApprover
- type ToolProvider
- type ToolProviderStage
- type Usage
Constants ¶
This section is empty.
Variables ¶
var ( // ErrApprovalPending reports that a host must resolve pending tool calls before execution can continue. ErrApprovalPending = errors.New("approval pending") // ErrInvalidRunCheckpoint reports a malformed, unsupported, or incomplete checkpoint. ErrInvalidRunCheckpoint = errors.New("invalid run checkpoint") // ErrInvalidApprovalResolution reports resolutions that do not exactly match the pending call batch. ErrInvalidApprovalResolution = errors.New("invalid approval resolution") )
var ErrApprovalDenied = errors.New("approval denied")
var ErrBudgetExceeded = errors.New("budget exceeded")
var ErrInputRejected = errors.New("input rejected")
var ErrMaxIterations = errors.New("max iterations reached")
var ErrMissingLLM = errors.New("agent requires LLM client")
var ErrOutputInvalid = errors.New("output invalid")
var ErrPolicyDenied = errors.New("policy denied")
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
func (*Agent) Resume ¶
func (a *Agent) Resume(ctx context.Context, checkpoint RunCheckpoint, resolutions []ToolApprovalResolution) (*RunResult, error)
Resume continues a run interrupted by pending tool approval. It returns a nil result with ErrApprovalPending when another approval is required.
func (*Agent) ResumeDetailed ¶
func (a *Agent) ResumeDetailed(ctx context.Context, checkpoint RunCheckpoint, resolutions []ToolApprovalResolution) (*RunResult, error)
ResumeDetailed continues a run interrupted by pending tool approval and preserves partial results on errors. A request-scoped ToolProvider must recreate the same tools for the checkpoint request.
func (*Agent) RunDetailed ¶
type ApprovalStage ¶
type ApprovalStage struct {
Approver ToolApprover
}
func (ApprovalStage) Name ¶
func (s ApprovalStage) Name() string
func (ApprovalStage) Run ¶
func (s ApprovalStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type BudgetDecision ¶
type BudgetGuard ¶
type BudgetGuard interface {
Check(ctx context.Context, state *RunState) BudgetDecision
}
func NewBudgetGuard ¶
func NewBudgetGuard(budget Budget) BudgetGuard
type BudgetStage ¶
type BudgetStage struct {
Guard BudgetGuard
}
func (BudgetStage) Name ¶
func (s BudgetStage) Name() string
func (BudgetStage) Run ¶
func (s BudgetStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type CheckpointRequest ¶
type CheckpointRequest struct {
Input string `json:"input"`
UserID string `json:"user_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
AllowedPermissions []policy.Permission `json:"allowed_permissions,omitempty"`
PolicyContext ports.PolicyContext `json:"policy_context"`
}
CheckpointRequest is the JSON-safe request context retained for a paused run. It intentionally keeps the Run ID in RunCheckpoint so that its JSON form is a string.
type ContextProjectionResult ¶
type ContextProjectionStage ¶
type ContextProjectionStage struct {
Projector ContextProjector
Budget Budget
}
func (ContextProjectionStage) Name ¶
func (s ContextProjectionStage) Name() string
func (ContextProjectionStage) Run ¶
func (s ContextProjectionStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type ContextProjector ¶
type ContextProjector interface {
Project(ctx context.Context, req ContextProjectionRequest) (*ContextProjectionResult, error)
}
type ContextStage ¶
type ContextStage struct{}
func (ContextStage) Name ¶
func (s ContextStage) Name() string
func (ContextStage) Run ¶
func (s ContextStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type EventType ¶
type EventType string
const ( EventStageStarted EventType = "stage.started" EventStageCompleted EventType = "stage.completed" EventStageFailed EventType = "stage.failed" EventToolStarted EventType = "tool.started" EventToolCompleted EventType = "tool.completed" EventToolFailed EventType = "tool.failed" EventToolRejected EventType = "tool.rejected" EventMemoryLoaded EventType = "memory.loaded" EventMemorySaved EventType = "memory.saved" EventFinalized EventType = "finalized" EventOutputValidated EventType = "output.validated" EventInputValidated EventType = "input.validated" EventInputRejected EventType = "input.rejected" EventApprovalRequested EventType = "approval.requested" EventApprovalCompleted EventType = "approval.completed" EventApprovalDenied EventType = "approval.denied" EventApprovalPending EventType = "approval.pending" )
type ExecutionSummary ¶
type FinalizeStage ¶
type FinalizeStage struct {
OutputFormat OutputFormat
OutputValidator OutputValidator
}
func (FinalizeStage) Name ¶
func (s FinalizeStage) Name() string
func (FinalizeStage) Run ¶
func (s FinalizeStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type InputGuard ¶
type InputGuard interface {
ValidateInput(context.Context, InputGuardRequest) error
}
InputGuard screens one raw run request. It must not call tools or mutate external state.
type InputGuardFunc ¶
type InputGuardFunc func(context.Context, InputGuardRequest) error
InputGuardFunc adapts a function to InputGuard.
func (InputGuardFunc) ValidateInput ¶
func (f InputGuardFunc) ValidateInput(ctx context.Context, req InputGuardRequest) error
type InputGuardRequest ¶
type InputGuardRequest struct {
RunID RunID
Input string
Metadata map[string]any
PolicyContext ports.PolicyContext
}
InputGuardRequest is the host-visible request boundary before memory, context, model, or tools run.
type InputGuardStage ¶
type InputGuardStage struct {
Guard InputGuard
}
InputGuardStage runs the host guard once before memory and context are populated.
func (InputGuardStage) Name ¶
func (s InputGuardStage) Name() string
func (InputGuardStage) Run ¶
func (s InputGuardStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type MemoryLoadStage ¶
type MemoryLoadStage struct {
Provider ports.MemoryProvider
}
func (MemoryLoadStage) Name ¶
func (s MemoryLoadStage) Name() string
func (MemoryLoadStage) Run ¶
func (s MemoryLoadStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type ModelDelta ¶
ModelDelta is a piece of model output streamed while a call runs, when the Agent's LLM implements ports.StreamingLLMClient. Iteration identifies the model call. Deltas reach only the stream, never the Agent's EventSink.
type Module ¶
type Module interface {
SystemPromptProvider
SkillProvider
ToolProvider
}
type MutableToolRegistry ¶
type MutableToolRegistry interface {
ports.ToolRegistry
Register(tool tools.Tool)
}
MutableToolRegistry is the per-run registry shape used by stages that both read configured tools and register request-scoped tools.
type ObserveStage ¶
type ObserveStage struct{}
func (ObserveStage) Name ¶
func (s ObserveStage) Name() string
func (ObserveStage) Run ¶
func (s ObserveStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type Option ¶
type Option func(*Agent)
func WithBudget ¶
func WithBudgetGuard ¶
func WithBudgetGuard(guard BudgetGuard) Option
func WithContextProjector ¶
func WithContextProjector(projector ContextProjector) Option
func WithEventSink ¶
func WithInputGuard ¶
func WithInputGuard(guard InputGuard) Option
WithInputGuard screens raw requests before memory, context, model, or tool execution.
func WithMaxIterations ¶
func WithMaxOutputTokens ¶
WithMaxOutputTokens caps generated tokens per model call.
func WithMemoryProvider ¶
func WithMemoryProvider(provider ports.MemoryProvider) Option
func WithModule ¶
func WithOutputFormat ¶
func WithOutputFormat(format OutputFormat) Option
func WithOutputValidator ¶
func WithOutputValidator(validator OutputValidator) Option
func WithPolicyEngine ¶
func WithPolicyEngine(engine ports.PolicyEngine) Option
func WithPromptBlocks ¶
func WithPromptCompiler ¶
func WithPromptCompiler(c ports.PromptCompiler) Option
func WithSkillProvider ¶
func WithSkillProvider(provider SkillProvider) Option
func WithSystemPromptProvider ¶
func WithSystemPromptProvider(provider SystemPromptProvider) Option
func WithToolApprover ¶
func WithToolApprover(approver ToolApprover) Option
func WithToolProvider ¶
func WithToolProvider(provider ToolProvider) Option
func WithToolRegistry ¶
func WithToolRegistry(r ports.ToolRegistry) Option
type OutputFormat ¶
type OutputFormat struct {
Name string
Description string
Instructions string
JSONSchema json.RawMessage
}
OutputFormat describes the final answer shape the host wants the model to produce. JSONSchema is both prompt guidance and a local validation contract.
func (OutputFormat) IsZero ¶
func (f OutputFormat) IsZero() bool
type OutputFormatStage ¶
type OutputFormatStage struct {
Format OutputFormat
}
OutputFormatStage adds final-output instructions before the prompt is compiled. Validation still happens later in FinalizeStage.
func (OutputFormatStage) Name ¶
func (s OutputFormatStage) Name() string
func (OutputFormatStage) Run ¶
func (s OutputFormatStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type OutputValidationRequest ¶
type OutputValidationRequest struct {
RunID RunID
Content string
Format OutputFormat
Metadata map[string]any
}
OutputValidationRequest is passed to host validators after the model returns a final answer and before the answer is saved to memory.
type OutputValidationResult ¶
type OutputValidationResult struct {
Structured json.RawMessage
Metadata map[string]any
}
OutputValidationResult lets custom validators attach parsed output or small validation metadata to the final RunResult.
type OutputValidator ¶
type OutputValidator interface {
ValidateOutput(context.Context, OutputValidationRequest) (*OutputValidationResult, error)
}
OutputValidator is a host-owned final-answer guardrail. It should validate output shape or safety, not call tools or mutate external state.
type OutputValidatorFunc ¶
type OutputValidatorFunc func(context.Context, OutputValidationRequest) (*OutputValidationResult, error)
func (OutputValidatorFunc) ValidateOutput ¶
func (f OutputValidatorFunc) ValidateOutput(ctx context.Context, req OutputValidationRequest) (*OutputValidationResult, error)
type Pipeline ¶
type Pipeline struct {
// contains filtered or unexported fields
}
func NewPipeline ¶
type PolicyStage ¶
type PolicyStage struct {
Engine ports.PolicyEngine
ToolRegistry ports.ToolRegistry
}
func (PolicyStage) Name ¶
func (s PolicyStage) Name() string
func (PolicyStage) Run ¶
func (s PolicyStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type PromptStage ¶
type PromptStage struct {
Compiler ports.PromptCompiler
Blocks []prompt.Block
}
func (PromptStage) Name ¶
func (s PromptStage) Name() string
func (PromptStage) Run ¶
func (s PromptStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type ReActConfig ¶
type ReActConfig struct {
LLM ports.LLMClient
PromptCompiler ports.PromptCompiler
PromptBlocks []prompt.Block
ToolRegistry MutableToolRegistry
PolicyEngine ports.PolicyEngine
MemoryProvider ports.MemoryProvider
SkillProvider SkillProvider
SystemPromptProvider SystemPromptProvider
ToolProvider ToolProvider
ContextProjector ContextProjector
InputGuard InputGuard
ToolApprover ToolApprover
OutputFormat OutputFormat
OutputValidator OutputValidator
BudgetGuard BudgetGuard
MaxIterations int
// MaxOutputTokens caps generated tokens per model call; zero leaves it to the provider.
MaxOutputTokens int
}
type ReActRunner ¶
type ReActRunner struct {
// contains filtered or unexported fields
}
func NewReActRunner ¶
func NewReActRunner(config ReActConfig) *ReActRunner
func (*ReActRunner) Run ¶
func (r *ReActRunner) Run(ctx context.Context, state *RunState) (StageResult, error)
type ResolvedApprovalStage ¶
type ResolvedApprovalStage struct {
Resolutions []ToolApprovalResolution
}
ResolvedApprovalStage verifies a complete host decision set before allowing a paused batch to execute.
func (ResolvedApprovalStage) Name ¶
func (s ResolvedApprovalStage) Name() string
func (ResolvedApprovalStage) Run ¶
func (s ResolvedApprovalStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type RunCheckpoint ¶
type RunCheckpoint struct {
Version int `json:"version"`
RunID string `json:"run_id"`
Request CheckpointRequest `json:"request"`
Iteration int `json:"iteration"`
Messages []Message `json:"messages"`
Usage Usage `json:"usage"`
LLMCalls int `json:"llm_calls"`
ToolCalls int `json:"tool_calls"`
UsedTools []string `json:"used_tools,omitempty"`
StartedAt time.Time `json:"started_at"`
Metadata map[string]any `json:"metadata"`
AllowedPermissions []policy.Permission `json:"allowed_permissions"`
PendingCalls []ports.ToolCall `json:"pending_calls"`
PromptBlocks []prompt.Block `json:"prompt_blocks"`
}
RunCheckpoint is a versioned, JSON-serializable snapshot of a run paused before tool execution. It includes raw user content and tool inputs, so hosts must store it as sensitive data.
type RunID ¶
func RunIDFromString ¶
type RunRequest ¶
type RunRequest struct {
RunID RunID
Input string
UserID string
SessionID string
Metadata map[string]any
AllowedPermissions []policy.Permission
PolicyContext ports.PolicyContext
}
type RunResult ¶
type RunResult struct {
RunID RunID
Content string
StructuredOutput json.RawMessage
OutputMetadata map[string]any
Usage Usage
ExecutionSummary ExecutionSummary
Interruption *ToolApprovalInterruption
}
type RunState ¶
type RunState struct {
RunID RunID
Input RunRequest
Iteration int
Messages []Message
Final *RunResult
Usage Usage
Metadata map[string]any
EventSink EventSink
PromptBlocks []prompt.Block
CompiledPrompt *prompt.Compiled
ContextProjection *ContextProjectionResult
LastResponse *ports.ChatResponse
PendingCalls []tools.Call
ToolResults []tools.Execution
AllowedPermissions []policy.Permission
// contains filtered or unexported fields
}
func NewRunState ¶
func NewRunState(runID RunID, req RunRequest) *RunState
type RunStream ¶
type RunStream struct {
Events <-chan RunStreamEvent
// contains filtered or unexported fields
}
func (*RunStream) DiscardEvents ¶
func (s *RunStream) DiscardEvents()
DiscardEvents stops public event delivery without canceling the Agent run. Call it when Events will not be drained; repeated calls are safe.
type RunStreamEvent ¶
type RunStreamEvent struct {
Event Event
Delta *ModelDelta
Result *RunResult
Error error
Done bool
}
RunStreamEvent carries one of: a run Event, a ModelDelta of streamed model output, or, when Done is set, the run's Result and Error.
type SkillProvider ¶
type SkillProvider interface {
Skills(ctx context.Context, req RunRequest) ([]Skill, error)
}
type SkillStage ¶
type SkillStage struct {
Provider SkillProvider
}
func (SkillStage) Name ¶
func (s SkillStage) Name() string
func (SkillStage) Run ¶
func (s SkillStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type StageResult ¶
type StageResult int
const ( StageContinue StageResult = iota StageBreak StageAbort StageInterrupt )
type SystemPromptProvider ¶
type SystemPromptStage ¶
type SystemPromptStage struct {
Provider SystemPromptProvider
}
func (SystemPromptStage) Name ¶
func (s SystemPromptStage) Name() string
func (SystemPromptStage) Run ¶
func (s SystemPromptStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type ThinkStage ¶
type ThinkStage struct {
LLM ports.LLMClient
ToolRegistry ports.ToolRegistry
MaxOutputTokens int
}
func (ThinkStage) Name ¶
func (s ThinkStage) Name() string
func (ThinkStage) Run ¶
func (s ThinkStage) Run(ctx context.Context, state *RunState) (StageResult, error)
type ToolApprovalDecision ¶
type ToolApprovalDecision struct {
Allowed bool
// Pending takes precedence over Allowed so an ambiguous decision cannot execute a tool.
Pending bool
Reason string
}
ToolApprovalDecision is a synchronous allow, deny, or pending decision for one tool call.
type ToolApprovalInterruption ¶
type ToolApprovalInterruption struct {
Checkpoint RunCheckpoint `json:"checkpoint"`
}
ToolApprovalInterruption exposes the checkpoint required to continue a pending approval.
type ToolApprovalRequest ¶
type ToolApprovalResolution ¶
type ToolApprovalResolution struct {
Index int `json:"index"`
ToolCallID string `json:"tool_call_id"`
Tool string `json:"tool"`
Allowed bool `json:"allowed"`
Reason string `json:"reason,omitempty"`
}
ToolApprovalResolution is a host decision for one checkpointed pending call. Index, ToolCallID, and Tool must exactly match the original call.
type ToolApprover ¶
type ToolApprover interface {
ApproveTool(ctx context.Context, req ToolApprovalRequest) ToolApprovalDecision
}
type ToolProvider ¶
ToolProvider returns request-scoped tools. Providers used with approval checkpoints must recreate the same valid tools for the checkpoint request.
type ToolProviderStage ¶
type ToolProviderStage struct {
Provider ToolProvider
Registry interface {
Register(tool tools.Tool)
}
}
func (ToolProviderStage) Name ¶
func (s ToolProviderStage) Name() string
func (ToolProviderStage) Run ¶
func (s ToolProviderStage) Run(ctx context.Context, state *RunState) (StageResult, error)
Source Files
¶
- act_stage.go
- agent.go
- approval.go
- budget.go
- budget_stage.go
- checkpoint.go
- context_projection.go
- context_stage.go
- doc.go
- events.go
- finalize_stage.go
- id.go
- input_guard.go
- memory_stage.go
- module.go
- observe_stage.go
- output.go
- pipeline.go
- policy_stage.go
- prompt_stage.go
- request.go
- resume_stage.go
- run_state.go
- skill.go
- skill_stage.go
- stage.go
- stream.go
- system_prompt_stage.go
- think_stage.go
- tool_provider_stage.go
- tool_registry.go