subagent

package
v0.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package subagent provides a mini tool loop for spawning one-shot subagents with isolated conversation context and a restricted tool set.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PathChecker

type PathChecker func(read, write []string) error

PathChecker validates that declared tool paths are allowed. Return non-nil error to reject the tool call.

type Result

type Result struct {
	// Text is the final assistant response (from the turn with no tool calls).
	Text string
	// ToolCalls is the total number of tool calls executed.
	ToolCalls int
	// Tools maps tool name → call count for summary display.
	Tools map[string]int
	// Usage is aggregated token usage across all LLM calls.
	Usage usage.Usage
}

Result is the outcome of a subagent run.

type ResultGuardFunc

type ResultGuardFunc func(ctx context.Context, toolName, result string) error

ResultGuardFunc checks whether a tool result is acceptable (e.g. size limits). Return non-nil error to reject the result.

type Runner

type Runner struct {
	// Provider is the LLM backend to call.
	Provider providers.Provider
	// Tools is the set of tools available to the subagent.
	Tools tool.Tools
	// Prompt is the system prompt for the subagent.
	Prompt string
	// Model is the resolved model to use for requests.
	Model model.Model
	// Events receives conversation events (can be a no-op sink).
	Events conversation.EventSink
	// MaxSteps caps the total number of LLM round-trips to prevent runaway loops.
	MaxSteps int
	// Think configures reasoning mode for requests (nil = off).
	Think *thinking.Value
	// ContextLength overrides the model's default context window. Zero = use Model.ContextLength.
	ContextLength int
	// ExecuteOverride replaces t.Execute() for sandboxable tools (e.g. Landlock re-exec).
	// If nil, all tools execute directly via t.Execute().
	ExecuteOverride func(ctx context.Context, toolName string, args map[string]any) (string, error)
	// PathChecker fast-fails tool calls whose declared paths fall outside sandbox bounds.
	// If nil, no path checking is performed.
	PathChecker PathChecker
	// ResultGuard optionally validates tool results (e.g. size limits). Nil = no validation.
	ResultGuard ResultGuardFunc
	// HooksRunner runs user-configured shell hooks before/after tool calls. Zero value = no hooks.
	HooksRunner hooks.Runner
	// LSPManager collects diagnostics after tool execution. Nil = no LSP diagnostics.
	LSPManager *lsp.Manager
	// CWD is the working directory passed to hook scripts. Empty = hooks receive empty cwd.
	CWD string
	// Estimate is the token estimation function.
	Estimate func(string) int
	// Features is the child's resolved feature set (global → agent → mode).
	// Used by downstream behavior (bash truncation, etc.).
	Features config.Features
	// ReadBeforePolicy is the resolved read-before enforcement policy for this subagent.
	// Created from the child's config, with parent's runtime override taking precedence.
	ReadBeforePolicy tool.ReadBeforePolicy
}

Runner executes a mini tool loop: system prompt → user prompt → LLM ↔ tools → text response.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, prompt string) (Result, error)

Run executes the subagent loop: sends the prompt, iterates tool calls, and returns the final text response when the LLM produces a turn with no tool calls.

Jump to

Keyboard shortcuts

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