(model?: string, toolCount?: number)
| 90 | * @returns Maximum tokens available for conversation history |
| 91 | */ |
| 92 | export function getConversationTokenLimit(model?: string, toolCount?: number): number { |
| 93 | const limit = MODEL_CONTEXT_LIMITS[model ?? 'default'] ?? MODEL_CONTEXT_LIMITS.default; |
| 94 | |
| 95 | // If tool count is provided, use dynamic calculation |
| 96 | if (toolCount !== undefined) { |
| 97 | const toolTokens = estimateToolTokens(toolCount); |
| 98 | const reserved = |
| 99 | TOKEN_BUFFERS.systemPrompt + |
| 100 | toolTokens + |
| 101 | TOKEN_BUFFERS.prependedContext + |
| 102 | TOKEN_BUFFERS.responseBuffer + |
| 103 | TOKEN_BUFFERS.safetyMargin; |
| 104 | return limit - reserved; |
| 105 | } |
| 106 | |
| 107 | // Fall back to default static buffer |
| 108 | return limit - RESERVED_TOKENS; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Estimate token count from text using a character-based heuristic. |
no test coverage detected