---
name: fable-5-agent-builder
description: "Build autonomous agents on Fable 5 — Agent SDK wiring, memory, sub-agents, MCP, cost guardrails. Builds production agents on claude-fable-5 with the Claude Agent SDK: session management, persistent memory, sub-agent orchestration, MCP server integration, structured outputs, and the token-budget guardrails that keep an autonomous loop from burning your API quota."
license: MIT
---

# Fable 5 Agent Builder

Fable 5 Agent Builder scaffolds production-grade autonomous agents on the `claude-fable-5` model using the Claude Agent SDK. It wires up the parts that are tedious to get right by hand — session lifecycle, persistent memory, sub-agent delegation, MCP server connections, and token-budget guardrails — so an autonomous loop runs without silently draining your API quota. It's aimed at backend and ML engineers shipping agents that run unattended rather than chat one-off prompts.

## When to use it

- You're moving past a single `query()` call into a multi-turn agent that needs to remember state across sessions.
- You want one orchestrator agent to spawn specialized sub-agents (research, codegen, review) and merge their results.
- You need to connect external tools — a database, a search API, your internal services — over MCP.
- An earlier agent loop ran away and burned tokens; you want hard ceilings before the next one ships.

## What it does

It generates a typed agent project against the Claude Agent SDK. The core is an agent loop built on the SDK's `query()` streaming interface with an `AgentDefinition` carrying your system prompt, allowed tools, and model (`claude-fable-5`). It sets up:

- **Session management** — resumable sessions so a run can pause and continue with full history.
- **Persistent memory** — a memory store (file or KV-backed) the agent reads at startup and writes facts back to between turns.
- **Sub-agents** — child agent definitions the orchestrator delegates to, each with scoped tool permissions.
- **MCP integration** — `mcpServers` config wiring stdio/HTTP servers and exposing their tools to the loop.
- **Structured outputs** — JSON-schema-validated final results instead of free text.
- **Cost guardrails** — a per-run token budget and max-turn cap that halt the loop and surface usage from the SDK's result message.

## Usage

```bash
curl -fsSL --create-dirs -o ~/.claude/skills/fable-5-agent-builder/SKILL.md https://claudeskil.com/skills/fable-5-agent-builder/SKILL.md

# Scaffold an agent
claude fable5 init research-agent --model claude-fable-5 --memory kv
```

```ts
const agent = defineAgent({
  model: "claude-fable-5",
  systemPrompt: "Research and summarize with citations.",
  mcpServers: { search: { command: "npx", args: ["my-search-mcp"] } },
  budget: { maxTokens: 200_000, maxTurns: 12 },
  memory: "./.fable/memory.json",
});
```

## Tips & gotchas

- Scope each sub-agent's `allowedTools` tightly — an orchestrator inheriting every tool is the usual cause of runaway loops.
- The budget cap counts input + output tokens including cached reads; set it above your largest expected context, not your average.
- Memory writes happen between turns, not mid-turn — if a run crashes inside a turn, that turn's facts are lost. Checkpoint important state explicitly.
- MCP stdio servers must be on PATH at runtime; missing binaries fail silently as "no tools available," not an error.

## FAQ

**Does it work with non-Fable Claude models?** Yes — change the `model` field. The SDK wiring is model-agnostic; Fable 5 is just the default and what the guardrail defaults are tuned for.

**How is memory persisted?** Either a local JSON file or a KV backend you point at. The agent loads it as context at session start and appends after each turn.

**Can I cap spend?** Yes — `budget.maxTokens` and `maxTurns` halt the loop and the SDK result reports actual usage so you can log it per run.
