interjection

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package interjection formats and buffers mid-turn user messages.

Index

Constants

View Source
const LargePromptThreshold = 25_000

LargePromptThreshold matches grok-build's mid-turn truncation limit.

Variables

This section is empty.

Functions

func Format

func Format(text string) string

Format wraps interjection text as a synthetic user message.

Types

type Buffer

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

Buffer holds pending mid-turn interjections keyed by run ID.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates an empty interjection buffer.

func (*Buffer) Drain

func (b *Buffer) Drain(runID string) []string

Drain removes and returns all pending messages for runID (oldest first).

func (*Buffer) PendingCount

func (b *Buffer) PendingCount(runID string) int

PendingCount reports how many messages are queued for runID.

func (*Buffer) Push

func (b *Buffer) Push(runID, text string)

Push queues a raw user message for later drain into the tool loop.

type DrainPhase

type DrainPhase string

DrainPhase identifies when the runtime may drain pending interjections.

const (
	// DrainBeforeSample is the start of a sampling step (before LLM call).
	DrainBeforeSample DrainPhase = "before_sample"
	// DrainAfterToolBatch is after a tool batch completes.
	DrainAfterToolBatch DrainPhase = "after_tool_batch"
	// DrainPostCompact is after context compaction reinjected reminder/context.
	DrainPostCompact DrainPhase = "post_compact"
)

type DrainPolicy

type DrainPolicy struct {
	// BeforeSample drains at the start of each sampling step (default true).
	BeforeSample bool
	// AfterToolBatch drains after tools complete (default true).
	AfterToolBatch bool
	// DeferUntilPostCompact skips BeforeSample when compaction needs reminder
	// reinjection; drain happens at PostCompact instead (Codex steer alignment).
	DeferUntilPostCompact bool
}

DrainPolicy controls when mid-turn interjections enter the message list. Zero value means DefaultDrainPolicy().

func DefaultDrainPolicy

func DefaultDrainPolicy() DrainPolicy

DefaultDrainPolicy matches historical behavior: drain before sample and after tools.

func (DrainPolicy) Allow

func (p DrainPolicy) Allow(phase DrainPhase, justCompacted bool) bool

Allow reports whether draining is permitted at phase. justCompacted is true when the latest prepareMessages set NeedsReminder.

func (DrainPolicy) Normalize

func (p DrainPolicy) Normalize() DrainPolicy

Normalize fills defaults for a zero-value policy.

Jump to

Keyboard shortcuts

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