Safeguard Work-Order Agent Ecosystem

Architecture

← Back to outcome

Architecture — Work-Order Agent Ecosystem

Pipeline (live stack)

HTTP POST /work-orders (server.mjs)
      │
      ▼
┌───────────────┐   classification (category, priority, fields, confidence)
│  Classifier   │
└───────────────┘
      │
      ▼
┌───────────────┐  routing (queue, crew, region, SLA)
│    Router     │
└───────────────┘
      │
      ▼
┌───────────────┐  VALID │ NEEDS_REVIEW │ REJECT   (duplicate check = DB query)
│   Validator   │───────────────┬───────────────────┐
└───────────────┘               │                   │
      │ VALID                   │ NEEDS_REVIEW       │ REJECT
      ▼                          ▼                   ▼
┌───────────────┐        ┌──────────────┐   ┌──────────────┐
│   Actioner    │        │ human excep- │   │  rejected +  │
└───────────────┘        │ tion queue   │   │  audited     │
   │            │        └──────────────┘   └──────────────┘
   │ gRPC wire  │ repository
   ▼            ▼
real gRPC     real PostgreSQL
DispatchSvc   (work_orders, audit_log, dispatch_records)

Design principles

  1. Agents are pure where possible. Classifier and router are pure functions;

the validator is pure given a pre-computed duplicate flag; only the actioner performs side effects, through the gRPC + repository seams.

  1. Confidence drives autonomy. The classifier emits calibrated confidence;

the validator converts low confidence into a human exception.

  1. Safety is conservative by default. Ambiguity, missing data, over-budget,

and duplicates route to a human. False-auto-action rate is a MUST_PASS metric pinned at 0.

  1. Real, contract-first integration. Dispatch is a real gRPC/HTTP2 call

defined by proto/dispatch.proto; persistence is real PostgreSQL via a repository interface. The same interfaces target a Go gRPC service and an external Postgres/Oracle server.

  1. Everything is auditable + durable. Every order produces one append-only

audit_log row; state lives in work_orders; dispatches in dispatch_records; all durable on disk.

Module map

ModuleResponsibility
src/schema.mjsdomain vocabulary + dispatch-payload contract
src/agents/classifier.mjsclassify + extract + confidence
src/agents/router.mjsrouting policy
src/agents/validator.mjsbusiness-rule safety boundary
src/agents/actioner.mjsdispatch / exception / reject + side effects
src/orchestrator.mjsend-to-end pipeline + HITL metric
src/config.mjsenvironment-based configuration
src/bootstrap.mjsselects external vs. in-process; wires the pipeline
src/db/database.mjsPostgreSQL (external via DATABASE_URL, or PGlite)
src/integrations/grpc-server.mjsin-process Node gRPC service (fallback/dev)
src/integrations/grpc-gateway.mjsreal gRPC dispatch client
src/integrations/repository.mjsPostgreSQL work-order repository
dispatch-service/external Go gRPC dispatch service (+ Dockerfile)
docker-compose.ymlexternal PostgreSQL + Go service
proto/dispatch.protogRPC dispatch contract (shared Node + Go)
src/http-app.mjsHTTP request handler
server.mjsHTTP ingest service
src/synth.mjsseeded labeled corpus generator
src/evaluation.mjsscores output vs. ground truth

Production integration path

  • Go gRPC service: implement proto/dispatch.proto in Go; point the gateway

address at it. Wire-compatible, no agent changes.

  • External Postgres / Oracle: set DATABASE_URL (Postgres) or supply an

Oracle adapter behind the same repository interface.

  • LLM classifier: implement classify() with an LLM, preserving the

confidence + reasoning contract.

See run-deploy-instructions.md.