Templates
create-agent-express ships with four templates that scaffold ready-to-run agent projects. Each template includes an agent definition, tests, TypeScript configuration, and environment setup.
# Use a specific templatenpx create-agent-express --template <name>
# Use the default template with zero promptsnpx create-agent-express --default
# Interactive wizardnpx create-agent-expressAll templates share the same project structure:
src/agent.ts -- Agent definition with middleware and toolstests/agent.agent.test.ts -- Tests using TestModel (no API key needed)package.json -- Scripts: dev, testtsconfig.json -- TypeScript configuration (ESM, strict).env.example -- API key placeholderCLAUDE.md -- API reference for AI-assisted developmentAGENTS.md -- Agent architecture documentationDefault
Section titled “Default”A minimal starter agent with a single tool. Good for learning the framework or starting a new project from scratch.
npx create-agent-express --template defaultWhat’s included:
- Agent named
"assistant"withanthropic/claude-sonnet-4-6 - One example tool:
get_weatherwith Zod schema validation - System instructions: “You are a helpful assistant. Answer questions clearly and concisely.”
- Default middleware auto-applied (retry, usage tracking, tools observation, duration, maxIterations)
- Test file with three tests using
TestModelandtestAgent()
Middleware used:
tools.function()— registers theget_weathertool- Defaults (auto-applied):
model.retry(),observe.usage(),observe.tools(),observe.duration(),guard.maxIterations()
Agent code:
import { Agent, tools } from "agent-express"import { z } from "zod"
const agent = new Agent({ name: "assistant", model: "anthropic/claude-sonnet-4-6", instructions: "You are a helpful assistant. Answer questions clearly and concisely.",})
agent.use( tools.function({ name: "get_weather", description: "Get current weather for a city", schema: z.object({ city: z.string().describe("City name, e.g. 'San Francisco'"), }), execute: async ({ city }) => { const conditions = ["Sunny", "Cloudy", "Rainy", "Partly cloudy"] const temp = Math.floor(Math.random() * 30) + 10 const condition = conditions[Math.floor(Math.random() * conditions.length)] return { city, temperature: `${temp}C`, condition } }, }),)
export default agentCoding
Section titled “Coding”A coding assistant with file system tools and safety guardrails. Demonstrates tool approval, budget limits, and the dev console.
npx create-agent-express --template codingWhat’s included:
- Agent named
"coding"withanthropic/claude-sonnet-4-6 - Three tools:
read_file,write_file(requires approval),list_dir - System instructions covering file reading, writing, and code style guidelines
- Approval gate that blocks writes to sensitive system paths (
/etc,/usr,/System, etc.) - Budget cap at $0.50 per session
- Dev console for terminal tracing
Middleware used:
tools.function()— three file system toolsguard.approve()— human-in-the-loop approval forwrite_filewith path-based deny rulesguard.budget({ limit: 0.50 })— cost capdev.console()— lifecycle terminal trace- Defaults (auto-applied):
model.retry(),observe.usage(),observe.tools(),observe.duration(),guard.maxIterations()
Key patterns demonstrated:
requireApproval: trueon thewrite_filetool definition- Path-based deny rules in the approval function
approve()anddeny()helper functions
Research
Section titled “Research”A research agent with web search, report saving, model routing, and output guardrails. Demonstrates cost optimization and PII redaction.
npx create-agent-express --template researchWhat’s included:
- Agent named
"research"withanthropic/claude-sonnet-4-6 - Two tools:
web_search(fake results for demo) andsave_report - System instructions with a 4-step workflow: break down question, search, synthesize, save
- Model router that uses cheaper models for simple queries
- Output guard that redacts email addresses and phone numbers
- Turn timeout at 30 seconds
Middleware used:
tools.function()— search and report saving toolsmodel.router()— routes simple queries toclaude-haiku-3-5, medium/complex toclaude-sonnet-4-6guard.output()— PII redaction (email and phone patterns)guard.timeout({ turn: 30_000 })— turn time limit- Defaults (auto-applied):
model.retry(),observe.usage(),observe.tools(),observe.duration(),guard.maxIterations()
Key patterns demonstrated:
- Complexity-based model routing for cost optimization
- Output validation with text transformation (redaction)
- Turn-level timeouts
Support-Bot
Section titled “Support-Bot”A production-style customer support bot with order management, refund processing, prompt injection defense, memory compaction, and structured logging. The most complete template.
npx create-agent-express --template support-botWhat’s included:
- Agent named
"support-bot"withanthropic/claude-sonnet-4-6 - Two tools:
lookup_orderandprocess_refund(requires approval) - Fake order database with three sample orders
- System instructions for ShopCo e-commerce support
- Budget guard at $1.00 per session
- Approval gate: auto-approves refunds under $100, denies larger ones
- Input guard blocking common prompt injection patterns
- Memory compaction at 4096 tokens (truncation strategy)
- Structured JSON logging
Middleware used:
tools.function()— order lookup and refund processingguard.budget({ limit: 1.0 })— cost capguard.approve()— conditional approval based on refund amountguard.input()— prompt injection detectionmemory.compaction({ maxTokens: 4096 })— context window managementobserve.log()— structured JSON logging to stderr- Defaults (auto-applied):
model.retry(),observe.usage(),observe.tools(),observe.duration(),guard.maxIterations()
Key patterns demonstrated:
- Conditional tool approval based on business rules (refund amount threshold)
- Input validation with pattern matching for prompt injection
- Memory compaction for long-running support conversations
- Structured logging for observability pipelines
- Multiple guard layers working together (budget + approval + input validation)
Running a Template
Section titled “Running a Template”After scaffolding, set up your project:
# Install dependenciesnpm install
# Add your API keycp .env.example .env# Edit .env and add your ANTHROPIC_API_KEY
# Start the dev REPLnpm run dev
# Run tests (no API key needed -- uses TestModel)npm test