rewriter

package
v0.11.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0, MIT Imports: 8 Imported by: 0

Documentation

Overview

Package rewriter provides LLM prompt rewriter middleware (master plan §6.x). The rewriter strips politeness filler, injects specificity hints, and classifies prompt complexity. It is wired through the agent's PromptRewriter interface and instantiated by the API layer when the rewriter config section is present. Not enabled by default; opt-in via config (see RewriterConfig).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalysisResult

type AnalysisResult struct {
	Complexity     Complexity `json:"complexity"`
	HasFiller      bool       `json:"has_filler"`
	HasVagueness   bool       `json:"has_vagueness"`
	HasSpecificity bool       `json:"has_specificity"`
	WordCount      int        `json:"word_count"`
	Confidence     float64    `json:"confidence"`
	Issues         []string   `json:"issues"`
}

type Complexity

type Complexity int
const (
	ComplexitySimple    Complexity = iota
	ComplexityAmbiguous Complexity = iota
	ComplexityComplex   Complexity = iota
)

func (Complexity) String

func (c Complexity) String() string

type LLMRewriter

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

func NewConfiguredRewriter

func NewConfiguredRewriter(provider providers.Provider, fallbackModel string, cfg config.RewriterConfig) *LLMRewriter

NewConfiguredRewriter is the shared CLI/API config mapping. In particular, enabling the middleware alone does not opt into paid provider calls.

func NewLLMRewriter

func NewLLMRewriter(provider providers.Provider, model string) *LLMRewriter

func NewWithOptions

func NewWithOptions(provider providers.Provider, model string, opts Options) *LLMRewriter

func (*LLMRewriter) Rewrite

func (r *LLMRewriter) Rewrite(ctx context.Context, input string) (*RewriteResult, error)

func (*LLMRewriter) RewritePrompt

func (r *LLMRewriter) RewritePrompt(ctx context.Context, input string) (string, error)

RewritePrompt is a thin convenience wrapper around Rewrite that returns just the rewritten string, suitable for middleware-style use. Falls back to the original input on error so a misbehaving rewriter never blocks the agent.

type Middleware

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

func NewMiddleware

func NewMiddleware() *Middleware

func (*Middleware) Analyze

func (m *Middleware) Analyze(input string) *AnalysisResult

func (*Middleware) InjectSpecificity

func (m *Middleware) InjectSpecificity(input string) (string, []string)

func (*Middleware) Strip

func (m *Middleware) Strip(input string) (string, []string)

type Options

type Options struct {
	Enabled          bool
	StripSycophancy  bool
	AntiPatternGuard bool
	LLMRewrite       bool
}

Options independently controls local and provider-assisted transformations. A disabled rewriter is an exact passthrough, including whitespace.

type RewriteResult

type RewriteResult struct {
	Original   string     `json:"original"`
	Rewritten  string     `json:"rewritten"`
	Complexity Complexity `json:"complexity"`
	Changed    bool       `json:"changed"`
	Injected   []string   `json:"injected"`
	Stripped   []string   `json:"stripped"`
	Confidence float64    `json:"confidence"`
}

type Rewriter

type Rewriter interface {
	Rewrite(ctx context.Context, input string) (*RewriteResult, error)
}

type SycophancyReducer

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

func NewSycophancyReducer

func NewSycophancyReducer() *SycophancyReducer

func (*SycophancyReducer) Check

func (s *SycophancyReducer) Check(response string) *SycophancyReport

func (*SycophancyReducer) Strip

func (s *SycophancyReducer) Strip(response string) string

type SycophancyReport

type SycophancyReport struct {
	Detected bool     `json:"detected"`
	Patterns []string `json:"patterns"`
	Severity float64  `json:"severity"`
}

Jump to

Keyboard shortcuts

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