agent

package
v0.41.10 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agent runs the reason → act → observe loop against an llm.Chatter, dispatching fat tools, injecting learned pitfalls into tool errors, and tracing every step.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSystemPrompt

func DefaultSystemPrompt() string

DefaultSystemPrompt is the baseline instruction given to the model. Kept tight on purpose — it ships in every request to a small local model.

func SubAgentSystemPrompt added in v0.8.0

func SubAgentSystemPrompt() string

SubAgentSystemPrompt is the baseline for a sub-agent — a fresh LLM session the main assistant spawns to carry out ONE delegated task. Deliberately different from the interactive prompt: a sub-agent has no user to talk to and no chat to see, so it works autonomously and returns a single, complete answer instead of a terse line plus a NEXT suggestion.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent holds the wiring for a run. The knowledge base and tracer may be nil. history carries the conversation across Run calls (the session memory); only the user goals and final answers are kept, not the tool back-and-forth, so a small model's context isn't swamped.

func New

func New(l llm.Chatter, reg *tool.Registry, kb *knowledge.KB, tr trace.Tracer, system string, maxSteps int) *Agent

New builds an Agent. maxSteps <= 0 defaults to 12.

func (*Agent) AnswerAside added in v0.34.0

func (a *Agent) AnswerAside(ctx context.Context, question string) string

AnswerAside answers a side question when no task is running, using the committed session history as context.

func (*Agent) Compact

func (a *Agent) Compact(ctx context.Context) (int, error)

Compact summarizes the session so far into a short recap and replaces the history with it, freeing context while keeping continuity. Returns how many messages were compacted (0 if there was nothing worth compacting).

func (*Agent) Detach added in v0.35.0

func (a *Agent) Detach()

Detach orphans the agent: its emit and remember become no-ops, so a wedged run that later unblocks can't scribble on the UI or the (now fresh) session.

func (*Agent) History

func (a *Agent) History() []llm.Message

History returns a copy of the session conversation (for persistence).

func (*Agent) MaxHistory added in v0.40.4

func (a *Agent) MaxHistory() int

MaxHistory reports the current trim cap (see SetMaxHistory).

func (*Agent) PlanMode

func (a *Agent) PlanMode() bool

PlanMode reports whether plan mode is on.

func (*Agent) Reattach added in v0.35.0

func (a *Agent) Reattach()

Reattach undoes Detach (used only if the agent swap it was part of failed).

func (*Agent) Reset

func (a *Agent) Reset()

Reset clears the session conversation memory.

func (*Agent) Run

func (a *Agent) Run(ctx context.Context, goal string) (Transcript, error)

Run executes the loop until the model produces a final answer (a reply with no tool calls), maxSteps is reached, or the context is cancelled.

func (*Agent) SessionLen

func (a *Agent) SessionLen() int

SessionLen reports how many remembered messages are in the current session.

func (*Agent) SetArchiver added in v0.40.0

func (a *Agent) SetArchiver(ar Archiver)

SetArchiver wires a durable record of session memory (see Archiver).

func (*Agent) SetAsides added in v0.34.0

func (a *Agent) SetAsides(fn func() []string)

SetAsides registers the /btw side-channel: fn is drained between steps of a running task, and each question gets a one-turn, no-tools answer (emitted as an "aside" event) using the live conversation, without steering the task.

func (*Agent) SetBeforeTurn added in v0.25.0

func (a *Agent) SetBeforeTurn(fn func() []llm.Message)

SetBeforeTurn registers a hook called at the top of every loop iteration; the messages it returns are appended to the working set before the next model call. Used for /btw side-channel steering. The hook must be concurrency-safe — it's invoked from the run goroutine while the UI goroutine may be feeding it.

func (*Agent) SetGoalLoop added in v0.13.0

func (a *Agent) SetGoalLoop(maxReturns int, nudgeIdle bool)

SetGoalLoop configures goal pursuit: when the model finalizes, a judge decides whether the goal is met; if not, re-feed the goal and keep going, up to maxReturns times (a TTL). 0 disables it — one run, the model's finish stands. nudgeIdle gives a model that re-finalizes without working after a re-feed one push before giving up.

func (*Agent) SetHistory

func (a *Agent) SetHistory(h []llm.Message)

SetHistory restores a session conversation (e.g. loaded from disk).

func (*Agent) SetLabel added in v0.8.0

func (a *Agent) SetLabel(s string)

SetLabel tags this agent as a sub-agent: the label is attached to every event it emits (as the "agent" field) so the UI can group a sub-agent's progress on its own status line during a parallel fan-out.

func (*Agent) SetMaxHistory added in v0.40.4

func (a *Agent) SetMaxHistory(n int)

SetMaxHistory overrides how many recent session messages remember() keeps verbatim before silently cutting the oldest ones — no LLM recap, no chance to preserve anything (default 16, set in New). Cutting the front of the prompt breaks a local server's KV-cache prefix reuse exactly like a summary compact does, so a low cap makes that happen on every single turn once a session runs long. Memory "raw" callers raise this a lot, turning the trim into a rare safety backstop instead of everyday routine.

func (*Agent) SetPlanMode

func (a *Agent) SetPlanMode(on bool)

SetPlanMode toggles plan mode. In plan mode the agent investigates with read-only tools and proposes a plan; mutating tool calls are refused, so it can't change anything until switched back to auto.

func (*Agent) SetSystem added in v0.4.2

func (a *Agent) SetSystem(s string)

SetSystem swaps the base system prompt (e.g. after learning new project facts), so the next run uses it without a full re-wire.

type Archiver added in v0.40.0

type Archiver interface {
	Archive(goal, entry string)
}

Archiver durably records every (goal, final answer + actions digest) pair remember() commits to session history — the same text that goes into the live session memory, but never trimmed or folded by Compact, so the `history` tool can always recover something a compaction summary has since shortened. Nil (the default) just means there's nothing to recall from.

type Transcript

type Transcript struct {
	Messages  []llm.Message
	Final     string
	Steps     int
	Cancelled bool // the user cancelled (esc) specifically
	Stopped   bool // ended before a clean answer (cancel / runaway / stuck / maxSteps / mid-run error) → no reflection
	Returns   int  // goal re-feeds the judge triggered this run
	GoalMet   bool // a goal-loop ran and the judge confirmed the goal was met
}

Transcript is the full record of one task run.

Jump to

Keyboard shortcuts

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