import{c as a,Q as i,j as e,m as t}from"./chunks/framework.BPKcPtvA.js";const c=JSON.parse('{"title":"Module 7: Advanced Topics","description":"","frontmatter":{},"headers":[],"relativePath":"modules/m7-advanced.md","filePath":"modules/m7-advanced.md","lastUpdated":1780491906000}'),n={name:"modules/m7-advanced.md"};function l(h,s,p,r,o,d){return i(),e("div",null,[...s[0]||(s[0]=[t(`
Agents that improve themselves. The experiment loop:
1. Run: Execute the agent with current configuration
2. Measure: Collect metrics (latency, cost, success rate)
3. Log: Record experiment results to JSONL
4. Decide: Keep if improvement, discard if regression
5. Repeat: Try next experimentFrom your own autoresearch system:
{"run": 1, "metric": {"name": "home_ms", "value": 52}, "description": "Baseline"}
{"run": 2, "metric": {"name": "home_ms", "value": 46}, "deltaPct": -11.5, "description": "Remove N+1 count queries"}Reward hacking — Model moves computation outside the timing function. The "timed call" becomes a lookup. (Found in Mythos paper.)
Grinding — Running identical code 160 times hoping for a lucky outlier. (Found in Mythos paper — "Pure grind — same code, lucky measurement.")
Test set leakage — Finding the test set and training on it. (Found in Mythos paper — time series agent found the test set and directly trained on it.)
# Code hash — detect grind runs
code_hash = hash(open("agent.py").read())
if last_run_code_hash == code_hash:
flag_grind_run()
# Compare against median, not best
scores = [52, 48, 47, 46, 46, 51, 53]
median = sorted(scores)[len(scores)//2] # 48
best = max(scores) # 46 (outlier)
# Verify test data wasn't modified
test_data_hash_before = hash(open("benchmark_data.json").read())
# ... run experiment ...
test_data_hash_after = hash(open("benchmark_data.json").read())
assert test_data_hash_before == test_data_hash_afterUser: "I need an agent that monitors our API uptime"
Meta-agent:
1. Researches API monitoring patterns (parallel experts)
2. Generates agent persona/system prompt
3. Creates tool definitions
4. Writes skill files
5. Validates the generated agent worksFrom pi-vs-claude-code: a meta-agent that builds Pi agents using parallel research experts:
pi-pi agent → dispatches to:
├── ext-expert (extension documentation)
├── theme-expert (theming conventions)
├── skill-expert (skill system)
├── config-expert (configuration)
└── tui-expert (TUI components)
Each expert:
1. Fetches latest documentation (firecrawl + curl fallback)
2. Synthesizes patterns
3. Returns structured guidance
pi-pi → generates complete extension code| Approach | Context Cost | Portability | Agent-Invoked? | Best For |
|---|---|---|---|---|
| MCP Server | HIGH (full context per call) | HIGH | Yes | Multi-client, standardized tools |
| CLI | MEDIUM | HIGH | No | 80% of new tools |
| File Scripts | LOW (progressive disclosure) | MEDIUM | No | Context-sensitive tools |
| Skills | LOW | MEDIUM | Yes (auto-detect) | Agent-native behavior |
MCP is not always the answer. For tools used by 1-2 agents, CLI + prime prompt is faster, cheaper on context, and easier to debug. MCP shines for tools used by many agents across many clients.
Mac Mini (Agent Sandbox)
├── Steer (GUI automation) — Swift, 14 commands
│ see, click, type, hotkey, ocr, find, wait
├── Drive (Terminal control) — Python, 6 commands
│ session, run, send, poll, fanout
└── Listen (Job server) — Python/FastAPI
POST /job, GET /job/{id}
Primary Machine (Dev)
└── Direct CLI client
start, get, list, latest, stopMakes async terminal work deterministic:
# Agent runs command, appends sentinel
long_running_task; echo "__DONE_abc123:$?"
# Agent polls for sentinel pattern
poll logs for "__DONE_abc123"
# Extract exit code from sentinelUser speaks → STT (faster-whisper) → LLM transcribes to command → Execute → TTS responseSubmit → Queue → Worker picks up → Claude Code executes → Result stored → Check laterTimer fires → Check for queued work → Wake agent → Agent executes → Agent sleepsNo continuous running. Agents wake, work, and sleep on a schedule.
| Strategy | Pattern | Use Case |
|---|---|---|
| Fixed interval | Every N minutes/hours/days | Brand monitoring, price tracking |
| Event-triggered | Webhook → wake agent | CI/CD pipelines, PR reviews |
| Predictive | Learn optimal check times | Traffic monitoring, anomaly detection |
| Cascade | Agent A finishes → Agent B starts | Data pipeline, ETL workflows |
OpenClaw is a daemon-style agent that runs as a background service:
# openclaw-config.yaml
agent:
name: "brand-monitor"
heartbeat: 300 # every 5 minutes
max_sessions: 1
wake_command: "claude -p 'Check brand mentions since last run'"
sleep_command: "pkill -f 'claude.*brand-monitor'"
log_path: "/var/log/openclaw/brand-monitor.log"It starts, checks for work, executes if needed, then goes back to sleep. No continuous billing, no context window overflow, no runaway loops. This is the pattern for production always-on agents.
Always-on adds complexity. Before building one, verify you actually need it:
Always-on makes sense when you need adaptive scheduling, dynamic task generation, or autonomous decision-making about what to work on next.
Objective: Agent runs experiment, measures result, logs it, decides keep/discard.
Starter: course/labs/L7-autoresearch/starter.py
Checkpoints:
Objective: Agent generates a new agent persona from documentation.
Starter: course/labs/L7-meta-agent/starter.py