// src/common/constants.ts /** * Minimum thinking budget allowed by the Anthropic API. * Extended thinking requires at least 1024 budget_tokens. * @see https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking */ export const MIN_THINKING_BUDGET = 1024; /** * Reduced thinking budget for subsequent ReAct iterations (tool-result turns). * * In a ReAct agent loop, the first LLM call processes the user's query and * may need deep reasoning. Subsequent iterations (after tool results return) * typically only need to decide "call next tool" or "generate final response" * — 1024 tokens is sufficient for this routing logic. * * This reduces wall-clock time per iteration from ~20-30s to ~5-10s, * compounding across multi-tool conversations (e.g., 10 tool calls). */ export const TOOL_TURN_THINKING_BUDGET = 1024; // ============================================================================ // CONTEXT OVERFLOW MANAGEMENT // // Context overflow is handled mechanically — no token budget numbers are // exposed to the LLM. The system uses: pruning (Graph), summarization // (summarizeCallback), and auto-continuation (client.js max_tokens detection). // // See: docs/context-overflow-architecture.md // ============================================================================ /** * Minimum number of attached documents before the multi-document delegation * hint is injected. Below this threshold, the agent processes documents * directly within its own context. */ export const MULTI_DOCUMENT_THRESHOLD = 3; /** * Context utilization safety buffer multiplier (0-1). * Applied as: effectiveMax = (maxContextTokens - maxOutputTokens) * CONTEXT_SAFETY_BUFFER * * Reserves headroom so the LLM doesn't hit hard token limits mid-generation. * 0.9 = 10% reserved for safety. */ export const CONTEXT_SAFETY_BUFFER = 0.9; // ============================================================================ // SUMMARIZATION CONFIGURATION DEFAULTS // // These constants provide sensible defaults for the SummarizationConfig. // They can be overridden per-agent via AgentInputs.summarizationConfig. // ============================================================================ /** * Default context utilization percentage (0-100) at which summarization triggers. * When the context window is ≥80% full, pruning + summarization activates. */ export const SUMMARIZATION_CONTEXT_THRESHOLD = 80; /** * Proactive summarization threshold (0-1 fraction of context window). * At this utilization level, background summarization fires BEFORE pruning is needed. * This gives the summary time to complete so it's ready when context actually fills up. * * Inspired by VS Code Copilot Chat's 3-tier strategy: * 80% → proactive background summary * 90% → pruning kicks in (with summary already cached) * 100% → graceful: use existing summary + recent messages, never block */ export const PROACTIVE_SUMMARY_THRESHOLD = 0.8; /** * Number of recent conversation rounds (human+AI pairs) to keep in the * windowed view when a summary is available. Everything older is covered * by the summary. 2 rounds = last 2 user questions + 2 AI responses. * * This prevents wasting tokens on raw messages the summary already covers * and keeps context tight for the LLM. */ export const COMPACTION_RECENT_ROUNDS = 2; /** * Default reserve ratio (0-1) — fraction of context window to preserve as recent messages. * 0.3 means 30% of the context budget is reserved for the most recent messages, * ensuring the model always has immediate conversation history even after aggressive pruning. */ export const SUMMARIZATION_RESERVE_RATIO = 0.3; /** * Default EMA (Exponential Moving Average) alpha for pruning calibration. * Controls how quickly the calibration adapts to new token counts. * Higher α = faster adaptation (more responsive to recent changes). * Lower α = smoother adaptation (more stable across iterations). * 0.3 provides a balance between responsiveness and stability. */ export const PRUNING_EMA_ALPHA = 0.3; /** * Default initial calibration ratio for EMA pruning. * 1.0 means no adjustment on the first iteration (trust the raw token counts). * Subsequent iterations will adjust based on actual vs. estimated token usage. */ export const PRUNING_INITIAL_CALIBRATION = 1.0; // ============================================================================ // TOOL DISCOVERY CACHING // ============================================================================ /** * Maximum number of tool discovery entries to cache per conversation. * Prevents unbounded memory growth in very long conversations. */ export const TOOL_DISCOVERY_CACHE_MAX_SIZE = 200; // ============================================================================ // MESSAGE DEDUPLICATION // ============================================================================ /** * Maximum length of system message content to hash for deduplication. * Messages longer than this are always considered unique (hashing would be expensive). */ export const DEDUP_MAX_CONTENT_LENGTH = 10000;