agent

package
v0.99.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package agent is the public facade for the Observe-Think-Act agent engine.

Runtime implementation lives in package loop; shared domain types live in msg.

Index

Constants

View Source
const (
	// RoleUser is a user message role.
	RoleUser = msg.RoleUser
	// RoleAssistant is an assistant message role.
	RoleAssistant = msg.RoleAssistant
	// RoleToolResult is a tool result message role.
	RoleToolResult = msg.RoleToolResult
	// RoleCustom is a custom application message role.
	RoleCustom = msg.RoleCustom
	// RoleBranchSummary is a branch summary message role.
	RoleBranchSummary = msg.RoleBranchSummary
	// RoleCompactionSummary is a compaction summary message role.
	RoleCompactionSummary = msg.RoleCompactionSummary
	// ToolExecutionParallel runs tool calls concurrently.
	ToolExecutionParallel = msg.ToolExecutionParallel
	// ToolExecutionSequential runs tool calls one at a time.
	ToolExecutionSequential = msg.ToolExecutionSequential
	// QueueAll drains every queued steering/follow-up message.
	QueueAll = msg.QueueAll
	// QueueOne drains a single queued message per drain.
	QueueOne = msg.QueueOne
	// StopReasonComplete indicates a normal model completion.
	StopReasonComplete = msg.StopReasonComplete
	// StopReasonError indicates the model stopped due to an error.
	StopReasonError = msg.StopReasonError
	// StopReasonAborted indicates the run was cancelled.
	StopReasonAborted = msg.StopReasonAborted
	// MediaKindImage is image input.
	MediaKindImage = msg.MediaKindImage
	// MediaKindAudio is audio input.
	MediaKindAudio = msg.MediaKindAudio
	// MediaKindVideo is video input.
	MediaKindVideo = msg.MediaKindVideo
)

Variables

View Source
var (
	// ErrMaxSteps is returned when the loop exceeds Config.MaxSteps.
	ErrMaxSteps = loop.ErrMaxSteps
	// ErrAborted is returned when the loop is cancelled.
	ErrAborted = loop.ErrAborted
	// ErrToolNotFound is returned when a tool call names an unknown tool.
	ErrToolNotFound = loop.ErrToolNotFound
	// ErrEmptyContext is returned when Continue is called with no messages.
	ErrEmptyContext = loop.ErrEmptyContext
	// ErrInvalidContinue is returned when Continue cannot resume from the last message.
	ErrInvalidContinue = loop.ErrInvalidContinue
)

Functions

This section is empty.

Types

type AfterToolCallFn

type AfterToolCallFn = msg.AfterToolCallFn

AfterToolCallFn runs after each tool execution.

type AfterToolContext

type AfterToolContext = msg.AfterToolContext

AfterToolContext is the input to AfterToolCall.

type AfterToolResult

type AfterToolResult = msg.AfterToolResult

AfterToolResult can rewrite a tool result or terminate the turn.

type Agent

type Agent = loop.Agent

Agent is a stateful wrapper around the agent loop with queues and subscriptions.

func NewAgent

func NewAgent(opts Options) *Agent

NewAgent creates an agent with default transforms and optional dependencies.

type AgentMessage

type AgentMessage = msg.AgentMessage

AgentMessage is the domain message type used throughout the agent loop.

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

AssistantMessage is a model turn with optional text and tool calls.

type BeforeToolCallFn

type BeforeToolCallFn = msg.BeforeToolCallFn

BeforeToolCallFn runs before each tool execution.

type BeforeToolContext

type BeforeToolContext = msg.BeforeToolContext

BeforeToolContext is the input to BeforeToolCall.

type BeforeToolResult

type BeforeToolResult = msg.BeforeToolResult

BeforeToolResult can cancel or rewrite a tool call before execution.

type BranchSummaryMessage

type BranchSummaryMessage = msg.BranchSummaryMessage

BranchSummaryMessage summarizes an abandoned session branch.

type CompactionSummaryMessage

type CompactionSummaryMessage = msg.CompactionSummaryMessage

CompactionSummaryMessage summarizes compacted conversation history.

type Config

type Config = msg.Config

Config holds runtime options for an agent loop invocation.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns conservative defaults for a new agent run.

type ContentPart

type ContentPart = msg.ContentPart

ContentPart is a union of message part types.

type Context

type Context = msg.Context

Context is the in-flight agent conversation state for a loop run.

type ConvertToLLMFn

type ConvertToLLMFn = msg.ConvertToLLMFn

