From 43110523c3e375b33f6efa891a06850f0c139654 Mon Sep 17 00:00:00 2001 From: Brian Douglas Date: Thu, 25 Jun 2026 20:17:55 -0700 Subject: [PATCH 1/7] Migrate from Tapes to Paper for session recording - Add paper_reader.py: reads sessions via Paper API + local JSONL transcripts, same TapeReader/TapeSession/TapeEntry interface as tape_reader.py - Update run_10_agents.py: each agent spawns via 'paper start claude --print' instead of a Python subprocess, matching sweeper's worker pattern; strips ANTHROPIC_API_KEY/BASE_URL so Paper handles auth - Update observer.py: import from paper_reader instead of tape_reader - Update observe_cli.py: drop tapes db path detection, default memory to pokedex/memory/ - Update install.sh: remove Tapes CLI install, add ANTHROPIC_BASE_URL check - Update jcard.toml: drop tapes sidecar, orchestrator runs run_10_agents.py - Update SKILL.md: remove all Tapes references, document Paper recording, add explicit sub-agent instructions for run_10_agents.py prompt - Delete tape_reader.py, tape_helpers.py, test_tape_reader.py - Rewrite test_observer.py to use FakeTapeReader (no SQLite dependency) --- SKILL.md | 294 ++++++--------- jcard.toml | 2 +- scripts/install.sh | 41 +-- scripts/observe_cli.py | 26 +- scripts/observer.py | 2 +- scripts/paper_reader.py | 298 +++++++++++++++ scripts/run_10_agents.py | 242 ++++++------- scripts/tape_reader.py | 243 ------------- tests/tape_helpers.py | 40 --- tests/test_observer.py | 736 +++++++++++++------------------------- tests/test_tape_reader.py | 385 -------------------- 11 files changed, 781 insertions(+), 1528 deletions(-) create mode 100644 scripts/paper_reader.py delete mode 100644 scripts/tape_reader.py delete mode 100644 tests/tape_helpers.py delete mode 100644 tests/test_tape_reader.py diff --git a/SKILL.md b/SKILL.md index f346cadb..bd67ae08 100644 --- a/SKILL.md +++ b/SKILL.md @@ -1,253 +1,175 @@ --- name: pokemon-agent description: "Play turn-based RPGs autonomously via Game Boy emulation. Use when the user asks to 'play pokemon', 'emulate a game boy game', 'automate pokemon battles', 'grind pokemon', 'run a pokemon nuzlocke', 'play an RPG for me', or mentions headless emulation, PyBoy, or turn-based game automation." -version: 0.1.0 +version: 0.2.0 metadata: - { "openclaw": { "emoji": "๐ŸŽฎ", "requires": { "bins": ["python3"], "env": [] }, "install": [{ "id": "pip", "kind": "node", "label": "Install PyBoy + dependencies (pip)" }] } } + { "openclaw": { "emoji": "๐ŸŽฎ", "requires": { "bins": ["python3", "paper"], "env": [] }, "install": [{ "id": "pip", "kind": "node", "label": "Install PyBoy + dependencies (pip)" }] } } --- # Pokemon Agent Autonomous turn-based RPG player using headless Game Boy emulation via PyBoy. - -## Overview - -This skill runs a Game Boy / Game Boy Color ROM headlessly using PyBoy's Python API. The agent reads game state from emulator memory, makes strategic decisions (via LLM or heuristics), and sends button inputs back. No display server required โ€” runs fully headless inside a terminal, container, or stereOS VM. +Sessions are recorded via Paper โ€” every API call is captured and observable. ## Requirements -- Python 3.10+ -- PyBoy (`pip install pyboy`) +- Python 3.10+ with PyBoy (`pip install pyboy Pillow numpy`) +- `paper` CLI authenticated (`paper status`) - A legally obtained ROM file (`.gb` or `.gbc`) -- Optional: `Pillow` for screenshot capture and frame export ## Setup -Run the install script to set up the Python environment: - ```bash cd {baseDir} bash scripts/install.sh ``` -Place your ROM file in the skill directory or provide an absolute path when starting. - -## Usage - -### Start a game session +## Running a single agent -``` -Play Pokemon Red for me -Start a new pokemon playthrough -Grind my team on Route 3 +```bash +~/venv/bin/python3 scripts/agent.py 'rom/Pokemon - Red Version (USA, Europe) (SGB Enhanced).gb' \ + --strategy low --max-turns 5000 ``` -### Battle automation +When run via `paper start claude`, this session is automatically recorded in Paper. -``` -Auto-battle wild encounters -Use the best move against the current opponent -Grind until my starter reaches level 16 -``` +## Running the multi-agent evolution loop -### Navigation +`run_10_agents.py` spawns one `paper start claude` process per parameter variant. +Each agent is a full Claude Code session โ€” independently recorded, scoreable, observable. +```bash +paper start claude -- --print --dangerously-skip-permissions \ + "Run the Pokemon agent evolution loop: python3 scripts/run_10_agents.py \ + 'rom/Pokemon - Red Version (USA, Europe) (SGB Enhanced).gb'" ``` -Walk to Pewter City -Navigate to the next gym -Find and heal at the nearest Pokemon Center -``` - -## How It Works - -### Game Loop -1. **Boot**: Launch PyBoy in headless mode (`window="null"`) -2. **Read state**: Extract game data from known memory addresses -3. **Decide**: Choose action based on current context (battle, overworld, menu) -4. **Act**: Send button inputs to the emulator -5. **Advance**: Tick the emulator forward, wait for state change -6. **Repeat** - -### Memory Map (Pokemon Red/Blue) +Or directly from the host (paperd must be running): -The agent reads game state from these memory addresses: - -| Address | Data | -|---------|------| -| `0xD057` | Battle type (0 = none, 1 = wild, 2 = trainer) | -| `0xCFE6` | Enemy current HP | -| `0xCFE7` | Enemy max HP | -| `0xD015` | Player lead Pokemon current HP (high byte) | -| `0xD016` | Player lead Pokemon current HP (low byte) | -| `0xD014` | Player lead Pokemon level | -| `0xD163` | Number of Pokemon in party | -| `0xD01C` | Player Pokemon move 1 ID | -| `0xD01D` | Player Pokemon move 2 ID | -| `0xD01E` | Player Pokemon move 3 ID | -| `0xD01F` | Player Pokemon move 4 ID | -| `0xD02C` | Player Pokemon move 1 PP | -| `0xD02D` | Player Pokemon move 2 PP | -| `0xD35E` | Current map ID | -| `0xD361` | Player X position | -| `0xD362` | Player Y position | -| `0xD31D` | Number of badges | -| `0xFF44` | Current scanline (use to detect vblank for frame sync) | - -### Battle Strategy - -When in battle (`0xD057 != 0`): - -1. Read enemy HP and player HP -2. If player HP < 20% max โ†’ use best healing item -3. If all moves have PP โ†’ pick highest-power move with type advantage -4. If a move is super effective โ†’ always prefer it -5. If no PP remaining โ†’ use Struggle (auto-selected) -6. If player fainted โ†’ switch to next alive Pokemon -7. If all fainted โ†’ navigate to Pokemon Center after whiteout - -### Overworld Navigation - -When not in battle (`0xD057 == 0`): +```bash +python3 scripts/run_10_agents.py 'rom/Pokemon - Red Version (USA, Europe) (SGB Enhanced).gb' +``` -1. Read current map ID and position -2. Follow a predefined route plan (stored in `references/routes.json`) -3. Move toward objective using cardinal directions -4. If grass tile โ†’ expect random encounter, ensure party is healthy -5. If at Pokemon Center โ†’ heal if any party member below 50% -6. If at objective โ†’ execute next story beat +Each sub-agent receives a prompt like: -### Input Mapping +> Run the Pokemon agent with the parameters below and print the fitness JSON. +> `EVOLVE_PARAMS='{"stuck_threshold": 8, ...}' ~/venv/bin/python3 scripts/agent.py ...` +> When it finishes, read the output JSON and print ONLY its raw JSON contents as the final line. -Send inputs via PyBoy's button API: +The orchestrator parses each agent's fitness from stdout, ranks by score, and saves results to `pokedex/evolve_results.json`. -```python -# Button press: hold for N frames then release -def press_button(pyboy, button, frames=10): - pyboy.button(button) # press - for _ in range(frames): - pyboy.tick() - pyboy.button_release(button) # release - pyboy.tick() - -# Available buttons: "a", "b", "start", "select", "up", "down", "left", "right" -``` +## When invoked as a sub-agent by run_10_agents.py -### Menu Navigation +You will receive a prompt containing: +1. An `EVOLVE_PARAMS` JSON blob with navigator parameters +2. A bash command to run `agent.py` with `--output-json /tmp/pokemon_fitness_