IMPORTANT
AI Context & Knowledge Heritage
- Subsystem: Architecture & Documentation / Core Docs / token_telemetry_mission
- Architecture:
@docs ARCHITECTURE:Documentation - Failure Path: Information drift, legacy terminology, or documentation mismatch.
- Observability: Traceability via
execution/parity_guard.py([token_telemetry_mission])
Token Telemetry Verification Swarm
This document details a multi-agent validation mission designed to verify the fidelity and propagation of token consumption and cost metrics throughout the Tadpole OS codebase.
1. Swarm Architecture & Mission Design
This mission runs a 4-agent cluster structured in a hierarchical command hierarchy:
graph TD
User([User / Script]) -->|POST /v1/agents/1/tasks| CEO["Agent 1 (CEO / Strategic Lead)<br/>gemma4:31b-cloud"]
CEO -->|Recursively recruits / delegates| COO["Agent 2 (Tadpole Alpha / COO)<br/>gemma4:31b-cloud"]
COO -->|Spawns in parallel| Coder["Coder Agent (Developer)<br/>gemma4:31b-cloud"]
COO -->|Spawns in parallel| Auditor["Audit Specialist (Auditor)<br/>gemma4:12b"]The Mission Objective
"Perform a multi-agent token telemetry validation audit. Delegate task analysis to Tadpole Alpha (ID: 2). Instruct Tadpole Alpha to spawn coder to draft a documentation summary of token tracking, and spawn audit_specialist to verify the database schema of token tracking. Ensure they return their findings in a synthesized report."
2. Token Propagation Flow
When the mission runs, token consumption propagates from the LLM provider to the SQLite database and finally to the React UI:
Step A: Provider Interaction & Turn Usage
Every model call (Ollama, Gemini, OpenAI, etc.) returns a response containing token usage:
input_tokens(prompt size)output_tokens(completion size)total_tokens(sum of both)
Step B: Finalization & Persistence
- The Swarm Dispatcher (defined in dispatcher.rs) manages execution loops.
- Upon completion of each agent's execution turn, finalize/mod.rs is called:
- Accumulates Tokens:
agent.economics.tokens_used += u.total_tokens - Calculates Cost: Using
rates::calculate_cost_with_custom_rates(defined inserver-rs/src/agent/rates.rs), prioritizing custom rates configured in the Model Registry (input_cost_per_mandoutput_cost_per_m) over fallback static tables, updatesagent.economics.cost_usd. - DB Persistence: Saves the updated record to the configured SQLite database (default
data/state/tadpole.db) under theagentstable (viasave_agent_db). - Mission Aggregation: Updates the
mission_historytable'scost_usdcolumn (viaupdate_missionin mission.rs).
- Accumulates Tokens:
Step C: API Endpoints Delivery
The backend exposes the updated state through these REST endpoints:
GET /v1/agentsreturns a JSON array of all registered agents containing:json{ "id": "coder", "tokens_used": 430941, "cost_usd": 0.928362, "input_tokens": 124500, "output_tokens": 306441, ... }GET /v1/agents/{id}returns the details of a single agent.GET /v1/agents/graphreturns the active mission structure and telemetry.
Step D: Frontend React UI Integration
- The frontend React app queries the endpoints and triggers reactive state updates.
- The useDashboardData hook fetches the agent registry into the Zustand
agent_store. - It performs a reactive aggregation (reduce) over the agents:
total_cost = agents.reduce((acc, curr) => acc + (curr.cost_usd || 0), 0)total_tokens = agents.reduce((acc, curr) => acc + (curr.tokens_used || 0), 0)
- The Ops_Dashboard.tsx renders these values in key telemetry cards at the top of the command panel.
3. How to Run the Telemetry Verification
Option A: Run via Verification Script (Automated)
Run the automated validation tool to inspect starting values, dispatch the mission, poll for progression, and display the final telemetry updates:
python execution/verify_token_propagation.pyOption B: Run via UI (Manual)
- Navigate to the Missions Board in the UI.
- Create or select a cluster named
Telemetry Audit Swarm. - Assign the following agents to the cluster:
- Agent of Nine (ID:
1) - Configure as the Alpha Node (Orchestrator). - Tadpole Alpha (ID:
2) - coder
- audit_specialist
- Agent of Nine (ID:
- Paste the Mission Objective text (from Section 1) into the objective input field.
- Click Run Mission.
- Switch to the Ops Dashboard to see the real-time update of
Total CostandTotal Tokensas the agents execute.
