( tools: Tools, getToolPermissionContext: () => Promise<ToolPermissionContext>, agentInfo: AgentDefinitionsResult | null, model?: string, )
| 232 | } |
| 233 | |
| 234 | export async function countToolDefinitionTokens( |
| 235 | tools: Tools, |
| 236 | getToolPermissionContext: () => Promise<ToolPermissionContext>, |
| 237 | agentInfo: AgentDefinitionsResult | null, |
| 238 | model?: string, |
| 239 | ): Promise<number> { |
| 240 | const toolSchemas = await Promise.all( |
| 241 | tools.map(tool => |
| 242 | toolToAPISchema(tool, { |
| 243 | getToolPermissionContext, |
| 244 | tools, |
| 245 | agents: agentInfo?.activeAgents ?? [], |
| 246 | model, |
| 247 | }), |
| 248 | ), |
| 249 | ) |
| 250 | const result = await countTokensWithFallback([], toolSchemas) |
| 251 | if (result === null || result === 0) { |
| 252 | const toolNames = tools.map(t => t.name).join(', ') |
| 253 | logForDebugging( |
| 254 | `countToolDefinitionTokens returned ${result} for ${tools.length} tools: ${toolNames.slice(0, 100)}${toolNames.length > 100 ? '...' : ''}`, |
| 255 | ) |
| 256 | } |
| 257 | return result ?? 0 |
| 258 | } |
| 259 | |
| 260 | /** Extract a human-readable name from a system prompt section's content */ |
| 261 | function extractSectionName(content: string): string { |
no test coverage detected