{"slug": "my-hermes-agent-spent-3-before-i-noticed-now-it-can-t", "title": "My Hermes agent spent $3 before I noticed. Now it can't.", "summary": "A developer accidentally spent $3 on a Hermes research agent running across 50 literature review tasks after forgetting to check the bill until the next morning, with the agent retrying failed web searches at a cost each time. The fix is `agent-cost-guard`, a Python library that tracks costs as they accumulate and stops execution when a user-defined limit is hit. The tool also supports warning callbacks at configurable thresholds and per-label cost breakdowns for logging or blocking modes.", "body_md": "*This is a submission for the Hermes Agent Challenge.*\n\nI ran a Hermes research agent across 50 literature review tasks and forgot to check the bill until the next morning. Three dollars gone. The agent had retried a bunch of failed web searches and each retry cost money.\n\nThe fix is obvious in hindsight: track cost as you go and stop when you hit the limit. That's `agent-cost-guard`\n\n.\n\n``` python\nfrom agent_cost_guard import CostGuard\n\nguard = CostGuard(limit_usd=1.00)\n\n# Inside your agent loop:\nresponse = client.messages.create(model=\"claude-sonnet-4-5\", ...)\ncost = calculate_cost(response.usage)\nguard.add(cost, label=\"research_turn\")  # raises CostLimitExceeded if over $1\npython\ndef on_warn(w):\n    log.warning(f\"Cost at {w.pct_used:.0%} — ${w.total_usd:.4f} of ${w.limit_usd:.4f}\")\n\nguard = CostGuard(\n    limit_usd=1.00,\n    warn_at=[0.5, 0.8],\n    on_warn=on_warn,\n)\n```\n\nThe callback fires once per threshold and never again unless you call `guard.reset()`\n\n.\n\n```\nguard.add(0.05, label=\"web_search\")\nguard.add(0.12, label=\"llm_synthesis\")\nguard.add(0.03, label=\"web_search\")\n\ns = guard.summary()\nprint(s.by_label)\n# {\"web_search\": 0.08, \"llm_synthesis\": 0.12}\n```\n\nNow you know where the money went.\n\n```\nguard = CostGuard(limit_usd=0.50, stop_on_limit=False)\nguard.add(1.00)  # no exception\nprint(guard.ok)         # False\nprint(guard.remaining_usd)  # -0.50\n```\n\nUseful for logging-only mode when you want to measure but not block.\n\n```\nguard.check()  # raises CostLimitExceeded if total > limit\n```\n\nCall it at checkpoints rather than after every single add.\n\n```\ns = guard.summary()\nprint(str(s))\n# Cost: $0.20 / $1.00 (20.0% used)\n# Entries: 3\n# Breakdown:\n#   llm_synthesis: $0.12\n#   web_search: $0.08\npython\nfrom agent_cost_guard import make_cost_guard\n\nguard = make_cost_guard(limit_usd=1.00, on_warn=on_warn)\n# warn_at defaults to [0.5, 0.8]\n```\n\nStandard library only: `dataclasses`\n\n, `time`\n\n. Nothing else.\n\n```\npip install agent-cost-guard\n```\n\n", "url": "https://wpnews.pro/news/my-hermes-agent-spent-3-before-i-noticed-now-it-can-t", "canonical_source": "https://dev.to/mukundakatta/my-hermes-agent-spent-3-before-i-noticed-now-it-cant-37dk", "published_at": "2026-05-25 21:21:13+00:00", "updated_at": "2026-05-25 21:33:42.871141+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "ai-infrastructure", "ai-research", "mlops"], "entities": ["Hermes", "CostGuard", "Claude Sonnet 4-5"], "alternates": {"html": "https://wpnews.pro/news/my-hermes-agent-spent-3-before-i-noticed-now-it-can-t", "markdown": "https://wpnews.pro/news/my-hermes-agent-spent-3-before-i-noticed-now-it-can-t.md", "text": "https://wpnews.pro/news/my-hermes-agent-spent-3-before-i-noticed-now-it-can-t.txt", "jsonld": "https://wpnews.pro/news/my-hermes-agent-spent-3-before-i-noticed-now-it-can-t.jsonld"}}