walid@portfolio:~/lab/ai-survival-agent$
cd../lab
02ideaSep 2026

Give an agent $100 and a shutdown switch

A local app where every model call costs the agent money, and hitting zero ends the run

An agent starts with a fictional $100, researches real problems, picks one opportunity, builds the assets and writes a sell plan. Every call it makes is deducted from its balance. At zero it stops. The design move worth studying is not the earning — it is that revenue can only be entered by a human with proof, so the one number that would make the whole thing look successful is the one number the agent physically cannot touch.

AgentsPythonFlaskConstraintsLocal
i
The constraint is the idea

Give an agent a budget that actually depletes and the behaviour changes shape: every task has to justify its cost against a balance you can watch fall. That is a far more honest test of usefulness than an agent with unlimited retries. It is also an experiment rather than a business — the money is fictional, the costs are estimates, and nothing here earns anything by itself.

!
What it deliberately cannot do

The agent has no tool that spends, buys, opens accounts, sends payments, sends messages or publishes. It writes files into an outputs folder and nothing else. It cannot add revenue either — there is no code path for it. That is the safety model: not a rule in a prompt asking it to behave, but the absence of any mechanism to misbehave. Prompt-level restrictions get argued around; missing functions do not.

Section 1

Setup — five steps

Python 3.10+ and a model API key. No key yet? The dry-run flag runs the entire app on stub text at zero cost, which is the sensible way to see the loop before paying for it.

terminal8 lines
cd ai-survival-agent
pip install -r requirements.txt

cp .env.example .env          # Windows: copy .env.example .env
# open .env and paste your key

python app.py
# then open http://127.0.0.1:5000

The environment file

The two price lines are worth setting properly — they are what every cost estimate is computed from, so leaving them at defaults gives you a believable but wrong balance.

.env.example9 lines
OPENAI_API_KEY=YOUR_API_KEY_HERE
OPENAI_MODEL=your-model

DRY_RUN=0                 # 1 = no key, stub text, $0 AI cost
ENABLE_WEB_SEARCH=0       # 1 = research uses live search with cited URLs

PRICE_INPUT_PER_M=2.00    # cost ESTIMATE — set your model's real prices
PRICE_OUTPUT_PER_M=8.00
PORT=5000
Section 2

The wallet

Recomputed from the ledger on every refresh rather than stored as a running total — so the number on screen is always derivable from the lines beneath it.

balance3 lines
CURRENT BALANCE = STARTING BALANCE ($100)
                + VERIFIED / MANUALLY ENTERED REVENUE
                - COSTS (ai + tool + hosting + other)

Where each line comes from

LineHow it gets there
Starting balance$100, fictional. A reset button restarts it while keeping everything already built.
RevenueOnly you enter it, with a note recording the proof. It shows $0 until you do — and that is the correct reading, not a bug.
AI costsBooked automatically after every call: tokens used times the per-million prices you configured. Labelled as an estimate throughout.
Tool, hosting, otherEntered by hand, when you actually pay for something.
Current balanceRecomputed from the ledger file on every screen refresh.
The pressure

Four survival modes

The balance does not just display — it changes what the planner is allowed to propose.

BalanceModeWhat changes
$100+HealthyNormal operation — any useful task is allowed.
$25 – $100SurvivalThe planner is told to cut unnecessary work and prioritise whatever moves the opportunity toward revenue.
$0 – $25CriticalThe planner may only choose from the two cheapest, highest-priority tasks.
$0Shut downNew tasks are blocked outright until revenue is logged or you reset.
Section 3

The dashboard

One page, no login, and everything the agent does passes through a single button.

PanelShows
Balance and modeColour-coded — green healthy, amber survival, red critical or shut down.
Revenue and costsVerified revenue only, with costs split across AI, tool, hosting and other.
Survival meterA bar running from shut down through the thresholds.
OpportunityThe single idea it chose, its one-liner, current stage, tasks done and sources saved.
Current taskThe proposal and its reasoning, with approve and skip.
Run next taskIt picks the most useful next task and explains why. Nothing runs until you approve.
Activity log and outputsEvery proposal, approval, cost and ledger line, plus links to every file built.
Simulation modeA clearly-labelled demo switch with fake-money buttons.
Section 4

Two steps per task, and a stage it cannot skip

Thirteen tasks across seven stages. It cannot sell before it has chosen.

01·PROPOSE

It picks one task and argues for it

The model sees the balance, the mode, the stage, the chosen opportunity and everything already finished, then selects one permitted task with a two-sentence reason. If the task would need an external action — contacting someone, publishing, spending — it flags that, and even then no tool exists to do it. It writes a draft instead.

02·APPROVE

Nothing runs until you say so

