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 ¶
- func DefaultSystemPrompt() string
- func SubAgentSystemPrompt() string
- type Agent
- func (a *Agent) Compact(ctx context.Context) (int, error)
- func (a *Agent) History() []llm.Message
- func (a *Agent) PlanMode() bool
- func (a *Agent) Reset()
- func (a *Agent) Run(ctx context.Context, goal string) (Transcript, error)
- func (a *Agent) SessionLen() int
- func (a *Agent) SetGoalLoop(maxReturns int)
- func (a *Agent) SetHistory(h []llm.Message)
- func (a *Agent) SetLabel(s string)
- func (a *Agent) SetPlanMode(on bool)
- func (a *Agent) SetSystem(s string)
- type Transcript
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) Compact ¶
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) Run ¶
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 ¶
SessionLen reports how many remembered messages are in the current session.
func (*Agent) SetGoalLoop ¶ added in v0.13.0
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.
func (*Agent) SetHistory ¶
SetHistory restores a session conversation (e.g. loaded from disk).
func (*Agent) SetLabel ¶ added in v0.8.0
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) SetPlanMode ¶
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.
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.