Documentation
¶
Overview ¶
Package agent implements the Observe-Think-Act agent loop and stateful runtime.
Index ¶
- Constants
- Variables
- type AfterToolCallFn
- type AfterToolContext
- type AfterToolResult
- type Agent
- func (a *Agent) Abort()
- func (a *Agent) ApplyConfig(fn func(*Config))
- func (a *Agent) ApplyState(fn func(*Context))
- func (a *Agent) Config() Config
- func (a *Agent) Continue(ctx context.Context) (*agentevent.Stream, error)
- func (a *Agent) FollowUp(message AgentMessage)
- func (a *Agent) Prompt(ctx context.Context, prompts ...AgentMessage) (*agentevent.Stream, error)
- func (a *Agent) SetActiveTools(names []string)
- func (a *Agent) SetModel(model llms.Model)
- func (a *Agent) SetTools(registry *tool.Registry)
- func (a *Agent) State() *Context
- func (a *Agent) Steer(message AgentMessage)
- func (a *Agent) Subscribe(handler agentevent.Handler)
- type AgentMessage
- type AssistantMessage
- type BeforeToolCallFn
- type BeforeToolContext
- type BeforeToolResult
- type BranchSummaryMessage
- type CompactionSummaryMessage
- type Config
- type ContentPart
- type Context
- type ConvertToLLMFn
- type CustomMessage
- type GetMessagesFn
- type ImagePart
- type LoopDeps
- type MessageRole
- type Options
- type PrepareNextTurnFn
- type QueueMode
- type ShouldStopAfterTurnFn
- type StopReason
- type TextPart
- type ToolCallPart
- type ToolExecutionMode
- type ToolResultMessage
- type TransformContextFn
- type TurnContext
- type TurnUpdate
- type Usage
- type UserMessage
Constants ¶
const ( RoleUser = msg.RoleUser RoleAssistant = msg.RoleAssistant RoleToolResult = msg.RoleToolResult RoleCustom = msg.RoleCustom RoleBranchSummary = msg.RoleBranchSummary RoleCompactionSummary = msg.RoleCompactionSummary ToolExecutionParallel = msg.ToolExecutionParallel ToolExecutionSequential = msg.ToolExecutionSequential QueueAll = msg.QueueAll QueueOne = msg.QueueOne StopReasonComplete = msg.StopReasonComplete StopReasonError = msg.StopReasonError StopReasonAborted = msg.StopReasonAborted )
Variables ¶
var ( ErrMaxSteps = msg.ErrMaxSteps ErrAborted = msg.ErrAborted ErrToolNotFound = msg.ErrToolNotFound ErrEmptyContext = msg.ErrEmptyContext ErrInvalidContinue = msg.ErrInvalidContinue )
Functions ¶
This section is empty.
Types ¶
type AfterToolCallFn ¶
type AfterToolCallFn = msg.AfterToolCallFn
type AfterToolContext ¶
type AfterToolContext = msg.AfterToolContext
type AfterToolResult ¶
type AfterToolResult = msg.AfterToolResult
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent is a stateful wrapper around the agent loop with queues and subscriptions.
func (*Agent) ApplyConfig ¶
ApplyConfig atomically mutates loop configuration before the next Prompt or Continue. Callers must preserve queue drains when replacing the whole struct.
func (*Agent) ApplyState ¶
ApplyState atomically mutates the agent's internal state using the provided function. This avoids the clone-modify-discard pattern when the caller needs to update state in place.
func (*Agent) FollowUp ¶
func (a *Agent) FollowUp(message AgentMessage)
FollowUp enqueues a message injected after the inner loop completes.
func (*Agent) Prompt ¶
func (a *Agent) Prompt(ctx context.Context, prompts ...AgentMessage) (*agentevent.Stream, error)
Prompt starts a new loop turn with one or more user messages.
func (*Agent) SetActiveTools ¶
SetActiveTools restricts which registered tools are exposed to the model.
func (*Agent) Steer ¶
func (a *Agent) Steer(message AgentMessage)
Steer enqueues a message injected between inner-loop turns.
func (*Agent) Subscribe ¶
func (a *Agent) Subscribe(handler agentevent.Handler)
Subscribe registers a lifecycle event handler.
type AgentMessage ¶
type AgentMessage = msg.AgentMessage
func RunLoop ¶
func RunLoop(ctx context.Context, prompts []AgentMessage, agentCtx *Context, cfg Config, deps LoopDeps, stream *agentevent.Stream) ([]AgentMessage, error)
RunLoop starts a new agent loop from prompt messages.
func RunLoopContinue ¶
func RunLoopContinue(ctx context.Context, agentCtx *Context, cfg Config, deps LoopDeps, stream *agentevent.Stream) ([]AgentMessage, error)
RunLoopContinue resumes a loop from existing context without adding prompts.
type AssistantMessage ¶
type AssistantMessage = msg.AssistantMessage
type BeforeToolCallFn ¶
type BeforeToolCallFn = msg.BeforeToolCallFn
type BeforeToolContext ¶
type BeforeToolContext = msg.BeforeToolContext
type BeforeToolResult ¶
type BeforeToolResult = msg.BeforeToolResult
type BranchSummaryMessage ¶
type BranchSummaryMessage = msg.BranchSummaryMessage
type CompactionSummaryMessage ¶
type CompactionSummaryMessage = msg.CompactionSummaryMessage
type Config ¶
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns conservative defaults for a new agent run.
type ContentPart ¶
type ContentPart = msg.ContentPart
type ConvertToLLMFn ¶
type ConvertToLLMFn = msg.ConvertToLLMFn
type CustomMessage ¶
type CustomMessage = msg.CustomMessage
type GetMessagesFn ¶
type GetMessagesFn = msg.GetMessagesFn
type MessageRole ¶
type MessageRole = msg.MessageRole
type Options ¶
type Options struct {
InitialState *Context
Config Config
Model llms.Model
Registry *tool.Registry
}
Options configures a new Agent instance.
type PrepareNextTurnFn ¶
type PrepareNextTurnFn = msg.PrepareNextTurnFn
type ShouldStopAfterTurnFn ¶
type ShouldStopAfterTurnFn = msg.ShouldStopAfterTurnFn
type StopReason ¶
type StopReason = msg.StopReason
type ToolCallPart ¶
type ToolCallPart = msg.ToolCallPart
type ToolExecutionMode ¶
type ToolExecutionMode = msg.ToolExecutionMode
type ToolResultMessage ¶
type ToolResultMessage = msg.ToolResultMessage
type TransformContextFn ¶
type TransformContextFn = msg.TransformContextFn
type TurnContext ¶
type TurnContext = msg.TurnContext
type TurnUpdate ¶
type TurnUpdate = msg.TurnUpdate
type UserMessage ¶
type UserMessage = msg.UserMessage
func NewUserMessage ¶
func NewUserMessage(text string) UserMessage
NewUserMessage builds a text user message with the current timestamp.
func NewUserMessageWithParts ¶
func NewUserMessageWithParts(parts ...ContentPart) UserMessage
NewUserMessageWithParts builds a multimodal user message.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package coding provides agent tools for terminal control, file I/O, web search, and code execution.
|
Package coding provides agent tools for terminal control, file I/O, web search, and code execution. |
|
Package ctxmgr manages agent context budgets, compaction, and branch summarization.
|
Package ctxmgr manages agent context budgets, compaction, and branch summarization. |
|
Package env provides filesystem and shell execution with Result-based error handling.
|
Package env provides filesystem and shell execution with Result-based error handling. |
|
Package event provides lifecycle event streaming for agent runs.
|
Package event provides lifecycle event streaming for agent runs. |
|
example
|
|
|
echo
Package echo provides a reference echo tool for agent examples.
|
Package echo provides a reference echo tool for agent examples. |
|
Package harness orchestrates agent runs with hooks, tools, and session persistence.
|
Package harness orchestrates agent runs with hooks, tools, and session persistence. |
|
Package hooks provides typed agent hook registration, emission, and loop Config bridging.
|
Package hooks provides typed agent hook registration, emission, and loop Config bridging. |
|
Package llm adapts langchaingo models for the agent loop and single-shot module tasks.
|
Package llm adapts langchaingo models for the agent loop and single-shot module tasks. |
|
Package model provides built-in LLM metadata and dual-model routing.
|
Package model provides built-in LLM metadata and dual-model routing. |
|
Package msg defines shared agent domain types used across subpackages.
|
Package msg defines shared agent domain types used across subpackages. |
|
Package permission evaluates tool invocation permissions with OpenCode-compatible rules.
|
Package permission evaluates tool invocation permissions with OpenCode-compatible rules. |
|
Package result provides a discriminated Result type for expected failures in the agent stack.
|
Package result provides a discriminated Result type for expected failures in the agent stack. |
|
Package session manages branchable conversation trees and JSONL serialization.
|
Package session manages branchable conversation trees and JSONL serialization. |
|
Package subagent runs a specialized agent loop in isolation so a primary agent can delegate a self-contained task and receive only the final result back.
|
Package subagent runs a specialized agent loop in isolation so a primary agent can delegate a self-contained task and receive only the final result back. |
|
Package tool provides tool registration and execution for agent runs.
|
Package tool provides tool registration and execution for agent runs. |
|
Package transform converts agent messages for LLM providers.
|
Package transform converts agent messages for LLM providers. |