Costo: Live runs call the Claude API and are billed to your Anthropic account. Steward stops at a daily spending limit (limits.dailyUsd, $5 by default).
Build an OpenClaw-style agent.
A chat window forgets you when you close it, waits for you to type, cannot touch anything outside the text box, and lives in one app. A persistent assistant fixes all four: it remembers, it acts with tools, it reaches you on more than one channel, and it can start work on its own schedule. OpenClaw made this kind of assistant popular. In this lab you build one yourself, one subsystem at a time, and you understand every line of it.
The assistant you build is called Steward. Its default persona is a certification study coach: it remembers your exam and your weak areas, answers with real dates, and (in later labs) reminds you to study, asks before it runs anything risky, and hands research to a helper agent.
This lab is not affiliated with OpenClaw. OpenClaw is mentioned as a well-known example of this kind of assistant.
Related certifications
The lab follows the domains of these exams, so building it is also exam preparation:
- Claude Certified Architect - Foundations (CCA-F) - the main one. Every lab step maps to a CCA-F domain (see the table below).
- NVIDIA-Certified Professional: Agentic AI (NCP-AAI) - agent architecture, memory, tools, and multi-agent design.
- AWS Certified Generative AI Developer - Professional (AIP-C01) - building agents and tool use on a model API.
- Microsoft Azure AI Apps and Agents Developer Associate (AI-103) - building AI apps and agents.
What you build
Código del diagrama
flowchart TB
T[Terminal] --> G
W[Web chat] --> G
S[Scheduler] --> G
A[Sub-agents] --> G
G[Gateway: one queue per session] --> L[Turn loop]
C[Context: persona, rules, memory, caching] --> L
L --> TO[Tools + permissions + approvals]
L --> M[Model client: Anthropic API or a test fake]
L --> LOG[(Session event log)]- A turn loop that streams answers, calls tools, and handles every way a model call can end.
- A session log on disk that is only ever appended to, so conversations survive restarts and crashes.
- Context assembly that keeps the prompt cache warm and costs visible.
- Tools with validated input, a confined workspace, and no shell.
- Approvals that wait for your answer, even hours later, from any channel.
- Long-term memory the assistant curates itself, kept apart from conversations.
- Long-conversation handling with the API's server-side compaction.
- Channels (terminal and a local web chat) behind one gateway.
- A scheduler for reminders the assistant can set on its own.
- Sub-agents with their own context, a cheaper model, and a budget.
- Tests that run without an API key, using a scripted fake model.
Details: docs/architecture.md. Security model: docs/security.md. Terms: docs/glossary.md.
Lab path
| # | Lab | Status | CCA-F domain |
|---|---|---|---|
| 00 | Setup and baseline | Available | Agentic Architecture & Orchestration |
| 01 | The turn loop | Available | Agentic Architecture & Orchestration |
| 02 | Durable sessions | Available | Context Management & Reliability |
| 03 | Context assembly and caching | Available | Context Management & Reliability; Prompt Engineering & Structured Output |
| 04 | Tools | Available | Tool Design & MCP Integration |
| 05 | Permissions and approvals | Available | Agentic Architecture & Orchestration; Tool Design & MCP Integration |
| 06 | Long-term memory | Available | Context Management & Reliability |
| 07 | Long conversations | Available | Context Management & Reliability |
| 08 | Gateway and channels | Available | Agentic Architecture & Orchestration |
| 09 | Scheduler | Available | Agentic Architecture & Orchestration |
| 10 | Sub-agents | Available | Agentic Architecture & Orchestration |
| 11 | Testing and evals | Available | Prompt Engineering & Structured Output; Context Management & Reliability |
| 12 | Run it for real | Available | Context Management & Reliability |
Labs 00-09 are the core path. Labs 10-12 are advanced and can be done in any order. Each lab
takes 20-45 minutes and ends with a checkpoint: pnpm lab <number>.
Get the lab
- Download the lab from its page on CertLabPro: certlabpro.com/labs/persistent-ai-assistant (Download the lab; the download includes the checkpoint tests).
- Unzip it and open a terminal in the folder:
cd persistent-ai-assistant
git init -q && git add -A && git commit -qm "lab baseline" # so you can undo experimentsQuick start
Requirements: Node.js 24 or later, pnpm, and access to the Claude API (an ANTHROPIC_API_KEY
environment variable, or a profile from ant auth login).
pnpm install
pnpm steward doctor # checks config, paths, and credentials
pnpm steward ask "What is an AI agent, in one sentence?"
pnpm steward init # copy the example study workspace to ~/steward-workspace
pnpm steward chat # the full assistant in the terminal
pnpm steward serve # web chat on http://127.0.0.1:8787 + scheduler + terminalOptional: copy config/steward.example.json to config/steward.json and edit it (your name,
time zone, model). The local copy is git-ignored.
Commands
| Command | What it does | Lab |
|---|---|---|
pnpm steward doctor |
Check config, files, and credentials | 00 |
pnpm steward ask "<question>" |
One stateless model call | 00 |
pnpm steward chat --ephemeral |
Chat with the two time tools; nothing is saved | 01 |
pnpm steward chat |
Chat backed by a durable session log | 02 |
pnpm steward sessions |
List sessions | 02 |
pnpm steward show |
Print the current session's event log | 02 |
pnpm steward usage |
Tokens, cost, and cache hits per session | 03 |
pnpm steward init |
Copy the example study workspace | 04 |
pnpm steward audit [n] |
The last tool decisions | 05 |
pnpm steward memory [entry] |
List or print long-term memory | 06 |
pnpm steward serve |
Web chat, scheduler, and terminal together | 08 |
pnpm steward jobs [run <id>] |
List scheduled jobs, or run one now | 09 |
pnpm steward eval [name] [--repeat N] |
Behavioral evals against the real model (costs money) | 11 |
pnpm steward backup [folder] |
Copy the data folder | 12 |
pnpm lab <n> |
Run one lab's checkpoint tests | all |
pnpm check |
Types, lint, formatting, and all tests | all |
Inside a chat: /new starts a new conversation, /usage shows tokens, cost, and context size,
/pending, /approve <id> [always], and /deny <id> answer approval requests, /help lists
commands, /quit (or Ctrl+D) leaves, and Ctrl+C cancels an answer in progress.
Project layout
persistent-ai-assistant/
README.md this file
lab.json lab metadata (title, steps, related certifications)
config/ steward.example.json, persona.md, rules.md, subagent.md
docs/ architecture, security, glossary
labs/NN-name/ one guide per lab step
examples/workspace/ the example study workspace (`steward init`)
src/
cli.ts the `steward` command
app.ts builds the assistant from config
config/ config loading and validation
core/ model client, turn loop, assistant
context/ system prompt, per-turn context, usage and cost
sessions/ event log, sessions, session store
tools/ tool contract, workspace, file and program tools
security/ policy, audit log, spending ledger
memory/ the memory tool and its backend
channels/ terminal and web chat
gateway/ the gateway and the per-session queue
scheduler/ cron, jobs, scheduler, scheduling tools
agents/ sub-agents
evals/ the behavioral eval runner
runtime/ process lock and backups
evals/scenarios/ eval scenarios (JSON)
deploy/ launchd, systemd, and Docker files
tests/
fakes/ scripted fake model and test helpers
labs/ checkpoint tests, one file per lab
scripts/lab.ts runs one lab's testsData (sessions, memory, jobs, the audit log, spending, the outbox, and "always" approvals) is
stored in ~/.steward/,
outside the project; set STEWARD_DATA_DIR to use another folder. File tools and programs work
only inside the workspace, ~/steward-workspace by default (paths.workspace).
How this lab uses the Claude API
Each row is one Claude API feature, where Steward uses it, and the page on the Claude Developer Platform docs that explains it.
| Concept | In this lab | Documentation |
|---|---|---|
| Messages API | Every model call goes through AnthropicModel.complete() in src/core/anthropic-model.ts, on the beta endpoint (client.beta.messages) |
Using the Messages API, Create a Message |
| TypeScript SDK | @anthropic-ai/sdk 1.12.0; new Anthropic() finds ANTHROPIC_API_KEY or an ant auth login profile on its own; message and tool types come from the SDK |
TypeScript SDK |
| Streaming | client.beta.messages.stream() with a text listener and finalMessage() (lab 01) |
Streaming |
| Stop reasons and refusal fallbacks | runTurn() in src/core/turn-loop.ts handles every stop_reason; fallbacks: 'default' with the server-side-fallback-2026-07-01 beta (lab 01) |
Stop reasons and fallback |
| Tool use | src/tools/tool.ts turns a Zod schema into input_schema and validates the model's input; src/core/turn-loop.ts sends tool_result blocks, with is_error for failures (labs 01, 04) |
Tool use overview, How tool use works, Define tools, Handle tool calls |
| Parallel tool calls | runBatch() in src/core/turn-loop.ts answers every tool_use of one response in one user message (labs 01, 05) |
Parallel tool use |
| Memory tool | src/memory/memory-tool.ts declares memory_20250818; src/memory/memory-store.ts is the backend (lab 06) |
Memory tool |
| Prompt caching | Top-level cache_control in buildRequestParams(); a stable system prompt (src/context/system-prompt.ts); per-turn facts in the user message (src/context/turn-context.ts) (lab 03) |
Prompt caching |
| Context windows and long conversations | contextTokens in src/core/turn-loop.ts; context_management with clear_tool_uses_20250919 and compact_20260112 in buildRequestParams() (lab 07) |
Context windows, Context editing, Compaction |
| Model choice and effort | model.main, model.subagent, and model.effort in the config; output_config.effort, and output_config.task_budget for sub-agents (lab 10) |
Models overview, Choosing a model |
| Pricing | pricing in config/steward.example.json (with the Haiku 5.5 long-prompt tier); costOf() and costOfTurn() in src/context/usage.ts price each request at the model that served it (lab 03) |
Pricing |
| Errors and rate limits | The SDK retries rate limits and server errors itself; AnthropicModel.complete() re-sends only a broken stream, and the CLI prints the SDK's typed error |
Errors, Rate limits |
| Prompts | config/persona.md, config/rules.md, and config/subagent.md (labs 00, 03, 10) |
Prompt engineering overview, Prompting best practices |
| Prompt-injection defense | Rule 1 in config/rules.md, src/security/policy.ts, src/tools/workspace.ts, the memory secret scan, and the planted-instruction eval (labs 04-06, 11) |
Mitigate jailbreaks and prompt injections |
| Evals | src/evals/runner.ts and evals/scenarios/*.json (lab 11) |
Define success criteria and build evaluations |
| Spending limits | Steward's own daily cap, limits.dailyUsd (src/security/budget.ts, lab 12); a monthly spend limit on your workspace in the Claude Console caps everything billed to that workspace |
Workspaces |
| Agent design | The turn loop, the gateway, sub-agents, and context assembly | Building effective agents, Effective context engineering |
Some parts are built by hand on purpose, so you see how they work: Steward runs its own turn loop
instead of the SDK's tool runner, keeps its own
session log because every Messages API request carries the whole conversation, and writes its own
backend for the API's memory tool (the SDK also ships betaMemoryTool). For long conversations it
does the opposite: it uses the API's compaction and context editing instead of summarizing by hand.
Tests and cost
pnpm test runs every checkpoint with a scripted fake model: no API key, no network, no cost.
Only ask, chat, serve, jobs run, and eval call the real API. The default model is
claude-opus-5-5 ($4 per million input tokens, $20 per million output tokens). For cheaper
experiments set model.main to claude-sonnet-5-5 ($2 / $10) or claude-haiku-5-5 ($0.10 /
$0.50 for prompts up to 100,000 tokens) in your local config, and use /usage to watch token
counts. Prices change: check the pricing page before you rely on them.
Practice for the exam
Building an agent teaches how the pieces fit. The exam also asks you to choose between designs under time pressure. Practice with CCA-F questions and full mock exams on CertLabPro, or study on your phone with the CertLabPro app for iOS and Android.