Foundation~25 minHazelJS
Scaffold Your First HazelJS Agent
Set up a runnable HazelJS project, install packages, choose mock vs real LLM, and verify the environment before writing tools.
- Authors
- editorial-team
- Published
- Last reviewed
What you will build in this track
Across these lessons you build one Ops Desk agent on HazelJS:
- Look up order
ORD-1001with a read-only tool - Bound the run so it cannot loop forever
- Keep tool results small and safe for the model
- Add a refund tool that requires human approval
- Lock behavior with
describeAgenttests - Watch runs in timelines / CLI
- Promote with a production checklist
You do not need prior agent frameworks. You do need basic TypeScript and Node.
Docs: Agent package, Agent OS. Companion hands-on guide: /guides/build-your-first-tool-using-agent.
Step 1Pick a project path
| Path | Use when |
|---|---|
hazeljs-agent-os-starter in hazel-js/hazeljs | You want Inspector, DI, and Agent OS wiring already present |
Greenfield npm init + packages below | You want the smallest possible script to learn the loop |
Both are valid. This course shows the script path so every line is visible. Map the same code into AgentModule.forRoot later when you join a real HazelJS app.
Step 2Install packages
npm install @hazeljs/agent @hazeljs/core @hazeljs/ai
# later lessons:
# npm install @hazeljs/testing
Enable TypeScript decorators (HazelJS agents use @Agent / @Tool):
// tsconfig.json (excerpt)
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strict": true,
"esModuleInterop": true,
"moduleResolution": "bundler",
"target": "ES2022"
}
}
Step 3Start with a mock LLM
For learning, use createMockLlmProvider so you can wire the runtime without burning tokens. Swap to OpenAIProvider (or another @hazeljs/ai provider) when the tools work.
import {
AgentRuntime,
createMockLlmProvider,
} from '@hazeljs/agent';
const llm = createMockLlmProvider(
'Learning mode: replace with OpenAIProvider when tools are ready.'
);
const runtime = new AgentRuntime({
llmProvider: llm,
enableRetry: false,
enableCircuitBreaker: false,
});
console.log('Runtime ready');
Run it. If this prints without errors, your install and decorator config are fine.
Step 4Know the three pieces you will write next
| Piece | Role |
|---|---|
@Agent class | Identity, system prompt, maxSteps |
@Tool methods | Typed actions the runtime can execute |
runtime.execute(name, goal, options) | Starts the loop |
The model never calls your APIs. It only proposes tool names + args. AgentRuntime validates and executes.
Common setup mistakes
- Decorators off —
@Agentsilently does nothing useful withoutexperimentalDecorators. - Wrong agent name —
execute('OpsDesk', …)must match@Agent({ name }). - Starting with write tools — begin read-only; add refunds only after lesson 5.
- Treating CLI DNA smoke as the app —
hazel agent runstubs tools; your appexecuteis the source of truth (covered later).
Checkpoint
Before the next lesson you should have:
- A TypeScript project with
@hazeljs/agentinstalled - Decorators enabled
- A file that constructs
AgentRuntimewith a mock LLM
What to do next
Define the agent and first tool: /learn/agentic-development/tool-using-agent-loop
Artifact: Local repo that imports @hazeljs/agent and prints a successful mock runtime construct