Skip to main content
Glama

llmkit_local_agents

Read-onlyIdempotent

Track and attribute AI agent costs within Claude Code sessions to identify spending patterns across providers.

Instructions

Subagent cost attribution for the current Claude Code session. Shows which agents cost the most.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
byTypeNo
sessionIdYes
agentCountYes
totalCostUsdYes
subagentsTotalCostUsdNo
mainConversationCostUsdNo

Implementation Reference

  • The `handleLocalAgents` function implements the core logic for the "llmkit_local_agents" tool, calculating costs for Claude Code subagents.
    export async function handleLocalAgents() {
      // Agent attribution is Claude Code specific (subagent JSONL files).
      // Other tools don't have subagent concepts (yet).
      const agentData = await getAgentCosts();
      if (!agentData) return fail('No agent data found. Agent attribution requires Claude Code with subagents.');
    
      const { session, agents, mainConversationCost } = agentData;
      const agentTotal = agents.reduce((s, a) => s + a.totalCost, 0);
    
      const byType: { type: string; count: number; costUsd: number; tokens: number }[] = [];
      if (agents.length > 0) {
        const typeMap = new Map<string, { count: number; cost: number; tokens: number }>();
        for (const a of agents) {
          const e = typeMap.get(a.agentType) ?? { count: 0, cost: 0, tokens: 0 };
          e.count++;
          e.cost += a.totalCost;
          e.tokens += a.totalInput + a.totalOutput;
          typeMap.set(a.agentType, e);
        }
        for (const [type, d] of typeMap) {
          byType.push({ type, count: d.count, costUsd: d.cost, tokens: d.tokens });
        }
      }
    
      const topAgents = agents.slice(0, 5).map(a => ({
        type: a.agentType, id: a.agentId, costUsd: a.totalCost, messages: a.messages, models: a.models,
      }));
    
      const lines = [
        'Agent Cost Attribution',
        '\u2500'.repeat(25),
        `Session: ${session.sessionId.slice(0, 12)}...`,
        `Total: $${session.totalCost.toFixed(4)}`,
        '',
        `Main conversation: $${mainConversationCost.toFixed(4)}`,
        `Subagents: $${agentTotal.toFixed(4)} (${agents.length} agents)`,
      ];
    
      if (byType.length > 0) {
        lines.push('', 'By type:');
        for (const t of byType) lines.push(`  ${t.type}: ${t.count}x, $${t.costUsd.toFixed(4)}, ${t.tokens.toLocaleString()} tokens`);
        lines.push('', 'Top agents:');
        for (const a of topAgents) lines.push(`  ${a.type} (${a.id}): $${a.costUsd.toFixed(4)}, ${a.messages} msgs`);
      }
    
      return ok(lines.join('\n'), {
        sessionId: session.sessionId,
        totalCostUsd: session.totalCost,
        mainConversationCostUsd: mainConversationCost,
        subagentsTotalCostUsd: agentTotal,
        agentCount: agents.length,
        byType,
        topAgents,
      });
    }
  • The input and output schema for "llmkit_local_agents" defined within `LOCAL_TOOLS`.
      name: 'llmkit_local_agents',
      description: 'Subagent cost attribution for the current Claude Code session. Shows which agents cost the most.',
      inputSchema: { type: 'object' as const, properties: {} },
      outputSchema: {
        type: 'object' as const,
        properties: {
          sessionId: { type: 'string' },
          totalCostUsd: { type: 'number' },
          mainConversationCostUsd: { type: 'number' },
          subagentsTotalCostUsd: { type: 'number' },
          agentCount: { type: 'number' },
          byType: { type: 'array', items: { type: 'object', properties: { type: { type: 'string' }, count: { type: 'number' }, costUsd: { type: 'number' }, tokens: { type: 'number' } } } },
        },
        required: ['sessionId', 'totalCostUsd', 'agentCount'],
      },
      annotations: { title: 'Agent Costs', ...HINTS },
    },
  • Registration of the "llmkit_local_agents" tool in the HANDLER_MAP in `packages/mcp-server/src/tools.ts`.
    const HANDLER_MAP: Record<string, Handler> = {
      llmkit_usage_stats: handleUsageStats,
      llmkit_cost_query: handleCostQuery,
      llmkit_list_keys: () => handleListKeys(),
      llmkit_budget_status: handleBudgetStatus,
      llmkit_health: () => handleHealth(),
      llmkit_session_summary: handleSessionSummary,
      llmkit_local_session: () => handleLocalSession(),
      llmkit_local_projects: () => handleLocalProjects(),
      llmkit_local_cache: () => handleLocalCache(),
      llmkit_local_forecast: () => handleLocalForecast(),
      llmkit_local_agents: () => handleLocalAgents(),
      llmkit_notion_cost_snapshot: handleNotionCostSnapshot,
      llmkit_notion_budget_check: handleNotionBudgetCheck,
      llmkit_notion_session_report: handleNotionSessionReport,
    };
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already provide strong behavioral hints (readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false). The description adds useful context by specifying it's for 'subagent cost attribution' and focuses on 'which agents cost the most', which helps the agent understand the tool's focus on ranking or highlighting high-cost agents rather than just raw data. No contradiction with annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with two clear sentences: 'Subagent cost attribution for the current Claude Code session. Shows which agents cost the most.' Every word earns its place, front-loading the core purpose without fluff or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 0 parameters, rich annotations (including readOnlyHint, idempotentHint), and an output schema exists, the description is reasonably complete. It specifies the scope ('current Claude Code session') and focus ('which agents cost the most'), which adds value beyond structured fields. However, it could benefit from more differentiation from sibling tools to be fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters with 100% schema description coverage, so the schema fully documents the input (none required). The description doesn't need to add parameter information, and it appropriately doesn't mention any. Baseline for 0 parameters is 4, as it avoids unnecessary parameter details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Subagent cost attribution for the current Claude Code session. Shows which agents cost the most.' It specifies the verb ('shows'), resource ('cost attribution'), and scope ('current Claude Code session'). However, it doesn't explicitly differentiate from sibling tools like 'llmkit_cost_query' or 'llmkit_usage_stats', which may have overlapping cost-related functions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions 'current Claude Code session' but doesn't clarify if this is for real-time monitoring, historical analysis, or how it differs from siblings like 'llmkit_cost_query' or 'llmkit_usage_stats'. No explicit when/when-not instructions or prerequisites are included.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/smigolsmigol/llmkit-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server