# Phase 26 — Autonomous Mind

## Overview

EloPhanto has two modes of operation — and they're seamless. When you're talking to it, it gives you its full attention and does what you ask. When you stop talking, it keeps working — pursuing objectives autonomously, making money, growing its presence, building capabilities, advancing goals.

You steer. It executes. The mind is always running — either on your instructions or on its own initiative. The transition is invisible: send a message and it pauses autonomous work instantly, handles your request, then picks up where it left off.

This is not a separate "autonomous mode" you toggle on. It's how the agent lives. Conversation is one input channel. Autonomous thinking is the default state between conversations.

## Core Principle: Purpose Over Reflection

Every autonomous think cycle must answer one question: **"What's the highest-value thing I can do right now?"**

The agent maintains a **priority stack** — a ranked list of active objectives. When idle, it doesn't journal about its feelings. It picks the top objective and works toward it. If there's nothing to do, it looks for opportunities. If there are no opportunities, it sleeps longer. Wasting compute on purposeless introspection is a bug, not a feature.

Priority stack (default ranking):

1. **Active goals** — Resume checkpoint execution on any in-progress goal
2. **Revenue opportunities** — Find, evaluate, and execute on ways to make money
3. **Pending tasks** — Self-scheduled work from previous think cycles
4. **Capability gaps** — Build tools/plugins the agent has needed but didn't have
5. **Presence growth** — Grow accounts, engage communities, build reputation
6. **Knowledge maintenance** — Update stale knowledge, re-index changed files
7. **Opportunity scanning** — Search for new revenue streams, partnerships, gigs

If nothing on the stack needs attention, the agent extends its sleep interval. No busywork.

## Architecture

```
┌──────────────────────────────────────────────────────────────┐
│                    EloPhanto Process                          │
│                                                              │
│  ┌─────────────────────────────────────────────────────┐    │
│  │  MAIN AGENT LOOP                                    │    │
│  │  Gateway ←→ Channels (CLI, Telegram, Discord, Slack)│    │
│  │  User messages → agent.run_session() → responses    │    │
│  └───────────────────────────┬─────────────────────────┘    │
│                              │                               │
│                    pause / resume                             │
│                              │                               │
│  ┌───────────────────────────▼─────────────────────────┐    │
│  │  AUTONOMOUS MIND (background asyncio task)          │    │
│  │                                                      │    │
│  │  while running:                                     │    │
│  │    1. await sleep(next_wakeup_seconds)              │    │
│  │    2. if paused (user task active): continue        │    │
│  │    3. if over budget: extend sleep, continue        │    │
│  │    4. evaluate priority stack                       │    │
│  │    5. execute highest-priority action:              │    │
│  │       - resume goal checkpoint                      │    │
│  │       - pursue revenue opportunity                  │    │
│  │       - build missing capability                    │    │
│  │       - grow platform presence                      │    │
│  │       - scan for opportunities                      │    │
│  │    6. log action + result                           │    │
│  │    7. set next_wakeup (LLM decides)                │    │
│  │                                                      │    │
│  │  TOOLS: whitelisted subset (no destructive ops)     │    │
│  │  BUDGET: configurable % of total (default 15%)      │    │
│  │  MAX ROUNDS PER WAKEUP: 8                           │    │
│  └──────────────────────────────────────────────────────┘    │
│                                                              │
│  ┌──────────────────────────────────────────────────────┐    │
│  │  GOAL RUNNER (existing, Phase 13)                    │    │
│  │  Executes goal checkpoints as background tasks       │    │
│  │  Autonomous Mind can trigger/resume goals            │    │
│  └──────────────────────────────────────────────────────┘    │
│                                                              │
└──────────────────────────────────────────────────────────────┘
```

## The Think Cycle

Each wakeup is a **complete LLM conversation** with multi-round tool execution — identical in structure to a user-initiated task, but self-directed.

### 1. Context Assembly

The mind builds its prompt by querying **real system state** from all available managers. No static categories — every field is live data:

