* Check agent descriptions token count
( agentInfo: AgentDefinitionsResult | null, )
| 71 | * Check agent descriptions token count |
| 72 | */ |
| 73 | async function checkAgentDescriptions( |
| 74 | agentInfo: AgentDefinitionsResult | null, |
| 75 | ): Promise<ContextWarning | null> { |
| 76 | if (!agentInfo) { |
| 77 | return null |
| 78 | } |
| 79 | |
| 80 | const totalTokens = getAgentDescriptionsTotalTokens(agentInfo) |
| 81 | |
| 82 | if (totalTokens <= AGENT_DESCRIPTIONS_THRESHOLD) { |
| 83 | return null |
| 84 | } |
| 85 | |
| 86 | // Calculate tokens for each agent |
| 87 | const agentTokens = agentInfo.activeAgents |
| 88 | .filter(a => a.source !== 'built-in') |
| 89 | .map(agent => { |
| 90 | const description = `${agent.agentType}: ${agent.whenToUse}` |
| 91 | return { |
| 92 | name: agent.agentType, |
| 93 | tokens: roughTokenCountEstimation(description), |
| 94 | } |
| 95 | }) |
| 96 | .sort((a, b) => b.tokens - a.tokens) |
| 97 | |
| 98 | const details = agentTokens |
| 99 | .slice(0, 5) |
| 100 | .map(agent => `${agent.name}: ~${agent.tokens.toLocaleString()} tokens`) |
| 101 | |
| 102 | if (agentTokens.length > 5) { |
| 103 | details.push(`(${agentTokens.length - 5} more custom agents)`) |
| 104 | } |
| 105 | |
| 106 | return { |
| 107 | type: 'agent_descriptions', |
| 108 | severity: 'warning', |
| 109 | message: `Large agent descriptions (~${totalTokens.toLocaleString()} tokens > ${AGENT_DESCRIPTIONS_THRESHOLD.toLocaleString()})`, |
| 110 | details, |
| 111 | currentValue: totalTokens, |
| 112 | threshold: AGENT_DESCRIPTIONS_THRESHOLD, |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Check MCP tools token count |
no test coverage detected