logic

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ParadoxThreshold = 0.8

ParadoxThreshold is the EAST magnitude above which cognitive paradox injection is triggered. Configurable via config.Policy.ParadoxThreshold (default 0.8).

View Source
var SteeringRegistry = []SteeringPolicy{
	{
		MinMagnitude: 0.8,
		HeaderKey:    "prompt_header_paradox",
		BodyKey:      "prompt_body_conservative",
	},
	{
		MinMagnitude: 0.5,
		HeaderKey:    "prompt_header_strict",
		BodyKey:      "prompt_body_structured",
	},
	{
		MinMagnitude: 0.0,
		HeaderKey:    "prompt_header_default",
		BodyKey:      "prompt_body_creative",
	},
}

SteeringRegistry holds the tiered policies for guiding LLM behavior under stress. LLD 5.4: Sorted by MinMagnitude descending. First match where magnitude > MinMagnitude wins.

Functions

func CalculateEAST

func CalculateEAST(logicSuccess, entropyCoefficient float64) float64

CalculateEAST computes the Entropic Activation Steering magnitude (P). LLD 5.4 Formula: P = exp(1 - LogicSuccess) / EntropyCoefficient

func GetSteeringPrompts

func GetSteeringPrompts(magnitude float64) (headerKey, bodyKey string)

GetSteeringPrompts selects the appropriate prompt templates based on the current EAST magnitude.

func ShouldInjectParadox

func ShouldInjectParadox(magnitude float64) bool

ShouldInjectParadox returns true if the system should forcefully inject cognitive paradoxes (conflicting imperatives) to induce highly conservative, step-by-step LLM output behavior due to extreme runtime logic failures.

Types

type Compiler

type Compiler struct {
}

Compiler orchestrates prompt assembly based on LLD 5.1/5.2.

func NewCompiler

func NewCompiler() *Compiler

NewCompiler initializes the prompt compiler.

func (*Compiler) Compile

func (c *Compiler) Compile(ctx context.Context, intent domain.IntentStr, options ...interface{}) (string, error)

Compile builds the final string to send to the GenerativePort.

type ContextManager

type ContextManager struct {
	BaseBuffer     int // Default safety margin (e.g., 200 tokens)
	ShaveThreshold int // Estimated token count at which Intensive Shaving occurs
}

ContextManager handles token allocation and rule-based pruning for LLM prompts. It ensures the LLM never exceeds its context window while maximizing relevant knowledge.

func NewContextManager

func NewContextManager() *ContextManager

NewContextManager creates a default context manager.

func (*ContextManager) CalculateContextBudget

func (cm *ContextManager) CalculateContextBudget(
	totalBudget, fp32Usage int, logicSuccess float64, previousOutputTokens int,
) int

CalculateContextBudget determines how many tokens remain for the soft context (INT8 facts). LLD 5.3: It employs "Logic Success Sharpening". As the agent fails logic audits (LogicSuccess drops), the safety buffer increases, restricting the context to force the LLM to focus only on the most critical facts.

func (*ContextManager) FilterStrategic

func (cm *ContextManager) FilterStrategic(atoms []domain.Atom, currentIntent domain.IntentStr) []domain.Atom

FilterStrategic performs the first pass of context pruning according to LLD 5.3. It retains atoms that match the Current Intent, OR are mathematically certain (Weight >= 0.9), OR are global context (no origin intent).

func (*ContextManager) Prune

func (cm *ContextManager) Prune(atoms []domain.Atom, maxTokens int) []domain.Atom

Prune restricts the context to the maxTokens budget. It estimates token counts using a fast heuristic, applies Intelligent Shaving if bloated, and sorts by Weight (Confidence) descending.

type PromptConfig

type PromptConfig struct {
	Intent             domain.IntentStr
	TaskType           domain.TaskType
	Context            []domain.Atom // Soft Logic (INT8)
	Axioms             []domain.Atom // Hard Logic (FP32) - Attention Sink
	Genes              []domain.DomainGene
	Facts              []byte // N-Quads
	SteeringMagnitude  float64
	InjectParadox      bool
	RefinementFeedback *RefinementContext
	Pass               int // Multi-pass iteration
	PreviousOutput     string
	SessionHistory     []domain.AuditResult
}

PromptConfig holds all possible inputs for the functional options compiler.

type PromptOption

type PromptOption func(*PromptConfig)

PromptOption defines the functional option pattern.

func WithAxioms

func WithAxioms(a []domain.Atom) PromptOption

func WithContext

func WithContext(a []domain.Atom) PromptOption

func WithFacts

func WithFacts(f []byte) PromptOption

func WithGenes

func WithGenes(g []domain.DomainGene) PromptOption

func WithHistory

func WithHistory(h []domain.AuditResult) PromptOption

func WithIntent

func WithIntent(i domain.IntentStr) PromptOption

Functional Options Setters

func WithPass

func WithPass(p int) PromptOption

func WithPrevious

func WithPrevious(o string) PromptOption

func WithRefinement

func WithRefinement(r *RefinementContext) PromptOption

func WithSteering

func WithSteering(m float64, p bool) PromptOption

func WithTaskType

func WithTaskType(t domain.TaskType) PromptOption

type RefinementContext

type RefinementContext struct {
	AuditResult   *domain.AuditResult
	PreviousDraft interface{}
}

RefinementContext encapsulates audit failures used to correct the LLM.

type SteeringPolicy

type SteeringPolicy struct {
	MinMagnitude float64
	HeaderKey    string // Prompt template key for the system header
	BodyKey      string // Prompt template key for the body instructions
}

SteeringPolicy defines template keys used for prompt assembly when the agent reaches a specific cognitive pressure threshold.

Jump to

Keyboard shortcuts

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