feedbackprompt

package
v1.172.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 20 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 feedbackprompt decides when a tool result tells an agent to report what the platform could not do for it, or to capture what it learned about the data (#2885).

The platform improves through two loops, and both depend on agents. What an agent learns about the data goes to memory_capture and the knowledge review queue; what it learns about the platform (a refusal it cannot fix, a missing tool or parameter, a gate that forces a workaround, a path that cost it calls) goes to manage_feedback topic=platform. The knowledge loop is prompted at every turn; the platform loop was prompted only on the second identical refusal in a session, so in five deployments with it on no agent ever posted.

This package holds the prompts and when they are given:

  • a refusal whose code means the capability is missing (an unknown tool, an unknown parameter or action) carries the reporting sentence the first time;
  • any other refusal carries it once the session has been refused before, by any tool;
  • a script save refused by a gate that forces a design change carries it the first time in a session (Gate);
  • a session whose calls show a pattern worth an improvement post (many similar calls, truncated results, repeated draft cycles, a workaround after a refusal) gets one line naming the pattern and its calls, once per pattern; a query corrected after errors gets a line pointing at memory_capture instead.

Each session's record (its recent calls, refusals and the prompts it was given) is kept in a Store: PostgreSQL when the platform has a database, so every replica reads the same record whichever one a call reaches, and memory otherwise.

Platform prompts are given only when platform feedback is on and the caller's persona may post (SetGate), so no session is told about something it cannot do; a managed script's calls get nothing. Which prompt a result carried is recorded on the call's platform context, and so in its audit row, as a fixed label (Mark).

Index

Constants

View Source
const (
	// LabelRefusal is the reporting sentence on a refusal after the session's
	// first.
	LabelRefusal = "refusal"
	// LabelMissing is the reporting sentence on a refusal whose code means the
	// tool, parameter or action does not exist.
	LabelMissing = "missing"
	// LabelGate is the reporting sentence on a script save a gate refused.
	LabelGate = "gate"
	// PatternPrefix starts the label of a pattern line: pattern:<name>.
	PatternPrefix = "pattern:"
	// LabelQueryCorrected is the one pattern line about the data rather than
	// the platform: it points at memory_capture, so the platform feedback
	// counts leave it out.
	LabelQueryCorrected = PatternPrefix + patternQueryCorrected
)

The labels a result's audit row records for the prompt it carried.

View Source
const RecordRetention = 24 * time.Hour

RecordRetention is how long a session's record is kept. Patterns read the last ten minutes; a session idle longer than a day starts again.

Variables

View Source
var DefaultThresholds = Thresholds{Window: 10 * time.Minute, SimilarCalls: 6, Truncated: 3, DraftCycles: 6, After: 3}

DefaultThresholds are the thresholds the platform runs with.

Functions

func Allowed

func Allowed(ctx context.Context, persona string) bool

Allowed reports whether the persona is told about platform feedback.

func Gate

func Gate(ctx context.Context) string

Gate is the sentence a script save refused by a gate carries, and records it, the first time in the call's session and only for a persona told about platform feedback; "" otherwise. A save outside a session (the portal) and a managed script's call get none.

func Mark

func Mark(ctx context.Context, label string)

Mark records on the call's platform context which prompt its result carried, which its audit row keeps. A call with no platform context records nothing.

func Middleware

func Middleware(o Options) mcp.Middleware

Middleware adds the prompts to tools/call results (see the package comment). A call with no session, a managed script's call, and a call to manage_feedback itself are left as they are.

func SetGate

func SetGate(f func(ctx context.Context, persona string) bool)

SetGate installs the check platform prompts are given under. The platform feedback wiring installs it; nil removes it.

Types

type Options

type Options struct {
	// Session is the session a call belongs to, "" when none.
	Session func(ctx context.Context) string
	// Thresholds are when a pattern is worth a line; zero is DefaultThresholds.
	Thresholds Thresholds
	// Now is the clock; nil is time.Now.
	Now func() time.Time
	// Store keeps each session's record; nil is an in-memory store, correct
	// for one replica. It is also the store Gate records in.
	Store Store
}

Options configure the middleware.

type Postgres

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

Postgres is the store every replica shares: a session's calls in feedback_prompt_calls, and the prompts it was given in feedback_prompt_given. A row holds a call's tool, the hashes of its shape and subject, its call reference and whether it was refused or cut short; never an argument value.

func NewPostgres

func NewPostgres(db *sql.DB) *Postgres

NewPostgres builds the store over the platform database.

func (*Postgres) Sweep

func (p *Postgres) Sweep(ctx context.Context, before time.Time) (int64, error)

Sweep deletes the calls and prompts recorded before the cutoff, reporting how many rows it removed.

type Store

type Store interface {
	// contains filtered or unexported methods
}

Store keeps each session's record (#2885). A session's calls reach every replica, so a deployment with a database keeps the records there (Shared): a record held by one replica would see a fraction of a session's calls, and a prompt given once per session would be given by each replica.

func Shared

func Shared(db *sql.DB) Store

Shared is the store a deployment keeps the records in: PostgreSQL when there is a database, shared by every replica, and memory otherwise, which is correct for one replica.

type Thresholds

type Thresholds struct {
	// Window is how far back similar calls and draft cycles are counted.
	Window time.Duration
	// SimilarCalls is how many calls to one tool that differ only in the item
	// they act on make a pattern.
	SimilarCalls int
	// Truncated is how many results cut short in a session make a pattern.
	Truncated int
	// DraftCycles is how many drafts and patches of one script make a pattern.
	DraftCycles int
	// After is how many calls after a refusal a different tool's success
	// counts as a workaround, and the same query tool's as a correction.
	After int
}

Thresholds are when a pattern is worth a line.

Jump to

Keyboard shortcuts

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