critic

package
v0.32.42 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package critic implements the session-scoped critic reviewer: a small LLM call that inspects a freshly-proposed or just-completed plan and either accepts it or returns concrete improvement feedback. The chat handler drives it as an OnTurnEnd hook bounded by SessionCritic.MaxIterations so each plan transition gets at most N review rounds.

Like the goal judge it is intentionally narrow: callers pass the trigger kind (plan_proposed | plan_completed), the plan and tasks snapshot, and a trailing chat window; the reviewer returns a structured verdict. Errors and unparseable verdicts are treated as "acceptable=false, fall-open" — the caller still emits the SSE event but does not inject feedback, so a reviewer outage cannot deadlock the chat loop.

Index

Constants

View Source
const (
	TriggerPlanProposed  = "plan_proposed"
	TriggerPlanCompleted = "plan_completed"
)

Trigger kinds match the SessionCritic.LastTrigger field and the SSE payload's "trigger" key. New trigger kinds must update both the reviewer prompt switch and the hook's plan-transition detector.

View Source
const DefaultRecentMessageWindow = 6

DefaultRecentMessageWindow is how many trailing chat messages the reviewer inspects by default. Kept small to bound prompt cost.

View Source
const MaxRecentMessageContentChars = 2000

MaxRecentMessageContentChars bounds each message body included in the reviewer prompt so pathological tool outputs cannot inflate cost.

Variables

This section is empty.

Functions

This section is empty.

Types

type LLMReviewer

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

LLMReviewer resolves the configured RoleCritic tier and runs a structured JSON-output chat call.

func NewLLMReviewer

func NewLLMReviewer(router RouterClientFor, role llm.Role) *LLMReviewer

NewLLMReviewer returns a Reviewer that resolves the critic role on the supplied router. Pass an empty role to use llm.RoleCritic.

func (*LLMReviewer) Review

func (r *LLMReviewer) Review(ctx context.Context, trigger string, plan *session.Plan, tasks []session.Task, recent []llm.ChatMessage) (Verdict, error)

Review runs the LLM call. Non-nil error → caller should treat as fail-open (skip injection this turn, no state mutation).

type Reviewer

type Reviewer interface {
	Review(ctx context.Context, trigger string, plan *session.Plan, tasks []session.Task, recent []llm.ChatMessage) (Verdict, error)
}

Reviewer evaluates a plan-transition event. Implementations must be safe for concurrent use.

type RouterClientFor

type RouterClientFor interface {
	ClientFor(role llm.Role) (llm.Client, llm.TierResolution, error)
}

RouterClientFor is the subset of llm.Router that the reviewer needs.

type Verdict

type Verdict struct {
	Acceptable bool   `json:"acceptable"`
	Feedback   string `json:"feedback"`
	Reason     string `json:"reason"`
}

Verdict is the structured output of a reviewer call.

func ParseVerdict

func ParseVerdict(raw string) (Verdict, error)

ParseVerdict tolerantly extracts a Verdict JSON object from raw text. Mirrors goal.ParseVerdict so reviewers and judges share the same lenient tolerance to code-fence wrappers and preamble text.

Jump to

Keyboard shortcuts

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