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

Function countCustomAgentTokens

src/utils/analyzeContext.ts:733–769  ·  view source on GitHub ↗
(agentDefinitions: {
  activeAgents: AgentDefinition[]
})

Source from the content-addressed store, hash-verified

731}
732
733async function countCustomAgentTokens(agentDefinitions: {
734 activeAgents: AgentDefinition[]
735}): Promise<{
736 agentTokens: number
737 agentDetails: Agent[]
738}> {
739 const customAgents = agentDefinitions.activeAgents.filter(
740 a => a.source !== 'built-in',
741 )
742 const agentDetails: Agent[] = []
743 let agentTokens = 0
744
745 const tokenCounts = await Promise.all(
746 customAgents.map(agent =>
747 countTokensWithFallback(
748 [
749 {
750 role: 'user',
751 content: [agent.agentType, agent.whenToUse].join(' '),
752 },
753 ],
754 [],
755 ),
756 ),
757 )
758
759 for (const [i, agent] of customAgents.entries()) {
760 const tokens = tokenCounts[i] || 0
761 agentTokens += tokens || 0
762 agentDetails.push({
763 agentType: agent.agentType,
764 source: agent.source,
765 tokens: tokens || 0,
766 })
767 }
768 return { agentTokens, agentDetails }
769}
770
771type MessageBreakdown = {
772 totalTokens: number

Callers 1

analyzeContextUsageFunction · 0.85

Calls 2

countTokensWithFallbackFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected