ACAgentic Craft

Advanced~28 minHazelJS

HITL Suspension in Production

Operate durableSuspend and approveAndResume with redaction and idempotent writes—full snippet.

Authors
editorial-team
Published
Last reviewed
Progress is stored locally in this browser.

Direct answer

Enable durableSuspend, gate writes with PolicyEngine require_approval, return waiting executionId, resume with approveAndResume.

Guide: /guides/add-human-approval-without-breaking-the-run.

Worked example

typescript
import {
  AgentRuntime,
  PolicyEngine,
  createDurableRunStore,
  defaultPiiMaskPolicies,
} from '@hazeljs/agent';

const store = createDurableRunStore('./.hazel/runs');
const runtime = new AgentRuntime({
  llmProvider,
  durableSuspend: true,
  runRepository: store.runRepository,
  checkpointService: store.checkpointService,
  humanTaskService: store.humanTaskService,
  policyEngine: new PolicyEngine([
    ...defaultPiiMaskPolicies(),
    {
      id: 'refund-needs-approval',
      tool: 'processRefund',
      effect: 'require_approval',
      priority: 20,
    },
  ]),
});

// HTTP handler — do not await the human
const waiting = await runtime.execute('order-desk', 'Refund ORD-100');
return { status: 'suspended', executionId: waiting.executionId };

// Later, from an authenticated ops endpoint:
const done = await runtime.approveAndResume(waiting.executionId, {
  approved: true,
  approvedBy: 'ops@example.com',
});

CLI runs resume|approve on a file store records intent; app code must still call approveAndResume.

Artifact: Approval channel redaction checklist

Sources

Related