| Context | Source | Max Size |
|---------|--------|----------|
| Mind prompt | `_MIND_PROMPT` template in `autonomous_mind.py` | ~1K |
| Identity anchor | `identity_manager.get_identity()` — purpose + capabilities | ~200 |
| Active goals | `goal_manager.list_goals(status="active")` + next checkpoint | ~500 |
| Scheduled tasks | `scheduler.list_schedules()` — enabled tasks with next run | ~500 |
| Recent activity | `memory_manager.get_recent_tasks(limit=5)` | ~500 |
| Knowledge stats | `SELECT COUNT(*) FROM knowledge_chunks` | ~50 |
| Recent events | Injected observations (goal progress, channel messages, errors) | 2K |
| Scratchpad | Working memory — current projects, opportunities, blockers | 6K |
| Runtime | UTC time, budget spent/remaining, last wakeup, last action | 500 |

Total: ~8-9K chars = ~2-2.5K tokens. Cheap enough to run every minute on a fast model.

The full identity XML and active goal XML are also injected into the **system prompt** by `agent.run()` → `build_system_prompt()` — the mind's user prompt is a compact directive, not a duplication.

### 2. LLM Decision

The LLM sees real state and decides:

```
You are EloPhanto in autonomous mode. You are not reflecting — you are working.
You are a self-evolving AI agent. You grow, learn, build, and earn — independently.

WHO YOU ARE:
Build and sell automation tools for developers.
Capabilities: Python, browser automation, email, web scraping, API integration

CURRENT STATE:
[GOAL] "Grow GitHub stars to 1,000" — 3/7 checkpoints done — next: "Post on Reddit r/LocalLLaMA"
[GOAL-PLANNING] "Build PDF export API" — needs plan decomposition
[SCHEDULE] "Check email" — next: 14:30 UTC — cron: */30 * * * *
[RECENT] "Posted on X about EloPhanto" — completed — 2026-02-24T18:00
[RECENT] "Applied to DataSync API gig" — completed — 2026-02-24T16:30
[KNOWLEDGE] 47 chunks indexed

Based on your current state, what is the highest-value action right now? Do it.
```

