Intermediate~40 minHazelJS
From Agent Demo to Production
Promote a working HazelJS demo through Agent OS: policies, HITL, durable store, contracts, recovery, governance, Inspector, and DNA.
- Authors
- editorial-team
- Published
- Last reviewed
- A demo @Agent that sometimes completes a real tool-using task on AgentRuntime
- Willingness to constrain autonomy with Agent OS options before scaling it
- A phased promote-to-production plan mapped to Agent OS capabilities
- HITL with durableSuspend/approveAndResume and durable run stores
- Policies, contracts, recovery, governance, Inspector, and DNA gates before writes
On this page
Who this is for
You have a HazelJS demo that sometimes completes a real task with @Tool methods. Stakeholders want it “in prod next sprint.” This guide sequences Agent OS work so you do not scale autonomy past control.
Pair with the checklist lesson: /learn/agentic-development/from-demo-to-production-checklist. Capability map: Agent OS.
Reality check
Ask:
- What side effects can tools perform today?
- What happens on retry after a crash mid-tool?
- Who gets paged when it misbehaves at 2am?
- What is the monthly cost ceiling (
costRoute/ budgets)? - How do you know a prompt or DNA change did not break
describeAgentfixtures?
If answers are vague, you have a prototype—not a service.
Agent OS capability map (use these names)
| Pillar | API |
|---|---|
| Confidence loop | options.loop — plan → execute → critique → validate |
| Durable process | AgentRun + createDurableRunStore / createSqlDurableRunStore |
| Durable HITL | durableSuspend · approveAndResume |
| Identity / budget | AgentIdentity · capabilities · RunBudget |
| Policies | PolicyEngine — allow / deny / mask / require_approval |
| Contracts | options.contract (+ fallback agent) |
| Recovery | options.recovery |
| Cost routing | CostOptimizer / options.costRoute |
| Governance | GovernanceGate / options.governance |
| Observe | Timeline · Inspector SSE · getTimeline |
| Testing | @hazeljs/testing describeAgent |
| DNA | exportAgentDna / bootstrapRuntimeFromDna / hazel agent run |
Phase A — Contain (1–3 days)
Goal: prevent catastrophic autonomy.
- Remove or disable irreversible tools
- Enforce
maxStepsandloop.maxIterationsin runtime - Add a global kill switch (feature flag)
- Lock credentials to least privilege / capabilities
- Turn on timeline logging with redaction (
defaultPiiMaskPolicies)
Ship containment before polish.
await runtime.execute('support-desk', message, {
loop: {
maxIterations: 4,
stages: ['plan', 'execute', 'critique', 'validate'],
},
costRoute: { qualityBias: 0.35, maxCostUsd: 0.05 },
});
Phase B — Make writes safe (3–10 days)
For every write tool:
- Side-effect classification
- Idempotency key strategy in the adapter
requiresApproval: true+PolicyEnginerequire_approvaldurableSuspend: trueand resume withapproveAndResume- Compensating action notes
const store = createDurableRunStore('.hazel/runs');
const runtime = new AgentRuntime({
llmProvider,
durableSuspend: true,
runRepository: store.runRepository,
checkpointService: store.checkpointService,
humanTaskService: store.humanTaskService,
policyEngine: new PolicyEngine([
{
id: 'refund-hitl',
tool: 'processRefund',
effect: 'require_approval',
priority: 20,
},
]),
});
const waiting = await runtime.execute('support-desk', 'Refund ORD-100');
await runtime.approveAndResume(waiting.executionId, {
approved: true,
approvedBy: 'ops@example.com',
});
Failure drill: kill the process after a successful external write but before checkpoint; fix until resume is safe (/patterns/durable-agent-run, /patterns/human-approval-gate).
For SQL process stores: createSqlDurableRunStore(prisma) with Agent OS Prisma models from the package example schema.
Phase C — Contracts, recovery, governance
Wire the remaining execute options from the Agent OS guide:
await runtime.execute('support-desk', message, {
loop: { maxIterations: 4, successScore: 90 },
contract: {
name: 'support-desk-slo',
maxLatencyMs: 30_000,
fallbackAgent: 'safe-desk',
},
recovery: {
maxRetries: 2,
fallbackAgent: 'safe-desk',
steps: ['retry', 'fallback_agent', 'fail'],
},
costRoute: { qualityBias: 0.35, maxCostUsd: 0.05 },
governance: {
action: 'agent.execute',
roles: ['agent:run'],
residency: 'eu',
compliancePacks: ['soc2'],
},
});
Also configure GovernanceGate / defaultAgentGovernance on AgentModule.forRoot when running inside a DI app.
Phase D — Prove quality (ongoing)
- Expand golden set: happy paths, tool errors, injection-like observations
- Put
describeAgentsuites in CI - Optional digital twin / canary (
runDigitalTwin/shouldRunCanary) before full traffic - Track success rate, human takeover rate, cost per success
Phase E — Operate with Inspector
- Timeline store (
FileTimelineStore) andgetTimeline - Inspector SSE / run endpoints (
/__hazel/agents/:name/…) - Dashboards and alerts (tool errors, budget exhaustion, approval lag)
- Runbook: pause agent, revoke tool auth, export timeline
- Named owners and an SLO—even a soft one tied to
contract - Security review against OWASP LLM Top 10
Phase F — DNA and expand autonomy deliberately
exportAgentDnafor prompt, tools metadata, policies, contracts- Review DNA in PRs; smoke with
hazel agent run ./agent.dna.json "hello" --mock/bootstrapRuntimeFromDna - Raise autonomy only when metrics are green: broader reads → reversible writes → gated irreversible → higher budgets → memory layers with retention (/patterns/memory-layers)
- Document each raise as a DNA version (/guides/design-an-agent-manifest)
Remember: DNA is configuration + contract; TypeScript @Tool handlers still live in the app.
Organizational pitfalls
- Demo-driven deadlines that skip kill switches and
durableSuspend - Shared admin API keys “just for the hackathon”
- No owner after the building team rotates
- Eval theater — three anecdotes instead of
describeAgentfixtures
Done when
- Checklist blockers cleared or formally accepted with expiry
- On-call can pause the agent and approve/reject HITL without the original author
- A DNA/prompt change that breaks a golden task fails CI
Next
Sources
- HazelJS Agent OS guide — Capability map: durableSuspend, loop, contract, recovery, costRoute, governance
- HazelJS Agent package
- OWASP Top 10 for LLM Applications