MCPcopy Create free account
hub / github.com/Noumena-Network/code / countToolDefinitionTokens

Function countToolDefinitionTokens

src/utils/analyzeContext.ts:235–259  ·  view source on GitHub ↗
(
  tools: Tools,
  getToolPermissionContext: () => Promise<ToolPermissionContext>,
  agentInfo: AgentDefinitionsResult | null,
  model?: string,
)

Source from the content-addressed store, hash-verified

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

Callers 5

toolSearch.tsFile · 0.85
countBuiltInToolTokensFunction · 0.85
countSlashCommandTokensFunction · 0.85
countSkillTokensFunction · 0.85
countMcpToolTokensFunction · 0.85

Calls 3

toolToAPISchemaFunction · 0.85
countTokensWithFallbackFunction · 0.85
logForDebuggingFunction · 0.70

Tested by

no test coverage detected