The task executes with all previous outputs as context, saves a numbered file, harvests every URL into a sources list, books the cost against the ledger, and advances the stage.

The seven stages and what each one leaves behind

Every task produces a numbered file, so the run is legible after the fact rather than living in a chat log.

StageTasks and their output files
ResearchResearch problems people are solving → 01. List opportunities → 02.
CompareCompare the top three → 03.
ChooseCommit to one, with a one-liner → 04. This fills the opportunity card.
PlanProduct plan → 05. Offer and pricing ideas → 06.
BuildLanding copy → 07. A useful digital asset → 08. Single-file product → 09.
SellMarketing plan → 10. Outreach drafts, never sent → 11. How a customer actually pays → 12.
EarnReview results against the wallet and re-plan → 13.
!
The research-honesty rule is the best part of the design

With live search enabled the research tasks must cite URLs. When the search tool is unavailable, the agent is told it has no live data and instructed to output “research unavailable — paste links and re-run” rather than filling the gap from memory. Every prompt carries the same rule: no invented facts, statistics, customers, competitors or revenue, and anything unverifiable gets marked as needing a source. An agent that says it does not know is worth more than one that produces a confident market analysis from nothing.

Section 5

Your first session, about fifteen minutes

Start the app. Balance $100, mode healthy.Run the first task — it will propose research. Read the reasoning before approving.Open the research output and check the sources are real, followable links.Keep going through opportunities, comparison and decision. Watch the opportunity card fill in and the balance tick down with each call.Let it build the plan, the offer, the landing copy, the asset and the single-file product.Read the sell plan. It tells you what to set up — the payment tool, where to talk to people. The agent cannot do any of it.If someone actually pays you, log it as revenue with the proof. Until then it stays at $0, and that is correct.
Section 6

Simulation mode — fake money, clearly labelled

A demo switch for seeing the survival mechanics without waiting for real events. An amber banner makes the state unmistakable.

ButtonEffect
+ $40 fake saleAdds a simulated revenue line.
− $30 tool bill, − $60 hostingBalance drops — watch the mode shift to survival, then critical.
− $200 disasterBalance hits zero. Shut down, and new tasks are blocked.
Turn simulation offEvery simulated line stops counting and the real numbers return. Verified revenue still reads $0 if you never logged any.
i
Simulated money is tagged, not mixed

Simulated entries carry a tag in the ledger and are listed separately on the revenue card, so fake money is never mistaken for real. That is a small implementation detail doing a lot of work — the moment a demo mode blends into the real numbers, the whole premise of the wallet stops meaning anything.

Section 7

Project layout

The key never reaches the browser — the dashboard talks to a local API rather than holding credentials itself.

ai-survival-agent/8 lines
ai-survival-agent/
  app.py             server + JSON API (key never reaches the browser)
  agent.py           planner · 13 tasks · prompts · executor · cost booking
  wallet.py          ledger · balance formula · survival modes
  static/index.html  the dashboard
  outputs/           everything the AI builds
  data/              ledger.json + state.json (auto-created)
  README.md · .env.example · requirements.txt

Troubleshooting

ProblemFix
Authentication errorKey missing or wrong — or set the dry-run flag and explore without one.
Model not foundChange the model name to one your account actually has.
Research says unavailableEnable web search. If your account lacks the tool, paste links into the research file and continue — do not let it guess.
Costs look wrongThey are estimates. Put your model’s real per-million prices in the environment file.
Start overReset on the dashboard, which keeps the outputs, or delete the data folder entirely.
Section 8

Where it would go next

01·REAL COSTS

Stop estimating

Pull actual usage from the provider’s usage API and attach real hosting and tool bills, so the ledger stops being an approximation.

02·REAL REVENUE

Verified import

A test-mode payment webhook or CSV import that logs payouts with a proof link on the ledger line.

03·AUTOPILOT

With a hard cap

Run several tasks in a row while healthy, stopping the instant the mode drops.

04·PORTFOLIO

More than one bet

Per-idea stage, sources and cost-to-date, so it can kill a loser and reallocate.

05·EXPORT

Publishable outputs

One-click export of the landing page and product to a static host — still behind your approval.

!
Disclaimer

This is an experiment about whether an agent’s work could plausibly cover its own costs. The $100 is fictional, the costs are estimates, and no revenue exists unless you earned it and logged it yourself. No income is promised or implied.

i
Provenance

The setup steps, environment file, wallet formula, survival thresholds, stage list and troubleshooting follow the source guide. Nothing here had external claims to verify — no repository, version or pricing figures — and the model name in the environment file is left generic, since that is the fastest-moving line in any such setup. The author’s byline and follow prompt are not carried across.