{"id":"6746a219-b8e9-40f9-b9bf-eed7904f8df0","entityType":"agent","slug":"clawhub-lrg913427-dot-agent-lens","name":"Agent Lens","canonicalUrl":"https://www.xpersona.co/agent/clawhub-lrg913427-dot-agent-lens","canonicalPath":"/agent/clawhub-lrg913427-dot-agent-lens","generatedAt":"2026-10-10T00:44:38.299Z","source":"CLAWHUB","claimStatus":"UNCLAIMED","verificationTier":"NONE","summary":{"evidence":{"source":"editorial-content","verified":true,"confidence":"high","updatedAt":"2026-10-09T12:11:21.503Z","emptyReason":null},"description":"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or... Skill: Agent Lens Owner: lrg913427-dot Summary: Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or... Tags: latest:3.0.0 Version history: v2.17.3 | 2026-06-13T10:01:59.198Z | auto - Version bumped from 2.17.0 to 2.17.2 in SKILL.md. - Internal documentation updated; no functional or interface changes to features o","descriptionLabel":"Technical summary","evidenceSummary":"Capability contract not published. No trust telemetry is available yet. 2.7K downloads reported by the source. Last updated 10/9/2026.","installCommand":"clawhub skill install s175nn6ap9fe4ne23bws9svzm185ywrq:agent-lens","sourceUrl":"https://clawhub.ai/lrg913427-dot/agent-lens","homepage":"https://clawhub.ai/lrg913427-dot/skills/agent-lens","primaryLinks":[{"label":"View on ClawHub","url":"https://clawhub.ai/lrg913427-dot/agent-lens","kind":"source"},{"label":"Homepage","url":"https://clawhub.ai/lrg913427-dot/skills/agent-lens","kind":"homepage"}],"safetyScore":84,"overallRank":62,"popularityScore":69,"trustScore":null,"claimedByName":null,"isOwner":false,"seoDescription":"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or... "},"coverage":{"evidence":{"source":"public-profile","verified":false,"confidence":"medium","updatedAt":"2026-10-09T12:11:21.503Z","emptyReason":null},"protocols":[{"protocol":"OPENCLEW","label":"OpenClaw","status":"self-declared","notes":"Declared in the public agent profile."}],"capabilities":[],"verifiedCount":0,"selfDeclaredCount":1,"capabilityMatrix":{"rows":[{"key":"OPENCLEW","type":"protocol","support":"unknown","confidenceSource":"profile","notes":"Listed on profile"}],"flattenedTokens":"protocol:OPENCLEW|unknown|profile"}},"adoption":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-10-09T12:11:21.503Z","emptyReason":null},"stars":null,"forks":null,"downloads":2685,"packageName":null,"latestVersion":"2.17.3","tractionLabel":"2.7K downloads"},"release":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-10-09T12:11:21.495Z","emptyReason":null},"lastUpdatedAt":"2026-10-09T12:11:21.503Z","lastCrawledAt":"2026-10-09T12:11:21.495Z","lastIndexedAt":null,"nextCrawlAt":"2026-10-10T12:11:21.495Z","lastVerifiedAt":null,"highlights":[{"version":"2.17.3","createdAt":"2026-06-13T10:01:59.198Z","changelog":"- Version bumped from 2.17.0 to 2.17.2 in SKILL.md. - Internal documentation updated; no functional or interface changes to features or commands. - Removed skill-card.md file.","fileCount":3,"zipByteSize":3621},{"version":"2.17.2","createdAt":"2026-06-04T10:06:46.281Z","changelog":"- Version bump: 2.17.2 release. - Documentation update in SKILL.md, with no functional changes. - Removed redundant file: skill-card.md.","fileCount":3,"zipByteSize":3729},{"version":"3.0.0","createdAt":"2026-06-04T04:05:55.772Z","changelog":"- Removed the file skill-card.md. - No other user-facing changes.","fileCount":3,"zipByteSize":3595},{"version":"2.18.0","createdAt":"2026-06-03T16:04:50.359Z","changelog":"- Removed the file: skill-card.md - No user-facing features or functional changes - Housekeeping update to project files","fileCount":3,"zipByteSize":3859},{"version":"2.17.1","createdAt":"2026-06-01T10:07:33.566Z","changelog":"- Removed the file skill-card.md. - Version number updated from 2.16.0 to 2.17.0 in SKILL.md. - No functional or usage changes in documentation content.","fileCount":3,"zipByteSize":3828},{"version":"2.17.0","createdAt":"2026-05-31T16:02:55.823Z","changelog":"自动迭代测试通过，持续维护","fileCount":3,"zipByteSize":3728},{"version":"2.16.0","createdAt":"2026-05-30T10:03:05.804Z","changelog":"No file or documentation changes detected in this release. - Version bumped from 2.15.0 to 2.16.0. - No new features, bug fixes, or documentation updates.","fileCount":3,"zipByteSize":3626},{"version":"2.15.0","createdAt":"2026-05-28T16:02:00.155Z","changelog":"- Updated to version 2.15.0. - Documentation improved in SKILL.md. - Removed the file skill-card.md.","fileCount":3,"zipByteSize":3834}]},"execution":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No published capability contract is available yet."},"installCommand":"clawhub skill install s175nn6ap9fe4ne23bws9svzm185ywrq:agent-lens","setupComplexity":"low","setupSteps":["Setup complexity is classified as HIGH. You must provision dedicated cloud infrastructure or an isolated VM. Do not run this directly on your local workstation.","Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data."],"contract":{"contractStatus":"missing","authModes":[],"requires":[],"forbidden":[],"supportsMcp":false,"supportsA2a":false,"supportsStreaming":false,"inputSchemaRef":null,"outputSchemaRef":null,"dataRegion":null,"contractUpdatedAt":null,"sourceUpdatedAt":null,"freshnessSeconds":null},"invocationGuide":{"preferredApi":{"snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/trust"},"curlExamples":["curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/snapshot\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/contract\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/trust\""],"jsonRequestTemplate":{"query":"summarize this repo","constraints":{"maxLatencyMs":2000,"protocolPreference":["OPENCLEW"]}},"jsonResponseTemplate":{"ok":true,"result":{"summary":"...","confidence":0.9},"meta":{"source":"CLAWHUB","generatedAt":"2026-10-10T00:44:38.298Z"}},"retryPolicy":{"maxAttempts":3,"backoffMs":[500,1500,3500],"retryableConditions":["HTTP_429","HTTP_503","NETWORK_TIMEOUT"]}},"endpoints":{"dossierUrl":"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/dossier","snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-lrg913427-dot-agent-lens/trust"}},"reliability":{"evidence":{"source":"runtime-metrics","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No trust, reliability, or runtime telemetry is available."},"trust":{"status":"unavailable","handshakeStatus":"UNKNOWN","verificationFreshnessHours":null,"reputationScore":null,"p95LatencyMs":null,"successRate30d":null,"fallbackRate":null,"attempts30d":null,"trustUpdatedAt":null,"trustConfidence":"unknown","sourceUpdatedAt":null,"freshnessSeconds":null},"decisionGuardrails":{"doNotUseIf":["Contract metadata is missing or unavailable for deterministic execution."],"safeUseWhen":[],"riskFlags":["missing_or_unavailable_contract","trust_data_unavailable","schema_references_missing"],"operationalConfidence":"low"},"executionMetrics":{"observedLatencyMsP50":null,"observedLatencyMsP95":null,"estimatedCostUsd":null,"uptime30d":null,"rateLimitRpm":null,"rateLimitBurst":null,"lastVerifiedAt":null,"verificationSource":null},"runtimeMetrics":{"successRate":null,"avgLatencyMs":null,"avgCostUsd":null,"hallucinationRate":null,"retryRate":null,"disputeRate":null,"p50Latency":null,"p95Latency":null,"lastUpdated":null}},"benchmarks":{"evidence":{"source":"no-benchmark-data","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No benchmark suites or observed failure patterns are available."},"suites":[],"failurePatterns":[]},"artifacts":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"high","updatedAt":"2026-10-09T12:11:21.503Z","emptyReason":null},"readme":"Skill: Agent Lens\n\nOwner: lrg913427-dot\n\nSummary: Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or...\n\nTags: latest:3.0.0\n\nVersion history:\n\nv2.17.3 | 2026-06-13T10:01:59.198Z | auto\n\n- Version bumped from 2.17.0 to 2.17.2 in SKILL.md.\n- Internal documentation updated; no functional or interface changes to features or commands.\n- Removed skill-card.md file.\n\nv2.17.2 | 2026-06-04T10:06:46.281Z | auto\n\n- Version bump: 2.17.2 release.\n- Documentation update in SKILL.md, with no functional changes.\n- Removed redundant file: skill-card.md.\n\nv3.0.0 | 2026-06-04T04:05:55.772Z | auto\n\n- Removed the file skill-card.md.\n- No other user-facing changes.\n\nv2.18.0 | 2026-06-03T16:04:50.359Z | auto\n\n- Removed the file: skill-card.md\n- No user-facing features or functional changes\n- Housekeeping update to project files\n\nv2.17.1 | 2026-06-01T10:07:33.566Z | auto\n\n- Removed the file skill-card.md.\n- Version number updated from 2.16.0 to 2.17.0 in SKILL.md.\n- No functional or usage changes in documentation content.\n\nv2.17.0 | 2026-05-31T16:02:55.823Z | user\n\n自动迭代测试通过，持续维护\n\nv2.16.0 | 2026-05-30T10:03:05.804Z | auto\n\nNo file or documentation changes detected in this release.\n\n- Version bumped from 2.15.0 to 2.16.0.\n- No new features, bug fixes, or documentation updates.\n\nv2.15.0 | 2026-05-28T16:02:00.155Z | auto\n\n- Updated to version 2.15.0.\n- Documentation improved in SKILL.md.\n- Removed the file skill-card.md.\n\nv2.14.0 | 2026-05-27T10:03:10.065Z | auto\n\n- Removed the file skill-card.md.\n- No changes made to documentation or underlying functionality.\n\nv2.13.1 | 2026-05-26T04:02:30.735Z | auto\n\n- Version updated from 2.12.0 to 2.13.0.\n- Documentation in SKILL.md updated to reflect the new version.\n- No functional or feature changes; only version and documentation were modified.\n\nv2.13.0 | 2026-05-24T04:03:07.697Z | auto\n\n- Version bumped from 2.11.0 to 2.12.0 in SKILL.md.\n- No other content or feature changes detected in the documentation.\n\nv2.12.0 | 2026-05-23T22:02:16.070Z | auto\n\nNo user-facing changes in this release.\n\n- Version bump to 2.12.0; no code or documentation updates detected.\n\nv2.11.1 | 2026-05-23T16:03:13.047Z | auto\n\n- Updated version to 2.11.0 in SKILL.md.\n- No functional changes; documentation version now matches release.\n\nv2.11.0 | 2026-05-23T10:03:00.483Z | auto\n\n- No file changes detected in this version.\n- Version number updated to 2.11.0.\n- No new features, fixes, or documentation updates included.\n\nv2.10.0 | 2026-05-20T10:02:33.717Z | auto\n\n- Version bumped to 2.10.0 in SKILL.md.\n- No functional or documentation changes beyond updating the version number.\n\nv2.9.1 | 2026-05-19T16:02:02.177Z | auto\n\n- Updated version to 2.9.0 in SKILL.md.\n- No other content changes detected.\n\nv2.9.0 | 2026-05-19T10:03:35.278Z | auto\n\n- Updated version to 2.8.0.\n- No functional or documentation changes, only the version number in SKILL.md was changed.\n\nv0.1.0 | 2026-05-19T10:02:23.278Z | auto\n\n- Version bump: 2.7.0 → 2.8.0\n- SKILL.md updated with the new version number\n- No other content or feature changes detected\n\nv2.8.0 | 2026-05-18T16:03:03.442Z | auto\n\nNo file changes detected between versions 2.7.0 and 2.8.0.\n\n- Version number updated from 2.7.0 to 2.8.0.\n- No other changes or new features introduced in this release.\n\nv2.7.1 | 2026-05-17T16:02:28.974Z | auto\n\n- Version updated to 2.7.0.\n- Documentation updated in SKILL.md; version number incremented.\n- No code or functional changes—SKILL.md only.\n\nv1.0.0 | 2026-05-16T10:01:59.209Z | auto\n\nVersion 2.7.0\n\n- Updated SKILL.md to increment version from 2.6.0 to 2.7.0.\n- No other content or feature changes.\n\nv2.7.0 | 2026-05-15T22:02:15.756Z | auto\n\n- Updated version to 2.6.0 in documentation.\n- No changes to functionality; only SKILL.md was modified.\n\nv2.6.0 | 2026-05-15T16:03:10.788Z | auto\n\n- Updated version number from 2.4.0 to 2.5.0 in SKILL.md.\n- No other changes were made to documentation or features.\n\nv2.5.0 | 2026-05-15T10:02:34.235Z | auto\n\n- Downgraded version number from 2.5.0 to 2.4.0 in documentation.\n- No functional or feature changes; only SKILL.md was updated.\n- All instructions, usage examples, and guidance remain unchanged.\n\nv2.4.0 | 2026-05-14T16:03:57.327Z | auto\n\nNo changes detected in this release.\n\n- Version number updated to 2.4.0.\n- No other updates or modifications present.\n\nv2.3.1 | 2026-05-14T04:07:17.761Z | auto\n\n- Updated version number in documentation to 2.3.0.\n- No functional or feature changes—documentation only.\n\nv2.3.0 | 2026-05-12T16:03:30.275Z | auto\n\n- Updated version number in SKILL.md from 2.1.0 to 2.2.0.\n- No other user-visible changes.\n\nv2.2.0 | 2026-05-12T04:02:19.279Z | auto\n\n- Updated version from 2.0.0 to 2.1.0 in SKILL.md.\n- No new features, fixes, or usage changes described in the documentation.\n- All documentation, usage instructions, and examples remain unchanged.\n\nv2.1.0 | 2026-05-10T04:02:51.217Z | auto\n\nNo changes detected in this release.\n\n- Version number updated to 2.1.0\n- No file or documentation changes included in this version\n\nv2.0.1 | 2026-05-09T10:02:24.339Z | auto\n\nNo changes in this release; version bump only.\n\n- No file or documentation changes detected.\n- Safe to upgrade without impact on functionality.\n\nv2.0.0 | 2026-05-09T04:01:44.642Z | auto\n\nMajor update with expanded tracking and usability enhancements.\n\n- Supports full tracking of AI agent API calls, token usage analysis, and cost optimization for multiple providers (OpenAI, Anthropic, Google, DeepSeek, more).\n- New decorator, context manager, and manual APIs for flexible integration.\n- Enhanced CLI: stats, cost breakdowns, recent calls, export features, and cost optimization workflow.\n- Local SQLite storage for trace data; keeps all info private and offline.\n- Improved documentation with quick start guides, usage examples, and troubleshooting tips.\n- Models with unknown pricing are tracked but show \"—\" for cost; manual token tracking improved for non-OpenAI APIs.\n\nArchive index:\n\nArchive v2.17.3: 3 files, 3621 bytes\n\nFiles: skill-card.md (1928b), SKILL.md (4989b), _meta.json (130b)\n\nFile v2.17.3:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.17.2\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v2.17.3:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.17.3\",\n  \"publishedAt\": 1781344919198\n}\n\nFile v2.17.3:skill-card.md\n\n## Description: <br>\nTrack AI agent API calls, analyze token usage, and optimize costs for OpenAI, Anthropic, Google, DeepSeek, and other LLM APIs. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent operators use this skill to instrument local LLM API calls, inspect token consumption, report costs, and identify expensive models, long prompts, repeated calls, latency issues, or error patterns. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: API telemetry may reveal model choices, usage patterns, costs, and call metadata when used on sensitive workloads. <br>\nMitigation: Review what the referenced Python package records before connecting sensitive workloads, and protect or periodically clean its local SQLite database according to retention needs. <br>\n\n\n## Reference(s): <br>\n- [Agent Lens on ClawHub](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n- [lrg913427-dot publisher profile](https://clawhub.ai/user/lrg913427-dot) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [Text, Markdown, Code, Shell commands, Guidance] <br>\n**Output Format:** [Markdown with inline shell commands, Python snippets, and operational guidance] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May include cost-analysis steps, CLI command suggestions, token-counting snippets, and local SQLite data-handling guidance.] <br>\n\n## Skill Version(s): <br>\n2.17.3 (source: server release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nArchive v2.17.2: 3 files, 3729 bytes\n\nFiles: skill-card.md (2139b), SKILL.md (4989b), _meta.json (130b)\n\nFile v2.17.2:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.17.2\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v2.17.2:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.17.2\",\n  \"publishedAt\": 1780567606281\n}\n\nFile v2.17.2:skill-card.md\n\n## Description: <br>\nTrack AI agent API calls, analyze token usage, and optimize costs. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and engineers use this skill to monitor LLM API spending, inspect token usage, debug model calls, and generate cost reports for OpenAI, Anthropic, Google, DeepSeek, and related providers. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: Production use may depend on an external package referenced by the skill. <br>\nMitigation: Review the package source, pin the installed version, and validate behavior in a controlled environment before relying on it for production cost monitoring. <br>\nRisk: Cost-monitoring tools may store API usage records locally. <br>\nMitigation: Protect the local database path, review retention needs, and periodically remove old records with the documented cleanup command. <br>\nRisk: Cost estimates can differ from provider invoices because list pricing, discounts, and provider billing rules change. <br>\nMitigation: Reconcile generated reports against provider billing dashboards before making budget or vendor decisions. <br>\n\n\n## Reference(s): <br>\n- [ClawHub skill page](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [text, markdown, code, shell commands, configuration, guidance] <br>\n**Output Format:** [Markdown guidance with inline shell and Python examples] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May guide local SQLite usage tracking and JSON or CSV cost-report exports.] <br>\n\n## Skill Version(s): <br>\n2.17.2 (source: server release evidence and SKILL.md frontmatter) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nArchive v3.0.0: 3 files, 3595 bytes\n\nFiles: skill-card.md (1770b), SKILL.md (4989b), _meta.json (129b)\n\nFile v3.0.0:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.17.0\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v3.0.0:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"3.0.0\",\n  \"publishedAt\": 1780545955772\n}\n\nFile v3.0.0:skill-card.md\n\n## Description:\n\nTrack AI agent API calls, analyze token usage, and optimize costs.\n\nThis skill is ready for commercial/non-commercial use.\n\n## Publisher:\n\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot)\n\n### License/Terms of Use:\n\nMIT-0\n\n## Use Case:\n\nDevelopers and engineers use this skill to instrument AI agent API calls, inspect token usage, compare model costs, and generate cost reports for supported LLM providers.\n\n### Deployment Geography for Use:\n\nGlobal\n\n## Known Risks and Mitigations:\n\nRisk: The setup flow tells users to install mutable code directly from GitHub without a pinned version or integrity check.\n\nMitigation: Review or pin the package to a specific audited commit or trusted package-registry release before installation.\n\nRisk: The tool may observe prompts, responses, usage data, and environment available to the instrumented process.\n\nMitigation: Install and run it in a virtual environment without elevated privileges, and avoid exposing sensitive prompts or credentials.\n\n## Reference(s):\n\n- [Agent Lens ClawHub page](https://clawhub.ai/lrg913427-dot/skills/agent-lens)\n\n## Skill Output:\n\n**Output Type(s):** [guidance, shell commands, code, configuration, markdown]\n\n**Output Format:** [Markdown with inline bash and Python code blocks]\n\n**Output Parameters:** [1D]\n\n**Other Properties Related to Output:** [May propose local SQLite-backed tracking workflows, CLI commands, and cost-analysis steps.]\n\n## Skill Version(s):\n\n3.0.0 (source: server release metadata)\n\n## Ethical Considerations:\n\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment.\n\nArchive v2.18.0: 3 files, 3859 bytes\n\nFiles: skill-card.md (2492b), SKILL.md (4989b), _meta.json (130b)\n\nFile v2.18.0:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.17.0\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v2.18.0:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.18.0\",\n  \"publishedAt\": 1780502690359\n}\n\nFile v2.18.0:skill-card.md\n\n## Description: <br>\nTrack AI agent API calls, analyze token usage, and optimize costs for OpenAI, Anthropic, Google, DeepSeek, and similar model APIs. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent builders use Agent Lens to instrument AI API calls, inspect token usage, latency, and errors, and generate cost reports. It is useful when investigating API bills, comparing model costs, or optimizing prompt spend. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: The skill asks users to install runtime code from the author's GitHub repository. <br>\nMitigation: Review and pin or audit the runtime package before using it with confidential prompts or production agent traffic. <br>\nRisk: Usage traces are stored locally in ~/.agent-lens/traces.db and may contain usage records that need retention controls. <br>\nMitigation: Protect, retain, or clean the local database according to data-retention needs; use the documented clean command when old data should be removed. <br>\nRisk: Cost reports are estimates based on list prices and recorded token counts. <br>\nMitigation: Compare reports with provider billing data before making financial or operational decisions. <br>\n\n\n## Reference(s): <br>\n- [Agent Lens on ClawHub](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n- [Publisher profile](https://clawhub.ai/user/lrg913427-dot) <br>\n- [Runtime package repository referenced by the skill](https://github.com/lrg913427-dot/agent-lens.git) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [text, markdown, code, shell commands, configuration, guidance] <br>\n**Output Format:** [Markdown with inline bash and Python code blocks] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May reference local SQLite usage data at ~/.agent-lens/traces.db; cost estimates depend on configured model pricing and may differ from actual billed rates.] <br>\n\n## Skill Version(s): <br>\n2.18.0 (source: server release evidence; artifact frontmatter reports 2.17.0) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nArchive v2.17.1: 3 files, 3828 bytes\n\nFiles: skill-card.md (2470b), SKILL.md (4989b), _meta.json (130b)\n\nFile v2.17.1:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.17.0\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v2.17.1:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.17.1\",\n  \"publishedAt\": 1780308453566\n}\n\nFile v2.17.1:skill-card.md\n\n## Description: <br>\nTrack AI agent API calls, analyze token usage, and optimize costs for OpenAI, Anthropic, Google, DeepSeek, and related LLM APIs. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and AI agent operators use this skill to inspect API spending, token usage, latency, error rates, and model-level cost drivers. It helps agents suggest cost optimization steps and generate usage reports from locally recorded traces. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: The quick start installs executable Python code from a GitHub repository. <br>\nMitigation: Review the referenced package and its dependencies before installation, especially in production or shared environments. <br>\nRisk: The tool stores API usage records locally for reporting, which may expose sensitive prompt, response, or usage metadata if recorded. <br>\nMitigation: Avoid recording sensitive prompts or responses unless local storage is acceptable, and periodically clean the local database. <br>\nRisk: Cost estimates use list prices and may differ from actual provider billing, discounts, or unknown model pricing. <br>\nMitigation: Treat generated savings guidance as advisory and verify costs against provider billing data before making budget decisions. <br>\n\n\n## Reference(s): <br>\n- [Agent Lens GitHub repository](https://github.com/lrg913427-dot/agent-lens.git) <br>\n- [Agent Lens on ClawHub](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n- [Publisher profile](https://clawhub.ai/user/lrg913427-dot) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [text, markdown, shell commands, code, guidance] <br>\n**Output Format:** [Markdown with inline shell commands and Python examples] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May include local CLI commands, Python integration snippets, cost reports, token counts, latency summaries, and optimization guidance.] <br>\n\n## Skill Version(s): <br>\n2.17.1 (source: server release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nArchive v2.17.0: 3 files, 3728 bytes\n\nFiles: skill-card.md (2149b), SKILL.md (4989b), _meta.json (130b)\n\nFile v2.17.0:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.16.0\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v2.17.0:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.17.0\",\n  \"publishedAt\": 1780243375823\n}\n\nFile v2.17.0:skill-card.md\n\n## Description: <br>\nAgent Lens helps agents track AI API calls, analyze token usage, monitor latency and errors, and estimate costs across common LLM providers. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent operators use this skill to monitor LLM spending, inspect token consumption, debug API-call behavior, and generate cost reports for supported providers. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: Recorded traces may include more than usage metadata depending on how the package is integrated. <br>\nMitigation: Inspect the package behavior, pin a reviewed commit, and confirm what trace fields are stored before using it in sensitive projects. <br>\nRisk: Cost reports are estimates and may not match actual provider billing, discounts, or custom pricing. <br>\nMitigation: Compare reported costs with provider billing records before making budget or procurement decisions. <br>\nRisk: Local SQLite trace storage can grow over time. <br>\nMitigation: Use the documented cleanup workflow periodically and apply local data-retention controls appropriate for the project. <br>\n\n\n## Reference(s): <br>\n- [ClawHub skill page](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [guidance, shell commands, code, configuration] <br>\n**Output Format:** [Markdown with inline shell commands and Python examples] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May include CLI workflows, integration snippets, and cost-optimization recommendations.] <br>\n\n## Skill Version(s): <br>\n2.17.0 (source: server release metadata; artifact frontmatter reports 2.16.0) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nArchive v2.16.0: 3 files, 3626 bytes\n\nFiles: skill-card.md (1971b), SKILL.md (4989b), _meta.json (130b)\n\nFile v2.16.0:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.15.0\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v2.16.0:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.16.0\",\n  \"publishedAt\": 1780135385804\n}\n\nFile v2.16.0:skill-card.md\n\n## Description: <br>\nTrack AI agent API calls, analyze token usage, and optimize costs for OpenAI, Anthropic, Google, DeepSeek, and related LLM APIs. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent operators use this skill to track LLM API calls, inspect token usage, compare costs by model or provider, and generate reports that support cost optimization. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: The skill asks users to install live code from a referenced Git repository. <br>\nMitigation: Review the referenced repository before installation and use normal dependency review practices for the execution environment. <br>\nRisk: Local usage records may accumulate under ~/.agent-lens and could contain operational metadata about API usage. <br>\nMitigation: Treat the local database as potentially sensitive and use the documented clean command when retention should be limited. <br>\n\n\n## Reference(s): <br>\n- [ClawHub Skill Page](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n- [Publisher Profile](https://clawhub.ai/user/lrg913427-dot) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [text, markdown, code, shell commands, guidance] <br>\n**Output Format:** [Markdown with Python and shell command snippets] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May guide agents to run the agent-lens CLI and record local usage data in SQLite.] <br>\n\n## Skill Version(s): <br>\n2.16.0 (source: server release evidence) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nArchive v2.15.0: 3 files, 3834 bytes\n\nFiles: skill-card.md (2417b), SKILL.md (4989b), _meta.json (130b)\n\nFile v2.15.0:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.15.0\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v2.15.0:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.15.0\",\n  \"publishedAt\": 1779984120155\n}\n\nFile v2.15.0:skill-card.md\n\n## Description: <br>\nTrack AI agent API calls, analyze token usage, and optimize costs for OpenAI, Anthropic, Google, DeepSeek, and related LLM APIs. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and engineers use Agent Lens to monitor LLM API calls, token usage, latency, errors, and model-level cost drivers. It helps investigate high API bills, compare model costs, and generate usage reports. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: Local usage records may contain sensitive API usage details such as token counts, model names, agent names, timestamps, errors, or captured request details. <br>\nMitigation: Store the local database according to the user's data handling requirements and limit access to trusted users and systems. <br>\nRisk: The local SQLite database can grow over time as traces accumulate. <br>\nMitigation: Use the documented cleanup workflow, such as `agent-lens clean --before <ts>`, and periodically remove old records. <br>\nRisk: Production use depends on an external GitHub package referenced by the skill. <br>\nMitigation: Inspect the external package and its dependencies before using it in production or regulated environments. <br>\n\n\n## Reference(s): <br>\n- [Agent Lens on ClawHub](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n- [Publisher profile](https://clawhub.ai/user/lrg913427-dot) <br>\n- [GitHub package URL listed in SKILL.md](https://github.com/lrg913427-dot/agent-lens.git) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [text, markdown, code, shell commands, configuration, guidance] <br>\n**Output Format:** [Markdown guidance with bash and Python code blocks] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May recommend CLI commands, Python integration snippets, JSON or CSV exports, and local SQLite cleanup commands.] <br>\n\n## Skill Version(s): <br>\n2.15.0 (source: SKILL.md frontmatter and server release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nArchive v2.14.0: 3 files, 3751 bytes\n\nFiles: skill-card.md (2283b), SKILL.md (4989b), _meta.json (130b)\n\nFile v2.14.0:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.13.0\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v2.14.0:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.14.0\",\n  \"publishedAt\": 1779876190065\n}\n\nFile v2.14.0:skill-card.md\n\n## Description: <br>\nTrack AI agent API calls, analyze token usage, and optimize costs for OpenAI, Anthropic, Google, DeepSeek, and other model providers. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and AI agent operators use Agent Lens to monitor local AI API usage, inspect token consumption, review latency and error rates, and generate cost reports for model-provider calls. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: Local trace data and exported reports may contain private usage, prompt, cost, or workflow information. <br>\nMitigation: Treat ~/.agent-lens/traces.db and exported reports as private data, avoid logging secrets or sensitive prompts where possible, and protect exported files. <br>\nRisk: Stored records can accumulate over time and increase local data exposure. <br>\nMitigation: Periodically clean old records with the skill's cleanup workflow and retain only records needed for monitoring or reporting. <br>\nRisk: Cost reports are estimates and may not match provider invoices or discounts. <br>\nMitigation: Use Agent Lens reports for operational analysis and confirm billing-critical decisions against provider billing records. <br>\n\n\n## Reference(s): <br>\n- [Agent Lens on ClawHub](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n- [lrg913427-dot publisher profile](https://clawhub.ai/user/lrg913427-dot) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [Guidance, Markdown, Code, Shell commands] <br>\n**Output Format:** [Markdown with inline shell and Python code blocks] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May include CLI commands, Python tracking snippets, local database guidance, and cost-optimization recommendations.] <br>\n\n## Skill Version(s): <br>\n2.14.0 (source: server release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nArchive v2.13.1: 3 files, 3575 bytes\n\nFiles: skill-card.md (1790b), SKILL.md (4989b), _meta.json (130b)\n\nFile v2.13.1:SKILL.md\n\n---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.13.0\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the most?\n3. **Check token efficiency**: Are prompts too long?\n4. **Suggest cheaper alternatives**:\n   - gpt-4o → gpt-4o-mini (10x cheaper)\n   - claude-3.5-sonnet → claude-3.5-haiku (4x cheaper)\n   - gpt-4 → gpt-4o (2x cheaper)\n5. **Check caching**: Are there repeated prompts?\n6. **Check error rate**: `agent-lens report --by status`\n\n## Token Counting\n\n```python\nimport tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")\n```\n\n## Supported Models\n\nPricing data for: OpenAI (GPT-4o, o1, o3), Anthropic (Claude 3.5/4), Google (Gemini 2.x), DeepSeek, Mistral, Qwen, GLM, MiMo.\n\nUnknown models are tracked but cost shows \"—\".\n\n## Integration with Hermes\n\n```python\n# Track Hermes agent API calls\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"hermes-main\")\n\n# In your agent loop:\nwith lens.trace(model=config.model) as t:\n    response = agent.run_conversation(message)\n    t.input_tokens = response.get(\"input_tokens\", 0)\n    t.output_tokens = response.get(\"output_tokens\", 0)\n```\n\n## Data Storage\n\nSQLite at `~/.agent-lens/traces.db`. Fully local, no cloud service needed.\n\n## Pitfalls\n\n- Token extraction auto-works only for OpenAI-compatible response format\n- For non-OpenAI providers, manually set `t.input_tokens` and `t.output_tokens`\n- Cost estimates use list prices; actual costs may differ with discounts\n- Database grows over time; use `agent-lens clean` periodically\n\n## Verification\n\n```bash\nagent-lens demo        # Generate 20 sample records\nagent-lens stats       # Should show 20 calls\nagent-lens cost        # Should show cost breakdown by model\n```\n\nFile v2.13.1:_meta.json\n\n{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.13.1\",\n  \"publishedAt\": 1779768150735\n}\n\nFile v2.13.1:skill-card.md\n\n## Description: <br>\nTrack AI agent API calls, analyze token usage, and optimize costs for OpenAI, Anthropic, Google, DeepSeek, and related LLM APIs. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and engineers use Agent Lens to monitor LLM API spending, inspect token usage, review latency and error patterns, and generate cost reports while optimizing prompts and model choices. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: Local API usage metadata may reveal sensitive model usage patterns, costs, or prompts if the local trace database is exposed. <br>\nMitigation: Install only if comfortable with the external package and review or clean ~/.agent-lens/traces.db when usage patterns, costs, or prompts are sensitive. <br>\n\n\n## Reference(s): <br>\n- [Agent Lens on ClawHub](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [text, markdown, code, shell commands, configuration, guidance] <br>\n**Output Format:** [Markdown with inline bash and Python code blocks] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [Guidance may include CLI commands, Python snippets, cost-analysis workflows, and local SQLite storage considerations.] <br>\n\n## Skill Version(s): <br>\n2.13.1 (source: server release evidence) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>","readmeExcerpt":"Skill: Agent Lens Owner: lrg913427-dot Summary: Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or... Tags: latest:3.0.0 Version history: v2.17.3 | 2026-06-13T10:01:59.198Z | auto - Version bumped from 2.17.0 to 2.17.2 in SKILL.md. - Internal documentation updated; no functional or interface changes to features o","codeSnippets":[],"executableExamples":[{"language":"bash","snippet":"# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent"},{"language":"python","snippet":"from agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")"},{"language":"python","snippet":"from agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens"},{"language":"python","snippet":"from agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)"},{"language":"python","snippet":"from agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ..."},{"language":"python","snippet":"import tiktoken\n\ndef count_tokens(text: str, model: str = \"gpt-4o\") -> int:\n    \"\"\"Count tokens for a given model.\"\"\"\n    try:\n        enc = tiktoken.encoding_for_model(model)\n    except KeyError:\n        enc = tiktoken.get_encoding(\"cl100k_base\")\n    return len(enc.encode(text))\n\n# Check before sending\nprompt = \"Your long prompt here...\"\ntokens = count_tokens(prompt)\nprint(f\"Prompt: {tokens} tokens\")\nprint(f\"Estimated cost: ${tokens * 2.50 / 1_000_000:.4f}\")"}],"parameters":null,"dependencies":[],"permissions":[],"extractedFiles":[{"path":"SKILL.md","content":"---\nname: agent-lens\ndescription: \"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or generate cost reports for OpenAI/Anthropic/Google/DeepSeek APIs.\"\nversion: 2.17.2\nauthor: lrg913427-dot\nlicense: MIT\nmetadata:\n  hermes:\n    tags: [llm, cost, tracking, observability, tokens, api, monitoring, agent]\n    related_skills: [db-explorer]\n---\n\n# Agent Lens\n\nTrack every AI API call, analyze token usage, and optimize costs.\n\n## When to Use\n\nActivate this skill when the user:\n- Says \"how much am I spending\", \"token usage\", \"API costs\"\n- Wants to know which model is most expensive\n- Needs to optimize prompt costs\n- Wants to track API call latency or error rates\n- Mentions \"budget\", \"cost optimization\", or \"token counting\"\n- Asks \"why is my API bill so high\"\n\n## Quick Start\n\n```bash\n# Install\npip install git+https://github.com/lrg913427-dot/agent-lens.git\n\n# Generate demo data and see it in action\nagent-lens demo\n\n# View stats\nagent-lens stats\nagent-lens cost\nagent-lens recent\n```\n\n## Three Ways to Track\n\n### 1. Decorator (easiest)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\n@lens.track(model=\"gpt-4o\")\ndef call_api(prompt):\n    return client.chat.completions.create(\n        model=\"gpt-4o\",\n        messages=[{\"role\": \"user\", \"content\": prompt}],\n    )\n\n# Token usage is auto-extracted from OpenAI-style responses\nresult = call_api(\"Hello\")\n```\n\n### 2. Context Manager (flexible)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\n\nwith lens.trace(model=\"claude-3.5-sonnet\") as t:\n    result = client.chat.completions.create(...)\n    t.input_tokens = result.usage.prompt_tokens\n    t.output_tokens = result.usage.completion_tokens\n```\n\n### 3. Direct Record (manual)\n\n```python\nfrom agent_lens import AgentLens\n\nlens = AgentLens(agent_name=\"my-agent\")\nlens.record(\n    model=\"gpt-4o\",\n    input_tokens=1500,\n    output_tokens=800,\n    latency_ms=2300,\n)\n```\n\n### Global Shortcuts\n\n```python\nfrom agent_lens import record, trace, track\n\nrecord(model=\"gpt-4o\", input_tokens=100, output_tokens=50)\n\nwith trace(model=\"gpt-4o\") as t:\n    ...\n\n@track(model=\"gpt-4o\")\ndef my_func():\n    ...\n```\n\n## CLI Commands\n\n| Command | Description |\n|---------|-------------|\n| `agent-lens stats` | Overview: total calls, tokens, cost |\n| `agent-lens report --by model` | Breakdown by model/provider/agent |\n| `agent-lens cost` | Cost ranking with percentage bars |\n| `agent-lens recent -n 10` | Latest API calls |\n| `agent-lens top` | Most expensive calls |\n| `agent-lens export --json` | Export to JSON |\n| `agent-lens export -o data.csv` | Export to CSV |\n| `agent-lens clean --before <ts>` | Clean old data |\n| `agent-lens demo` | Generate sample data |\n\n## Cost Optimization Workflow\n\nWhen user asks \"how can I save money\":\n\n1. **Run cost report**: `agent-lens cost`\n2. **Identify expensive models**: Which models cost the m"},{"path":"_meta.json","content":"{\n  \"ownerId\": \"kn78qy8qw1m82vx09qkaawp9c985z0mn\",\n  \"slug\": \"agent-lens\",\n  \"version\": \"2.17.3\",\n  \"publishedAt\": 1781344919198\n}"},{"path":"skill-card.md","content":"## Description: <br>\nTrack AI agent API calls, analyze token usage, and optimize costs for OpenAI, Anthropic, Google, DeepSeek, and other LLM APIs. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[lrg913427-dot](https://clawhub.ai/user/lrg913427-dot) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent operators use this skill to instrument local LLM API calls, inspect token consumption, report costs, and identify expensive models, long prompts, repeated calls, latency issues, or error patterns. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: API telemetry may reveal model choices, usage patterns, costs, and call metadata when used on sensitive workloads. <br>\nMitigation: Review what the referenced Python package records before connecting sensitive workloads, and protect or periodically clean its local SQLite database according to retention needs. <br>\n\n\n## Reference(s): <br>\n- [Agent Lens on ClawHub](https://clawhub.ai/lrg913427-dot/agent-lens) <br>\n- [lrg913427-dot publisher profile](https://clawhub.ai/user/lrg913427-dot) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [Text, Markdown, Code, Shell commands, Guidance] <br>\n**Output Format:** [Markdown with inline shell commands, Python snippets, and operational guidance] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May include cost-analysis steps, CLI command suggestions, token-counting snippets, and local SQLite data-handling guidance.] <br>\n\n## Skill Version(s): <br>\n2.17.3 (source: server release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>"}],"languages":[],"docsSourceLabel":"CLAWHUB","editorialOverview":"Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or... Skill: Agent Lens Owner: lrg913427-dot Summary: Track AI agent API calls, analyze token usage, and optimize costs. Use when user wants to monitor LLM spending, debug API calls, track token consumption, or... Tags: latest:3.0.0 Version history: v2.17.3 | 2026-06-13T10:01:59.198Z | auto - Version bumped from 2.17.0 to 2.17.2 in SKILL.md. - Internal documentation updated; no functional or interface changes to features o","editorialQuality":{"score":100,"threshold":65,"status":"ready","wordCount":1041,"uniquenessScore":47,"reasons":[]}},"media":{"evidence":{"source":"no-media","verified":false,"confidence":"low","updatedAt":"2026-10-09T12:11:21.503Z","emptyReason":"No screenshots, media assets, or demo links are available."},"primaryImageUrl":null,"mediaAssetCount":0,"assets":[],"demoUrl":null},"ownerResources":{"evidence":{"source":"unclaimed","verified":false,"confidence":"low","updatedAt":"2026-10-09T12:11:21.503Z","emptyReason":"This page has not been claimed by the agent owner."},"hasCustomPage":false,"customPageUpdatedAt":null,"customLinks":[],"structuredLinks":{"docsUrl":null,"demoUrl":null,"supportUrl":null,"pricingUrl":null,"statusUrl":null},"customPage":null},"relatedAgents":{"evidence":{"source":"protocol-neighbors","verified":false,"confidence":"medium","updatedAt":"2026-10-10T00:44:38.299Z","emptyReason":null},"items":[{"id":"8ebccd8e-3863-4187-8355-c3f14e1f9edf","entityType":"agent","canonicalPath":"/agent/iofficeai-aionui","slug":"iofficeai-aionui","name":"AionUi","description":"Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!","url":"https://github.com/iOfficeAI/AionUi","homepage":"https://www.aionui.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-10-09T19:11:12.944Z","createdAt":"2026-02-25T03:38:16.584Z","downloads":null},{"id":"b917f68a-ebff-438e-84f8-3f4b2494c0bc","entityType":"agent","canonicalPath":"/agent/activepieces-activepieces","slug":"activepieces-activepieces","name":"activepieces","description":"AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents","url":"https://github.com/activepieces/activepieces","homepage":"https://www.activepieces.com","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-15T02:22:12.426Z","createdAt":"2026-02-25T03:38:12.412Z","downloads":null},{"id":"5cb26759-3a39-483f-94cf-276a98c13bb8","entityType":"agent","canonicalPath":"/agent/cherryhq-cherry-studio","slug":"cherryhq-cherry-studio","name":"cherry-studio","description":"AI productivity studio with smart chat, autonomous agents, and 300+ assistants. Unified access to frontier LLMs","url":"https://github.com/CherryHQ/cherry-studio","homepage":"https://cherry-ai.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-11T14:38:40.986Z","createdAt":"2026-02-25T03:38:19.379Z","downloads":null},{"id":"6f6582d0-5d76-4f0f-b81d-86520247950b","entityType":"agent","canonicalPath":"/agent/copilotkit-copilotkit","slug":"copilotkit-copilotkit","name":"CopilotKit","description":"The Frontend for Agents & Generative UI. React + Angular","url":"https://github.com/CopilotKit/CopilotKit","homepage":"https://docs.copilotkit.ai","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-03-25T09:50:57.846Z","createdAt":"2026-02-25T03:39:14.617Z","downloads":null}],"links":{"hub":"/agent","source":"/agent/source/clawhub","protocols":[{"label":"OpenClaw","href":"/agent/protocol/openclew"}]}}}