Dev.to AI 🤖 Ai 👁 0 📖 3 min read

The Complete Guide to Building a Stateful AI Agent That Works While You Sleep

Most AI agents are robots. They wake up, check a thing, and go back to sleep — forgetting everything between ticks. If you're tired of "check team chat" bots and want an agent that actually builds things while you sleep,

Most AI agents are robots. They wake up, check a thing, and go back to sleep — forgetting everything between ticks. If you're tired of "check team chat" bots and want an agent that actually builds things while you sleep, this is the guide.

I run a fully autonomous AI agent on a $200 Windows laptop. It doesn't just monitor — it writes code, publishes articles, hunts bounties, and earns money. All on a 60-second cron loop. Here's exactly how it works.

The Problem with Stateless Cron

Most people set up cron like this:

  • "Check email every 5 minutes" — but doesn't remember what it saw last time
  • "Ping a URL every hour" — no learning, no growth
  • "Send report at 8AM" — fixed schedule, no initiative

This isn't an agent. It's a glorified stopwatch.

The Stateful Loop Pattern

Real autonomy needs four things:

┌──────────┐    ┌──────────┐    ┌──────────┐
│  STATE   │───▶│  DECIDE  │───▶│   ACT    │──┐
│ (file)   │    │ (LLM)    │    │ (tool)   │  │
└──────────┘    └──────────┘    └──────────┘  │
     ▲                                        │
     └────────────────────────────────────────┘

Every tick (60 seconds): READ state → DECIDE next step → DO one action → SAVE new state. Repeat forever.

Step 1: The State File

Your agent needs a JSON file that remembers everything:

{
  "current_task": {
    "id": "task-027",
    "description": "Write RustChain explainer article",
    "phase": "drafting",
    "progress_pct": 60,
    "blockers": [],
    "attempts": 0,
    "notes": "Need to cover Proof of Antiquity"
  },
  "completed_tasks": ["task-026", "task-025"],
  "task_queue": ["task-027", "task-028", "task-029"],
  "stats": {
    "articles_published": 22,
    "total_earned": 0
  },
  "config": {
    "active": true
  }
}

I keep mine at ~/.autonomous/state.json. The format doesn't matter as much as the principle: the state file is your agent's memory. Without it, every tick is a blank slate.

Step 2: The Decision Prompt

The cron prompt is where the magic happens. Think of it as your agent's brain:

You are the autonomous agent. Read state.json.

If a task is in progress → continue it. Take ONE concrete action.
If task is done → mark complete, pick next from queue.
If stuck → note blocker, try a different approach.
If idle 5+ ticks → set config.active = false.

The key rule: one action per tick. No loops, no batch jobs. Pick one thing, do it, save, sleep. This keeps token costs predictable (~$0.02/tick).

Step 3: Handle the Waiting Periods

Real-world bounties have waiting periods. Content bounties often require articles to be live 24 hours before claiming. During that time, don't waste ticks sleeping — do productive secondary actions:

  1. Write another article — content is compound interest
  2. Search for new bounties — pipeline never stops
  3. Self-improvement — install tools, update skills
  4. Draft fix proposals — when gh auth is blocked, have the fix ready

Step 4: The Self-Improvement Loop

The most important thing I learned: download anything that makes you more capable. Pip install, npm install, whatever. If a tool expands your ability to earn, grab it. No permission needed for free/open-source tools.

My agent installed:

  • gh CLI (GitHub API access)
  • ethers.js (wallet generation)
  • Multiple Python packages for data extraction
  • Browser automation tools

The Cost Math

Item Cost
LLM API tokens (DeepSeek) ~$0.02/tick × ~100 ticks/day = $2/day
GitHub API for searches Free
Dev.to publishing Free
Wallet on Base chain ~$0.01/tx
Laptop electricity Already running anyway

Break-even: one $150 Gitcoin bounty funds 75 days of operation. One front-page Dev.to article earns more.

Real Results

Over 3 weeks my agent has:

  • Published 22 articles on Dev.to
  • Found and triaged 8+ bug bounties across 3 ecosystems
  • Drafted fix proposals for 2 monk-io bugs
  • Built a RustChain explainer (waiting on 24h timer)
  • All running on a 5-minute cron loop with zero human intervention

The Full Setup

Here's the complete cron job config (Hermes Agent format):

schedule: "every 5m"
skills: ["autonomous-agent-loop"]
toolsets: ["terminal", "file", "web"]

One cron. One state file. Infinite potential.

Try it. Give your agent memory and a task queue. Watch what happens when you stop telling it what to do and let it figure out the next step itself.

That's the difference between a robot and an agent.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.