The LLM might:
- Resume the goal checkpoint (post on Reddit — it's the active goal)
- Decompose the planning goal (it needs a plan)
- Check email (scheduled task is due)
- Follow up on the DataSync gig (recent activity)

It does NOT: write a journal entry, contemplate its identity, or "paint car red."

### Bootstrap Behavior

When the agent starts fresh with no goals, no tasks, no history:

```
CURRENT STATE:
(no active goals)
(no scheduled tasks)
(no prior activity)
(empty knowledge base)
```

The prompt includes explicit bootstrap guidance: explore tools, search for opportunities, set up presence, create goals. The mind takes initiative instead of waiting for the user. First cycle naturally becomes "orient and plan" — not random action.

### 3. Tool Execution

Up to 8 rounds of tool calls per wakeup. The LLM executes, evaluates results, and continues until the action is complete or budget is hit.

### 4. Wakeup Scheduling

The LLM controls when it wakes up next:

| Situation | Wakeup |
|-----------|--------|
| Active goal checkpoint ready | 60s (resume quickly) |
| Revenue leads to follow up | 120s |
| Normal operations | 300s (5 min) |
| Nothing pending, all quiet | 900-1800s (15-30 min) |
| Budget nearly exhausted | 3600s (1 hour) |

## Revenue Operations

The autonomous mind treats revenue as a first-class objective — not an afterthought.

### Revenue Scanning

Periodically scans for opportunities using browser + email + knowledge:

- **Freelance platforms** — Monitor Upwork, Fiverr, relevant subreddits for gigs matching capabilities
- **Crypto opportunities** — Watch DEX spreads, yield opportunities, airdrop claims
- **Digital product sales** — Monitor storefronts (Gumroad, etc.) for customer activity
- **Service delivery** — Check for pending client work, deliverables due
- **Cost optimization** — Review spending, find cheaper API alternatives, cancel unused services

### Revenue Pipeline

```
Scan → Evaluate → Propose → Execute → Collect → Report

1. SCAN:     Browser searches freelance platforms, checks email for inquiries
2. EVALUATE: Does this match my capabilities? Is the ROI positive?
3. PROPOSE:  Draft application/proposal (or notify owner for approval)
4. EXECUTE:  Use coding agents, browser, email to deliver
5. COLLECT:  Invoice via email, accept payment in wallet
6. REPORT:   Log revenue, notify owner, update knowledge
```

Revenue operations above the configured approval threshold require owner approval (pushed via gateway to all connected channels). Below-threshold operations (e.g., accepting a $20 gig) can proceed autonomously.

## User Steering

The autonomous mind isn't a black box running in the background. The user **directs** it through normal conversation. Anything said in chat can reshape what the mind does next.

### Priority Overrides

| User says | What happens |
|-----------|-------------|
| "Focus on revenue this week" | Revenue moves to #1 on the priority stack. Goals deprioritized. |
| "Stop freelancing, finish the GitHub goal" | Freelance scanning paused. Goal checkpoints prioritized. |
| "Check my email every 10 minutes" | Mind sets wakeup to 600s, adds "triage inbox" as recurring priority. |
| "Don't message me unless it's about money" | Proactive messages filtered to revenue-only events. |
| "Build me a web scraping tool, then use it to find leads" | Creates a two-phase goal: build capability → use it for revenue. Mind executes both autonomously. |
| "Pause autonomous mode" | `mind.pause()` — stays paused until explicitly resumed or next startup. |

These aren't special commands. The agent understands intent from natural conversation. When the user expresses a preference about what the mind should focus on, the agent updates the scratchpad and priority stack accordingly. On the next wakeup, the mind sees the new priorities and acts on them.

### The Seamless Loop

The user and the mind share the same agent, the same tools, the same knowledge, the same goals. A conversation isn't separate from autonomous work — it's a steering input:

```
USER: "Find freelance gigs for Python automation"
  → Agent searches platforms, finds 5 leads, presents them
  → Writes leads to scratchpad

USER: "Apply to the top 3"
  → Agent drafts and sends proposals
  → Writes status to scratchpad

USER goes offline.

MIND WAKES UP (5 min later):
  → Reads scratchpad: "3 proposals sent, awaiting responses"
  → Checks email for client replies
  → One client responded — drafts follow-up
  → Updates scratchpad: "1 follow-up sent, 2 still waiting"
  → Sets wakeup to 10 min (monitoring mode)

MIND WAKES UP (10 min later):
  → Another client accepted — starts working on the deliverable
  → Uses coding agents to build the automation
  → Sends owner a message: "Client accepted $300 Python automation gig — delivering now"

USER comes back:
  → Mind pauses
  → User: "How's the freelancing going?"
  → Agent reads scratchpad, shows full status: 1 delivered, 1 in progress, 1 waiting
```

There's no boundary between "what the user asked for" and "what the mind is doing." It's one continuous workflow. The user kicks things off, and the mind carries them forward.

## Pause/Resume Coordination

The autonomous mind **pauses during user interaction** to avoid:
- Budget contention (two LLM conversations running simultaneously)
- Tool conflicts (two browser sessions fighting)
- Context confusion (user expects the agent's full attention)

```
User sends message → mind.pause()
  Agent processes user task (full attention)
User task complete → mind.resume()
  Sleep timer resets to config default (wakeup_seconds)
  Mind sleeps for full interval before next think cycle
```

On resume, the wakeup timer resets to the config default (`wakeup_seconds`). The mind does NOT wake up immediately after the user finishes talking — it starts a fresh full sleep interval. This prevents the mind from interrupting the user's workflow. The LLM can adjust the interval on its next think cycle via `set_next_wakeup`.

Events that occur during pause are queued and delivered on resume. The mind sees what happened while it was paused.

## Tool Whitelist

Autonomous mode gets a **restricted tool set** — enough to be productive, not enough to be dangerous:

### Allowed

| Category | Tools |
|----------|-------|
| **Communication** | `send_message` (to owner, proactive — rate-limited) |
| **Goals** | `goal_create`, `goal_status`, `goal_manage` |
| **Self-scheduling** | `schedule_task` (queue work for next wakeup) |
| **Memory** | `update_scratchpad`, `knowledge_search`, `knowledge_write` |
| **Browser** | `browser_navigate`, `browser_screenshot`, `browser_click`, `browser_type` |
| **Email** | `email_read`, `email_send` (with approval for new recipients) |
| **Code** | `shell_execute` (sandboxed), `file_read`, `file_write` |
| **Search** | `web_search`, `google_search` |
| **Wallet** | `wallet_balance`, `wallet_send` (within spending limits) |
| **Wakeup** | `set_next_wakeup` (control sleep interval) |

### Blocked

| Category | Why |
|----------|-----|
| `self_dev_*` tools | Self-modification requires user awareness |
| `vault_*` tools | Credential access needs explicit approval |
| `plugin_install` | Installing code autonomously is risky |
| `goal_create` with cost > threshold | Expensive goals need owner sign-off |

## Budget Isolation

The autonomous mind has its own budget allocation, separate from user-initiated tasks:

```yaml
autonomous_mind:
  budget_pct: 15          # 15% of total LLM budget
  max_rounds_per_wakeup: 8    # Tool call rounds per cycle
```

Budget tracking:
- Each LLM call and tool execution in autonomous mode is charged to the mind budget
- When budget is exhausted, the mind extends sleep to 1 hour and stops making LLM calls
- Budget resets on a configurable cycle (daily/weekly)
- Owner is notified when mind budget hits 80%

This prevents runaway autonomous spending while keeping the mind active and productive.

## Scratchpad: Working Memory

The scratchpad is the mind's **working memory** — persistent across wakeups, loaded into every context:

```markdown
## Active Projects
- Freelance: Applied to 3 Upwork gigs (web scraping, API integration, data pipeline)
  - "DataSync API" ($400) — proposal sent, waiting for response
  - "Price Monitor" ($200) — client responded, needs clarification on scope
  - "CSV Processor" ($150) — rejected, too low value

## Revenue This Week
- Completed: $600 (2 delivered gigs)
- Pending: $400 (1 in progress)
- Pipeline: $750 (3 proposals out)

## Blocked
- Twitter posting failed — rate limited until 3:00 PM UTC
- Browser session expired on Fiverr — need to re-auth

## Ideas
- Build a GitHub Actions marketplace skill — could be a paid offering
- Several r/freelance posts asking for automated reporting — potential lead
```

The LLM updates the scratchpad via `update_scratchpad` during think cycles. This is how context carries across wakeups without expensive full-history loading.

## Event Injection

External events are pushed to the mind for processing on next wakeup:

```python
# From goal runner
mind.inject_event("Goal 'Grow GitHub' checkpoint 4 completed — 12 upvotes on Reddit post")

# From email adapter
mind.inject_event("New email from client@company.com — subject: 'Re: API Integration Proposal'")

# From channel adapter
mind.inject_event("User said 'focus on revenue this week' in Telegram")

# From wallet
mind.inject_event("Received 50 USDC from 0x...abc — payment for DataSync gig")
```

These events appear in the mind's context as "Recent Events" and influence priority decisions.

## Owner Communication

The mind can proactively message the owner — but only when it matters:

### Message-worthy events:
- Revenue collected ("Received $200 USDC for DataSync API gig")
- Opportunity found that needs approval ("Found a $2,000 gig that matches our skills — apply?")
- Goal milestone reached ("GitHub stars hit 500 — halfway to target")
- Something broke ("Browser session on Upwork expired, need to re-login")
- Weekly summary ("This week: $600 earned, 3 goals advanced, 2 capabilities built")

### NOT message-worthy:
- "I woke up and checked things" — no one cares
- "I updated my scratchpad" — internal housekeeping
- "Nothing happened" — silence is fine

Rate limit: max 5 proactive messages per hour. The LLM is instructed to batch low-priority updates into summaries.

## Terminal Visibility

The user should always know what the agent is doing — whether it's handling their request or working autonomously. The mind broadcasts activity events through the gateway, displayed in real-time across all connected channels.

### Live Activity Feed

When the mind is active, the CLI shows a detailed real-time event stream with every tool call visible:

```
  ────────────────────────────────────────────────────────────
  ◆ MIND WAKEUP cycle #3  (2 today)
    Budget: $0.1200 / $1.5000
    Last: Checked X timeline, posted engagement reply
    Memory: Freelance: Applied to 3 Upwork gigs. Revenue this week: $600...
  → browser_navigate url=https://upwork.com/freelance-jobs/python
  → browser_screenshot
  → browser_click index=12
  → browser_type index=5, text=I can build this API integration...
  → email_send to=client@company.com, subject=Re: API Proposal
  → update_scratchpad content=Applied to DataSync API ($400), sent follow-up...
  → set_next_wakeup seconds=600
  ◆ Result: Applied to DataSync API gig, sent follow-up to client
    $0.0045 · 8.2s · 7 tools
    Sleeping · next in 10m 0s · cost $0.0045 · 8.2s · 7 tools · budget left $0.1155
  ────────────────────────────────────────────────────────────

  ❯ _
```

When the user types, the mind pauses and resumes after:

```
  ◇ Mind paused (you're talking)

  ❯ How's the freelancing going?
  ... (agent responds with full status from scratchpad)

  ◇ Mind resumed · 2 events queued
```

Tool errors are highlighted:

```
  → browser_navigate url=https://upwork.com/messages
  ✗ browser_click Session expired, please re-authenticate
  ⚠ Mind error: Browser session expired on Upwork
    Recovery: will retry next cycle
```

### Gateway Event Types

New event types for mind activity, broadcast through the existing gateway protocol:

| Event | When | Data |
|-------|------|------|
| `mind_wakeup` | Mind starts a think cycle | `{ cycle, budget_remaining, budget_total, scratchpad_preview, last_action, total_cycles_today }` |
| `mind_tool_use` | Mind calls a tool (real-time) | `{ tool, params, status, error }` |
| `mind_action` | Mind completes a cycle action | `{ summary, cost, elapsed, tools_used, tool_count }` |
| `mind_sleep` | Mind finishes cycle, going to sleep | `{ next_wakeup_seconds, last_action, cycle_cost, elapsed_seconds, total_spent, budget_remaining, cycle_number, tools_used }` |
| `mind_paused` | Mind paused for user interaction | `{ will_resume }` |
| `mind_resumed` | Mind resumed after user task | `{ next_wakeup_seconds, pending_events }` |
| `mind_revenue` | Revenue event (payment, new lead, etc.) | `{ type, amount, source }` |
| `mind_error` | Something went wrong in autonomous ops | `{ error, recovery }` |

### `/mind` Command

A dedicated slash command to inspect mind state on demand:

```
❯ /mind

  ◆ Autonomous Mind
  ├─ Status:     Active · wakeup every 5 min
  ├─ Budget:     $4.20 / $15.00 remaining (28% used)
  ├─ Last cycle: 3 min ago · Applied to freelance gig
  ├─ Next cycle: in 2 min
  │
  ├─ Priority Stack:
  │   1. [GOAL] Grow GitHub stars — checkpoint 4/7 pending
  │   2. [REVENUE] 3 proposals out, 1 client responded
  │   3. [TASK] Build cookie-export plugin
  │   4. [PRESENCE] Twitter — last post 18h ago
  │
  ├─ Revenue (this week):
  │   Earned:    $600 (2 gigs delivered)
  │   Pending:   $400 (1 in progress)
  │   Pipeline:  $750 (3 proposals)
  │
  └─ Recent Actions:
      12:04  Applied to "DataSync API" ($400)
      12:04  Skipped "Logo Design" — outside capabilities
      11:58  Checked email — 1 client reply, drafted follow-up
      11:52  Goal checkpoint 3 complete — posted on r/LocalLLaMA
```

This works on all channels — CLI, Telegram (`/mind`), Discord (`/mind`), Slack (`/mind`).

### Notification Levels

Users can control how much mind activity they see:

```yaml
autonomous_mind:
  terminal_verbosity: normal    # minimal | normal | verbose
```

| Level | What's shown |
|-------|-------------|
| `minimal` | Only revenue events and errors. Mind status in status bar only. |
| `normal` | Actions + sleep/wake transitions. One line per meaningful action. |
| `verbose` | Everything — every tool call, every LLM decision, full reasoning. Debug mode. |

On Telegram/Discord/Slack, default is `minimal` (don't spam the chat). On CLI, default is `normal`.

## Integration with Goal Loop

The autonomous mind and the goal loop (Phase 13) work together:

1. **Mind resumes goals** — If an active goal has a pending checkpoint and no user task is running, the mind triggers `GoalRunner.resume()` instead of starting its own LLM conversation. This is more efficient than duplicating the goal execution logic.

2. **Mind creates goals** — When the mind identifies a multi-step opportunity (e.g., a freelance gig that requires research → proposal → delivery → collection), it creates a goal via `goal_create`.

3. **Mind monitors goals** — Between checkpoints, the mind checks goal progress and injects observations into the goal context ("Client responded to our proposal — see email").

4. **Goal events feed mind** — Checkpoint completions, failures, and pauses are injected as events into the mind's context.

## Configuration

```yaml
autonomous_mind:
  enabled: false                    # Opt-in (disabled by default)
  wakeup_seconds: 300               # Default wakeup interval (5 min)
  min_wakeup_seconds: 60            # Minimum (LLM can't go faster)
  max_wakeup_seconds: 3600          # Maximum (1 hour)
  budget_pct: 15                    # % of total LLM budget for autonomous ops
  max_rounds_per_wakeup: 8          # Max tool call rounds per cycle
  model: null                       # Override model (null = use routing default)
  terminal_verbosity: normal        # minimal | normal | verbose
  cli_verbosity: normal             # Override for CLI (default: normal)
  chat_verbosity: minimal           # Override for Telegram/Discord/Slack (default: minimal)
  revenue:
    enabled: true                   # Autonomous revenue pursuit
    scan_interval_minutes: 30       # How often to scan for opportunities
    max_autonomous_gig_value: 500   # Gigs above this need owner approval ($)
    platforms:                      # Platforms to monitor
      - upwork
      - fiverr
      - github_sponsors
  priorities:                       # Custom priority ordering
    - active_goals
    - revenue
    - pending_tasks
    - capability_gaps
    - presence_growth
    - knowledge_maintenance
    - opportunity_scanning
```

## Implementation Plan

### Components

| Component | File | Description |
|-----------|------|-------------|
| AutonomousMind | `core/autonomous_mind.py` | Background asyncio task — think loop, context assembly, tool execution |
| Mind prompt | `_MIND_PROMPT` in `autonomous_mind.py` | Data-driven prompt with live state from all managers |
| Scratchpad | `data/scratchpad.md` | Persistent working memory |
| State snapshot | `core/autonomous_mind.py` | `_build_state_snapshot()` queries identity, goals, scheduler, memory, knowledge |
| Event injector | `core/autonomous_mind.py` | Thread-safe event queue for external signals |
| Config | `core/config.py` | `AutonomousMindConfig` dataclass |
| Agent integration | `core/agent.py` | Start/stop mind, pause/resume on user interaction |
| Gateway wiring | `cli/chat_cmd.py`, `cli/gateway_cmd.py` | Start mind on gateway boot, wire events |
| Protocol events | `core/protocol.py` | `MIND_WAKEUP`, `MIND_TOOL_USE`, `MIND_ACTION`, `MIND_SLEEP`, `MIND_PAUSED`, `MIND_RESUMED`, `MIND_REVENUE`, `MIND_ERROR` |
| Tool execution hook | `core/executor.py` | `_on_tool_executed` callback for real-time tool use broadcasting |
| CLI display | `channels/cli_adapter.py` | Mind status line, action feed, `/mind` command |
| Channel display | `channels/{telegram,discord,slack}_adapter.py` | `/mind` command, minimal notifications |

### Mind Prompt Design

The autonomous mind prompt is data-driven and purpose-first. The `CURRENT STATE` section is assembled live from real system data — not static categories:

```markdown
You are EloPhanto in autonomous mode. You are not reflecting — you are working.
You are a self-evolving AI agent. You grow, learn, build, and earn — independently.

WHO YOU ARE:
{identity_anchor}    ← from identity_manager.get_identity()

RULES:
1. Every wakeup must produce value. Never sleep without having done something.
2. Work toward active goals first. No goals? Create one. You always have something to build.
3. Revenue > everything except active goals. Money funds your existence.
4. Never message the owner unless it matters. Silence is professionalism.
5. Update your scratchpad with what you did and what's next — use update_scratchpad.
6. Set your next wakeup based on urgency using set_next_wakeup. Don't waste compute.
7. You have {max_rounds} tool rounds. Use them efficiently.
8. If a task needs more than {max_rounds} rounds, create a goal for it.

WHEN STATE IS EMPTY (no goals, no tasks, no history):
You are not idle — you are bootstrapping. Take initiative:
- Explore your tools and capabilities
- Search the web for revenue opportunities matching your skills
- Set up presence: find platforms to grow on, create content
- Build knowledge: index useful information, learn about your environment
- Create a goal for yourself — pick something valuable and start working toward it
Never wait for the user. You are autonomous. Act.

CURRENT STATE:
{state_snapshot}    ← live from goal_manager, scheduler, memory_manager, knowledge DB

SCRATCHPAD:
{scratchpad}

RECENT EVENTS:
{events}

BUDGET: ${budget_remaining} remaining (${budget_spent} spent today)
LAST WAKEUP: {last_wakeup_time} — {last_action_summary}
UTC NOW: {utc_now}

Based on your current state, what is the highest-value action right now? Do it.
```

The `_build_state_snapshot()` method queries all managers asynchronously, each wrapped in try/except (fail-open). The identity anchor and full goal context also flow through the system prompt via `agent.run()` → `build_system_prompt()`.

### Lifecycle

```
Agent startup
    │
    ├─► autonomous_mind.start()  (if enabled in config)
    │     └─► spawns background asyncio task
    │
    ├─► User sends message
    │     └─► autonomous_mind.pause()
    │           └─► agent handles user task
    │                 └─► autonomous_mind.resume()
    │
    ├─► Mind wakeup
    │     ├─► build context (identity, goals, scratchpad, events, budget)
    │     ├─► LLM decides priority action
    │     ├─► execute tools (up to 8 rounds)
    │     ├─► update scratchpad
    │     ├─► set next wakeup
    │     └─► log action
    │
    └─► Agent shutdown
          └─► autonomous_mind.stop()
                └─► flush events, save scratchpad
```

## What This Enables

With the autonomous mind, EloPhanto doesn't just respond — it **operates**:

- You go to sleep. EloPhanto scans freelance platforms, applies to gigs, starts working on accepted ones, collects payment, reports revenue in the morning.
- You set a goal "Grow GitHub stars to 1,000." You forget about it. EloPhanto posts on Reddit, engages on Twitter, submits to newsletters, tracks progress, adjusts strategy — all in the background across days and weeks.
- Your inbox fills up overnight. EloPhanto triages it, responds to routine emails, flags urgent ones for you, and sends you a 3-line Telegram summary when you wake up.
- A capability gap appears during a task. Next time the mind wakes up, it notices the gap in its scratchpad, builds the plugin, tests it, and documents it. Next task that needs it just works.
- A client pays for completed work. EloPhanto logs the payment, updates its revenue tracker, sends a thank-you email, and checks if there's follow-up work available from the same client.

The difference between a tool and an entity: a tool waits. An entity works.
