The Stateless Agent Trap
TRIGGER
Agents were repeatedly solving the same multi-step tasks from scratch—like exporting a Google Sheet to CSV format—rewriting similar code each time with no way to build on previous successful implementations.
APPROACH
When an agent develops working code for a task, save it as a named function in a `./skills/` directory with a SKILL.md file describing its purpose. Input: working agent-generated code for a completed task. Output: importable TypeScript module (e.g., `./skills/save-sheet-as-csv.ts`) that future agent executions can discover and import. The agent explores the skills directory like any other code, loading existing implementations before writing new ones.
PATTERN
“Same Google Sheets export code rewritten from scratch every time—the "stateless agent trap" where each execution forgets previous successes. Agents that solved a task once may not solve it identically again; capture working code when it works. A ./skills/ directory with SKILL.md files lets the agent evolve its own toolset.”
✓ WORKS WHEN
- Tasks have recurring patterns that vary only in parameters (different sheet IDs, different CRM records)
- Agent has persistent filesystem access across executions
- Code complexity justifies reuse (>10 lines or multiple tool calls)
- Skills can be validated or tested before becoming part of the trusted library
- Agent can reliably discover and evaluate existing skills before writing new code
✗ FAILS WHEN
- Each task is genuinely novel with no recurring patterns
- Agent executions are fully isolated with no persistent storage
- Skills require frequent updates as underlying APIs change, creating maintenance burden
- Security model prohibits agents from writing executable code to persistent storage
- Skill discovery overhead exceeds time savings from reuse (small skill library, complex discovery)