Cost attribution — fine-grained cost tracking per tool, agent, and workflow. Tracks token costs at multiple granularities: per-tool-call, per-agent, per-workflow, and per-session. Enables cost optimization and billing. Usage:: tracker = CostTracker() with tracker.track_call("Bash
# Source: https://github.com/aiming-lab/AutoHarness | License: MIT | Copyright 2026 AgentLint Contributors
# Provided via justclaw.it.com; keep this notice with the code.
"""Cost attribution — fine-grained cost tracking per tool, agent, and workflow.
Tracks token costs at multiple granularities: per-tool-call, per-agent,
per-workflow, and per-session. Enables cost optimization and billing.
Usage::
tracker = CostTracker()
with tracker.track_call("Bash", agent_id="explore-1") as call:
# ... execute tool call ...
call.record_tokens(input=1200, output=300)
report = tracker.generate_report()
print(report.by_tool) # {"Bash": $0.012, "Read": $0.003, ...}
print(report.by_agent) # {"explore-1": $0.015, "plan-1": $0.008}
print(report.total_cost) #
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key