ConvertToLLMFn converts agent messages to provider message content.

type CustomMessage

type CustomMessage = msg.CustomMessage

CustomMessage is an application-defined message in the session tree.

type GetMessagesFn

type GetMessagesFn = msg.GetMessagesFn

GetMessagesFn drains steering or follow-up queues.

type LoopDeps

type LoopDeps = loop.LoopDeps

LoopDeps holds runtime dependencies for the agent loop.

type MediaKind added in v0.98.2

type MediaKind = msg.MediaKind

MediaKind classifies multimodal input for modality checks and LLM conversion.

type MediaPart added in v0.98.2

type MediaPart = msg.MediaPart

MediaPart holds multimodal media content for user messages.

type MessageRole

type MessageRole = msg.MessageRole

MessageRole identifies the role of an agent message in the session tree.

type ModelResolver added in v0.98.2

type ModelResolver = loop.ModelResolver

ModelResolver returns the langchaingo client for a specific model name.

type Options

type Options = loop.Options

Options configures a new Agent instance.

type PrepareNextTurnFn

type PrepareNextTurnFn = msg.PrepareNextTurnFn

PrepareNextTurnFn runs after tools and may inject follow-up work.

type QueueMode

type QueueMode = msg.QueueMode

QueueMode controls how steering and follow-up queues drain.

type ShouldStopAfterTurnFn

type ShouldStopAfterTurnFn = msg.ShouldStopAfterTurnFn

ShouldStopAfterTurnFn decides whether the inner loop should stop.

type StopReason

type StopReason = msg.StopReason

StopReason is the model stop reason for an assistant turn.

type TextPart

type TextPart = msg.TextPart

TextPart holds plain text content in a multi-part message.

type ToolCallPart

type ToolCallPart = msg.ToolCallPart

ToolCallPart is a tool invocation requested by the assistant.

type ToolExecutionMode

type ToolExecutionMode = msg.ToolExecutionMode

ToolExecutionMode selects parallel or sequential tool batch execution.

type ToolResultMessage

type ToolResultMessage = msg.ToolResultMessage

ToolResultMessage carries the outcome of a tool invocation.

type TransformContextFn

type TransformContextFn = msg.TransformContextFn

TransformContextFn optionally rewrites messages before ConvertToLLM.

type TurnContext

type TurnContext = msg.TurnContext

TurnContext is the input to PrepareNextTurn / ShouldStopAfterTurn hooks.

type TurnUpdate

type TurnUpdate = msg.TurnUpdate

TurnUpdate is the mutable result of PrepareNextTurn.

type Usage

type Usage = msg.Usage

Usage captures token consumption reported by the LLM provider.

type UserMessage

type UserMessage = msg.UserMessage

UserMessage is a user turn, optionally multimodal.

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 approval implements chatagent auto approval mode helpers: mode parsing, Layer2 flagged detection, aux LLM review, and denial circuit breaker.
Package approval implements chatagent auto approval mode helpers: mode parsing, Layer2 flagged detection, aux LLM review, and denial circuit breaker.
Package ctxmgr manages agent context budgets, compaction, and branch summarization.
Package ctxmgr manages agent context budgets, compaction, and branch summarization.
Package dcg integrates Destructive Command Guard (dcg) as a pre-exec check for chat agent run_terminal and run_code tools.
Package dcg integrates Destructive Command Guard (dcg) as a pre-exec check for chat agent run_terminal and run_code tools.
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 eval provides FakeModel-scripted harness evaluation scenarios and scoring.
Package eval provides FakeModel-scripted harness evaluation scenarios and scoring.
Package event provides lifecycle event streaming for agent runs.
Package event provides lifecycle event streaming for agent runs.
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 loop implements the Observe-Think-Act agent loop and stateful Agent runtime.
Package loop implements the Observe-Think-Act agent loop and stateful Agent runtime.
Package loopdetect detects repetitive tool-call patterns in an agent run.
Package loopdetect detects repetitive tool-call patterns in an agent run.
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 sandbox provides optional Docker isolation for agent shell and code tools.
Package sandbox provides optional Docker isolation for agent shell and code tools.
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.
tools
coding
Package coding provides agent tools for terminal control, filesystem navigation, search, patching, web access, and code execution.
Package coding provides agent tools for terminal control, filesystem navigation, search, patching, web access, and code execution.
echo
Package echo provides a reference echo tool for agent examples.
Package echo provides a reference echo tool for agent examples.
Package transform converts agent messages for LLM providers.
Package transform converts agent messages for LLM providers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL