runner

package
v0.1.5 Latest Latest
Warning

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

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

Documentation

Overview

Package runner fans out prompts to multiple model adapters concurrently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendHistory

func AppendHistory(
	histories map[string][]models.ConversationTurn,
	adapterIDs []string,
	responses []models.ModelResponse,
	userPrompt string,
) map[string][]models.ConversationTurn

AppendHistory updates histories with the results of a completed run. For each adapter (identified by adapterIDs[i]) whose response is successful and has non-empty text, it appends a user turn and an assistant turn. Error responses and write-only responses (empty text) are skipped. A nil histories map is initialized on first use. The updated map is returned.

func CompactHistories

func CompactHistories(
	ctx context.Context,
	adapters []models.ModelAdapter,
	histories map[string][]models.ConversationTurn,
	onEvent func(modelID string, event models.AgentEvent),
) map[string][]models.ConversationTurn

CompactHistories calls each adapter to summarise its own conversation history. On success the full history is replaced with a single compact context pair. Adapters with no history, or whose compaction call fails, are left unchanged.

The summarization prompt is resolved per-model from the context (via prompt.ResolveSummarizationPrompt). If no payload is configured, it falls back to DefaultSummarizationPrompt.

func EstimateHistoryTokens

func EstimateHistoryTokens(history []models.ConversationTurn) int64

EstimateHistoryTokens returns a rough token count for history (4 chars ≈ 1 token).

func HasInterrupted

func HasInterrupted(responses []models.ModelResponse) bool

HasInterrupted reports whether any response in the slice has Interrupted set.

func IsContextOverflowError

func IsContextOverflowError(errStr string) bool

IsContextOverflowError reports whether errStr looks like a context-window-exceeded error from any supported provider.

func RunAll

func RunAll(
	ctx context.Context,
	adapters []models.ModelAdapter,
	histories map[string][]models.ConversationTurn,
	userPrompt string,
	onEvent func(modelID string, event models.AgentEvent),
	onModelDone func(idx int, resp models.ModelResponse),
	verbose bool,
) []models.ModelResponse

RunAll sends prompt to every adapter concurrently and returns all responses. histories is a per-adapter map (keyed by adapter ID) of prior conversation turns; nil or a missing key means a fresh conversation for that adapter. onEvent is called from goroutines — callers must be safe for concurrent use. onModelDone, if non-nil, is called from the adapter's goroutine as soon as it finishes (before RunAll returns). This lets callers render incremental completion (e.g. marking a TUI panel as "done") without waiting for the slowest adapter.

func ShouldAutoCompact

func ShouldAutoCompact(histories map[string][]models.ConversationTurn, adapterID string, threshold float64) bool

ShouldAutoCompact reports whether the history for adapterID has grown past threshold relative to the model's known context window. threshold=0 uses the package default (0.80). Returns false when the context window is unknown.

func TrimHistory

func TrimHistory(history []models.ConversationTurn, maxTurns int) []models.ConversationTurn

TrimHistory returns the most recent maxTurns turns from history, preserving complete user+assistant pairs. If len(history) <= maxTurns or maxTurns <= 0, history is returned unchanged. maxTurns is rounded down to the nearest even number.

func WithRunOptions

func WithRunOptions(ctx context.Context, opts RunOptions) context.Context

WithRunOptions returns a context carrying the given RunOptions.

Types

type RunOptions

type RunOptions struct {
	Timeout          time.Duration     // 0 → no timeout
	CompactThreshold float64           // 0 → autoCompactThreshold (0.80)
	MaxHistoryTurns  int               // 0 → defaultMaxHistoryTurns (20)
	MaxSteps         int               // 0 → unlimited agentic loop turns
	CheckpointPath   string            // "" disables incremental checkpointing
	WorkDirs         map[string]string // per-adapter working directory (adapter ID → dir path)
}

RunOptions controls per-run behavior. Zero values fall back to package defaults.

Jump to

Keyboard shortcuts

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