/** * Context Pressure Utilities * * Pure functions for context overflow management. These handle: * 1. Multi-document detection — counting attached documents in messages * 2. Multi-document delegation hint — injected when 3+ documents detected * 3. Post-prune context note — injected after pruning/summarization * * DESIGN PRINCIPLE: The LLM never sees raw token numbers. Context overflow * is handled mechanically by pruning (Graph) + auto-continuation (client.js). * Only task-driven hints (multi-document) are injected — never budget-based. * * @see docs/context-overflow-architecture.md */ import type { BaseMessage } from '@langchain/core/messages'; /** Result of scanning messages for attached documents */ export interface DocumentDetectionResult { /** Total unique documents detected */ count: number; /** Names of detected documents */ names: string[]; } /** * Scan messages for attached documents using known content patterns. * * Detects documents from: * 1. `# "filename"` headers in "Attached document(s):" blocks (text content) * 2. `**filename1, filename2**` in "The user has attached:" blocks (embedded files) * * @param messages - Conversation messages to scan * @returns Document count and names (deduplicated) */ export declare function detectDocuments(messages: BaseMessage[]): DocumentDetectionResult; /** * Determine whether the multi-document delegation hint should be injected. * * Only fires on the first iteration (before any AI response) when the * document count meets the threshold. This ensures the agent delegates * upfront rather than trying to process all documents itself. * * @param documentCount - Number of detected documents * @param hasAiResponse - Whether the agent has already responded in this chain * @returns Whether to inject the delegation hint */ export declare function shouldInjectMultiDocHint(documentCount: number, hasAiResponse: boolean): boolean; /** * Build the multi-document delegation hint message content. * * @param documentCount - Number of detected documents * @param documentNames - Names of detected documents * @returns Message content string for injection as HumanMessage */ export declare function buildMultiDocHintContent(documentCount: number, documentNames: string[]): string; /** * Build the post-prune context note injected after messages are pruned * and summarized. No token numbers — just a contextual signal that * earlier conversation was compressed. * * @param discardedCount - Number of messages that were pruned * @param hasSummary - Whether a summary was successfully generated * @returns Message content string for injection as SystemMessage, or null if no note needed */ export declare function buildPostPruneNote(discardedCount: number, hasSummary: boolean): string | null; /** * Check whether a tool named "task" exists in the agent's tool set. * * @param tools - Array of tool objects or structured tools * @returns Whether the task tool is available */ export declare function hasTaskTool(tools: Array<{ name?: string; } | unknown> | undefined): boolean;