reflect

package
v0.75.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 10 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 reflect runs the post-task learning pass: it asks the model to distill durable lessons from a finished transcript and returns them as pitfalls for the knowledge base. Parse failures yield no lessons (not an error); only a transport failure surfaces as ReflectionError.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lessons added in v0.4.2

type Lessons struct {
	Pitfalls []knowledge.Pitfall
	Facts    []string
	// Parsed reports whether a JSON object was actually read out of the model's
	// reply. It separates "the model looked and found nothing to learn" from "we
	// could not read what it said" — two different failures with two different
	// fixes, which were indistinguishable because both surfaced as an empty
	// Lessons and neither was logged at all.
	Parsed bool
	// Reply is what came back when nothing could be parsed, for the log. Empty
	// once Parsed is true.
	Reply string
}

Lessons is what a reflection pass distills: general tool pitfalls (saved to the workspace's lesson store) and durable facts about THIS project (saved alongside them, folded into the prompt next time). Both are per workspace and both are wiped by /clear.

type ReflectionError

type ReflectionError struct{ Err error }

ReflectionError wraps a host-level failure of the reflection pass (the model call itself failing).

func (*ReflectionError) Error

func (e *ReflectionError) Error() string

func (*ReflectionError) Unwrap

func (e *ReflectionError) Unwrap() error

type Reflector

type Reflector struct {
	// Model and Provider name the connection for the log. Without them a failed
	// pass says only that "the model" looped, and the first question — which one,
	// the task's or a reflect profile's — could not be answered from the log at
	// all. Optional; empty is fine.
	Model    string
	Provider string

	LLM  llm.Chatter
	Lite bool

	// Prefix, when set, sends every reflection call as the next message of the
	// run itself — Prefix is the run's own messages as the server last saw them,
	// Tools the run's own tool list — so a caching local server answers from the
	// prefix it already holds instead of prefilling a summary under a different
	// system prompt. A reply that is not the JSON asked for falls back to the
	// standalone call. Only meaningful when LLM talks to the same server and
	// model the run did.
	Prefix []llm.Message
	Tools  []map[string]any
	// contains filtered or unexported fields
}

Reflector distills lessons from a transcript using a Chatter. Lite uses a simpler, facts-only prompt — for a small local model that loops on the full two-part ask.

func New

func New(l llm.Chatter) *Reflector

New constructs a Reflector.

func (*Reflector) Reflect

func (r *Reflector) Reflect(ctx context.Context, t agent.Transcript) (Lessons, error)

Reflect distills lessons from t. A turn with no tool use (a plain chat) has nothing to learn, so it skips the model call — no point making a small model reason over an empty run.

Lite runs two narrow calls instead of one combined one (see the prompts above); a failure of either is not fatal to the other, since half the lessons beats none.

Jump to

Keyboard shortcuts

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