Documentation
¶
Overview ¶
Package loop implements the Observe-Think-Act agent loop and stateful Agent runtime.
Index ¶
- Variables
- func DefaultConfig() msg.Config
- func NewUserMessage(text string) msg.UserMessage
- func NewUserMessageWithParts(parts ...msg.ContentPart) msg.UserMessage
- func RunLoop(ctx context.Context, prompts []msg.AgentMessage, agentCtx *msg.Context, ...) ([]msg.AgentMessage, error)
- func RunLoopContinue(ctx context.Context, agentCtx *msg.Context, cfg msg.Config, deps LoopDeps, ...) ([]msg.AgentMessage, error)
- type Agent
- func (a *Agent) Abort()
- func (a *Agent) ApplyConfig(fn func(*msg.Config))
- func (a *Agent) ApplyState(fn func(*msg.Context))
- func (a *Agent) Config() msg.Config
- func (a *Agent) Continue(ctx context.Context) (*agentevent.Stream, error)
- func (a *Agent) FollowUp(message msg.AgentMessage)
- func (a *Agent) Prompt(ctx context.Context, prompts ...msg.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() *msg.Context
- func (a *Agent) Steer(message msg.AgentMessage)
- func (a *Agent) Subscribe(handler agentevent.Handler)
- type LoopDeps
- type ModelResolver
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMaxSteps is returned when the loop exceeds msg.Config.MaxSteps. ErrMaxSteps = msg.ErrMaxSteps // ErrAborted is returned when the loop is cancelled. ErrAborted = msg.ErrAborted // ErrToolNotFound is returned when a tool call names an unknown tool. ErrToolNotFound = msg.ErrToolNotFound // ErrEmptyContext is returned when Continue is called with no messages. ErrEmptyContext = msg.ErrEmptyContext // ErrInvalidContinue is returned when Continue cannot resume from the last message. ErrInvalidContinue = msg.ErrInvalidContinue )
Functions ¶
func DefaultConfig ¶
DefaultConfig returns conservative defaults for a new agent run.
func NewUserMessage ¶
func NewUserMessage(text string) msg.UserMessage
NewUserMessage builds a text user message with the current timestamp.
func NewUserMessageWithParts ¶
func NewUserMessageWithParts(parts ...msg.ContentPart) msg.UserMessage
NewUserMessageWithParts builds a multimodal user message.
func RunLoop ¶
func RunLoop(ctx context.Context, prompts []msg.AgentMessage, agentCtx *msg.Context, cfg msg.Config, deps LoopDeps, stream *agentevent.Stream) ([]msg.AgentMessage, error)
RunLoop starts a new agent loop from prompt messages.
func RunLoopContinue ¶
func RunLoopContinue(ctx context.Context, agentCtx *msg.Context, cfg msg.Config, deps LoopDeps, stream *agentevent.Stream) ([]msg.AgentMessage, error)
RunLoopContinue resumes a loop from existing context without adding prompts.
Types ¶
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 msg.AgentMessage)
FollowUp enqueues a message injected after the inner loop completes.
func (*Agent) Prompt ¶
func (a *Agent) Prompt(ctx context.Context, prompts ...msg.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 msg.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 LoopDeps ¶
type LoopDeps struct {
Model llms.Model
// ResolveModel optionally returns the langchaingo client for a turn's model name.
// Dual-model routing changes ModelName across turns; without ResolveModel the loop
// would keep calling deps.Model (bound to the chat provider endpoint).
ResolveModel ModelResolver
Registry *tool.Registry
}
LoopDeps holds runtime dependencies for the agent loop.
type ModelResolver ¶
ModelResolver returns the langchaingo client for a specific model name.