{"id":47978399,"url":"https://github.com/runcycles/cycles-runaway-demo","last_synced_at":"2026-04-04T10:59:09.180Z","repository":{"id":344379163,"uuid":"1181589231","full_name":"runcycles/cycles-runaway-demo","owner":"runcycles","description":"Demo: How Cycles prevents runaway AI agent spend ($6 in 30s → hard stop at $1)","archived":false,"fork":false,"pushed_at":"2026-03-28T13:21:26.000Z","size":5856,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-04T10:58:52.001Z","etag":null,"topics":["ai-agents","budget","cost-control","demo","llm","runaway-agent"],"latest_commit_sha":null,"homepage":"https://runcycles.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/runcycles.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-14T10:54:57.000Z","updated_at":"2026-03-30T00:26:47.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/runcycles/cycles-runaway-demo","commit_stats":null,"previous_names":["runcycles/cycles-runaway-demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/runcycles/cycles-runaway-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runcycles%2Fcycles-runaway-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runcycles%2Fcycles-runaway-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runcycles%2Fcycles-runaway-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runcycles%2Fcycles-runaway-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/runcycles","download_url":"https://codeload.github.com/runcycles/cycles-runaway-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runcycles%2Fcycles-runaway-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31397056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-agents","budget","cost-control","demo","llm","runaway-agent"],"created_at":"2026-04-04T10:59:09.105Z","updated_at":"2026-04-04T10:59:09.172Z","avatar_url":"https://github.com/runcycles.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cycles Runaway Demo\n\nA runaway agent burns $6 in 30 seconds. Cycles stops it at $1.\n\nSame agent. Same bug. Two outcomes.\n\n## The scenario\n\nA customer support bot drafts a response, evaluates its quality, and refines it in a loop until the quality score exceeds 8.0. The bug: the quality evaluator never returns above 6.9. Without a budget boundary, the agent loops forever — burning tokens with no exit condition. With Cycles, the server returns `409 BUDGET_EXCEEDED` before the next call can proceed, and the agent stops cleanly.\n\nNo real LLM is used. All calls are simulated at 50ms latency. The cost math is real.\n\n## Run it\n\nPrerequisites: Docker Compose v2+, Python 3.10+, `curl`\n\n```bash\ngit clone https://github.com/runcycles/cycles-runaway-demo\ncd cycles-runaway-demo\npython3 -m venv .venv \u0026\u0026 source .venv/bin/activate\npip install -r agent/requirements.txt\n./demo.sh\n```\n\nThat's it. The script starts the Cycles stack (Redis + server + admin), provisions a tenant and budget, then runs both modes back to back.\n\nRun a single mode:\n\n```bash\n./demo.sh unguarded    # without Cycles (~30s)\n./demo.sh guarded      # with Cycles (stops at $1.00)\n./demo.sh both         # both back to back (default)\n```\n\nRe-runs just work — the script resets the stack automatically to ensure a fresh budget.\n\nStop the stack when done:\n\n```bash\n./teardown.sh\n```\n\n### Windows (WSL)\n\nThe demo runs on Windows 11 via WSL. Install [Docker Desktop for Windows](https://docs.docker.com/get-docker/) with the WSL 2 backend enabled (the default), then inside your WSL terminal:\n\n```bash\nsudo apt update \u0026\u0026 sudo apt install -y python3-full curl\ngit clone https://github.com/runcycles/cycles-runaway-demo\ncd cycles-runaway-demo\npython3 -m venv .venv \u0026\u0026 source .venv/bin/activate\npip install -r agent/requirements.txt\n./demo.sh\n```\n\nDocker Desktop shares the daemon between Windows and WSL automatically — no extra configuration needed.\n\n\u003e **Note:** Ubuntu 23.04+ requires `python3-full` (not just `python3`) so that venvs get their own pip. Without it, even `pip` inside a venv hits the PEP 668 \"externally-managed-environment\" error.\n\n### First run notes\n\nThe first run pulls three Docker images (~200MB total). You'll see Docker's pull progress. Subsequent runs start in seconds.\n\n## What you'll see\n\n![Cycles Runaway Demo](demo.gif)\n\n### Without Cycles\n\nA live terminal display (no scroll flood) shows three panels updating in-place:\n\n- **Live Counter** — call count climbing, spend in dollars, current action with quality score\n- **Budget Thresholds** — the $0.10 threshold crossed in red; $0.50 and $1.00 showing \"X% to go\"\n- **Projection** — extrapolated cost rate: $/min, $/hr, $/day plus a real-LLM estimate (~$3.60/hr per stuck ticket)\n\nAfter 30 seconds the demo auto-terminates. The final red panel reads:\n\u003e *\"In production: no hard stop existed. Alert fires AFTER spend.\"*\n\nIn 30s at simulation speed, the agent makes ~600 calls and spends ~$6.00. The projection panel shows what happens if you don't catch it — the hourly and daily rates are the scary numbers.\n\n### With Cycles (budget: $1.00)\n\nThe same counter, the same loop, the same bug. The display is identical — same panels, same structure. But when cumulative spend reaches $1.00 (after ~100 calls), the Cycles server returns `409 BUDGET_EXCEEDED` on the next reservation attempt. The `@cycles` decorator raises `BudgetExceededError`, the agent catches it, and the loop ends cleanly. The final green panel reads:\n\u003e *\"Cycles stopped the agent BEFORE call N+1 could proceed.\"*\n\n### Expected output\n\n```\n⚡ Cycles — Runaway Agent Demo\n\nResetting stack (clean budget state)...\n\n  [Docker compose output]\n\nWaiting for services to be healthy...\nProvisioning tenant and budget...\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n  MODE 1: Without Cycles\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n  [live panels update in-place for ~30s]\n\n╭──────────────── Final — UNGUARDED ─────────────────╮\n│ Result:   auto-stop after 30s                      │\n│ Calls:    ~595                                     │\n│ Spend:    ~$5.95                                   │\n│ Duration: 30.0s                                    │\n│                                                    │\n│ In production: no hard stop existed.               │\n│ Alert fires AFTER spend.                           │\n╰────────────────────────────────────────────────────╯\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n  MODE 2: With Cycles (budget: $1.00)\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\n  [live panels update in-place until budget hit]\n\n╭───────────────── Final — GUARDED ──────────────────╮\n│ Result:   BUDGET_EXCEEDED — Cycles server          │\n│           returned 409                             │\n│ Calls:    100                                      │\n│ Spend:    $1.0000                                  │\n│ Duration: ~8s                                      │\n│                                                    │\n│ Cycles stopped the agent BEFORE call 101           │\n│ could proceed.                                     │\n╰────────────────────────────────────────────────────╯\n\nDemo complete.\n  Swagger UI:   http://localhost:7878/swagger-ui.html\n  Admin UI:     http://localhost:7979/swagger-ui.html\n  Re-run:       ./demo.sh\n  Stop stack:   ./teardown.sh\n```\n\n## The code change\n\nThe diff between `agent/unguarded.py` and `agent/guarded.py` is:\n\n```python\n# --- Import the SDK ---\nfrom runcycles import BudgetExceededError, CyclesClient, CyclesConfig, cycles, set_default_client\n\n# --- Initialize the client ---\ndef _setup():\n    config = CyclesConfig(\n        base_url=os.environ[\"CYCLES_BASE_URL\"],\n        api_key=os.environ[\"CYCLES_API_KEY\"],\n        tenant=os.environ[\"CYCLES_TENANT\"],\n        workspace=\"default\",\n        app=\"default\",\n        workflow=\"default\",\n        agent=\"support-bot\",\n    )\n    set_default_client(CyclesClient(config))\n\n# --- Add three decorators ---\n@cycles(estimate=COST_PER_CALL_MICROCENTS, action_kind=\"llm.completion\", action_name=\"draft-response\")\ndef draft_response(ticket_text: str) -\u003e str: ...\n\n@cycles(estimate=COST_PER_CALL_MICROCENTS, action_kind=\"llm.completion\", action_name=\"evaluate-quality\")\ndef evaluate_quality(draft: str) -\u003e float: ...\n\n@cycles(estimate=COST_PER_CALL_MICROCENTS, action_kind=\"llm.completion\", action_name=\"refine-response\")\ndef refine_response(draft: str, score: float) -\u003e str: ...\n\n# --- Catch the budget exception ---\nexcept BudgetExceededError:\n    # agent stops cleanly\n```\n\nThree decorators. One except. That is the entire integration.\n\n## Why this matters\n\nRate limits cap velocity, not total exposure. Observability alerts fire after the damage. Provider caps are per-provider and per-key. Cycles enforces a hard ceiling **before** the next call is made — across providers, tenants, and agents.\n\n## Next steps\n\nAfter running the demo, explore how to add Cycles to your own application:\n\n- [What is Cycles?](https://runcycles.io/quickstart/what-is-cycles) — understand the problem and the solution\n- [End-to-End Tutorial](https://runcycles.io/quickstart/end-to-end-tutorial) — zero to a working budget-guarded app in 10 minutes\n- [Choose a First Rollout](https://runcycles.io/quickstart/how-to-choose-a-first-cycles-rollout-tenant-budgets-run-budgets-or-model-call-guardrails) — decide your adoption strategy\n- [Adding Cycles to an Existing App](https://runcycles.io/how-to/adding-cycles-to-an-existing-application) — incremental adoption guide\n- [Full Documentation](https://runcycles.io) — complete docs at runcycles.io\n\n## Links\n\n- Protocol: https://github.com/runcycles/cycles-protocol\n- Server:   https://github.com/runcycles/cycles-server\n- Python:   `pip install runcycles`\n- Java:     `io.runcycles:cycles-client-java-spring`\n- Node.js:  `npm install runcycles`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruncycles%2Fcycles-runaway-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruncycles%2Fcycles-runaway-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruncycles%2Fcycles-runaway-demo/lists"}