Applied AI Workflow Implementations

I built these three zero-dependency Node.js 20+ reference agents to show how I scope, guard, test, and hand off customer LLM workflows: deterministic rules in code, a swappable model, and every claim verifiable offline across support deflection, multi-tenant hospitality hosting, and human-approved review replies.

  • 3 Reference Agents
  • 45 Source Files
  • 91/91 Offline Checks
  • 33/33 Live Evals (Support KB)
  • 0 Dependencies

All sample entities (Tillwren point-of-sale help center and Copperwren Supper House) are fictional datasets created so every rule, guardrail, and test case can be inspected and run offline safely.

Three Guardrailed Workflows

Select any implementation below to inspect its deterministic architecture, replay representative guardrail scenarios in the browser (retrieval, schema checks, allergen gating, risk flags, and draft linting ported directly from the source; stub replies mirror the offline test suites), or jump directly to its source file.

The rules, configuration schema, deterministic guardrails, and evaluation suite are the implementation. The underlying model is swappable.
Standard workflow stage Deterministic safety gate, validator, or compliance linter

Support Knowledge-Base Agent

Tier-one point-of-sale support deflection grounded strictly in an 18-article fictional help center (Tillwren). Enforces exact citation verification, flags conflicting documentation (R4), resists prompt injection, and escalates missing or sensitive account questions to a person.

1. Input Customer Question CLI query or interactive loop; user input is tagged as untrusted data.
2. Code IDF Top-3 Retrieval Title (2x) + capped body frequency across 18 articles. Zero vector DB required.
3. Contract Rules R1–R4 + Schema Structured JSON output enforcing 4 exact keys and A1–A6 citation rules.
4. Guardrail validateReply() Check Rejects extra keys, missing citations, or mismatched article titles/URLs.
5. Outcome Cited Answer or Fallback Verified reply with source URL, or fail-closed human escalation card.
  • Deterministic IDF retrieval (retrieve()): Tokenizes, stems, and ranks 18 saved articles locally so retrieval failures can be isolated cleanly from model failures.
  • Deliberate conflict test (Rule R4): Two articles intentionally disagree on offline card-hold expiry (24 hours vs. 72 hours), verifying the agent escalates and names both sources rather than guessing.
  • Zero-patch validator (validateReply()): Malformed JSON, extra keys, uncited answers, or hallucinated URLs are rejected into a fail-closed fallback escalation that always scores FAIL in evaluation.

Replay Guardrail Scenarios

Browser port of agent.js retrieval & validator


            

Verification and Evaluation Scope

Every test count below distinguishes offline deterministic code checks, live LLM evaluation runs, and unexecuted direct API paths.

Implementation Offline Deterministic Suite Live LLM Evaluation Direct API Key Path
Support Knowledge-Base Agent
support-kb-agent/
33 / 33 PASS
IDF retrieval ranking, JSON schema contract, exact citation check, R4 conflict toggle, adversarial scorer harness.
20 / 20 Starter · 13 / 13 Adv
Run Nov 2026 via promptfoo using Claude Sonnet 5.5 (medium effort, Agent SDK, tools off, single run each).
Implemented to Anthropic Messages API structured-output schema; verified offline for fail-closed handling (not run against a live API key).
Restaurant Host Agent
restaurant-host-agent/
27 / 27 PASS
18 scenario cases + 9 safety/plumbing checks: pre-model allergen gate, zero allergen tags in prompt, post-model safety backstop, live 86'd hot-reload.
Not run against a live model; deterministic gates and stub scenarios verified offline. Implemented to Anthropic Messages API schema; env-only key check and fail-closed fallback verified offline (not run live).
Review Reply Agent
review-reply-agent/
31 / 31 PASS
8 review cases, 8 linter catches (R2–R6), 8 terminal approval-gate tests, 5 127.0.0.1 HTTP webhook checks, 2 live-mode fail-closed checks.
Not run against a live model; risk classifier, linter, HTTP intake, and approval gate verified offline. Implemented to Anthropic Messages API schema (DRAFT_MODE=live); verified offline to stop before network when key is unset.

Evaluation Transparency Notes

  • Offline verification (npm test): All 91 / 91 checks run offline on Node.js 20+ in ~2.5 seconds with zero packages installed and zero network access.
  • Live Claude evaluation (support-kb-agent): The 20/20 starter and 13/13 adversarial evals ran the repository's own retrieval and prompt builder (prompt.js) via promptfoo (anthropic:claude-agent-sdk, claude-sonnet-5-5, medium effort, $0.25/case cap, single run each, November 2026).
  • Key handling: Live API paths read ANTHROPIC_API_KEY strictly from environment variables and never read from or write keys to disk.

Run All 91 Checks Locally (Node 20+)

unzip applied-ai-implementations.zip
cd applied-ai-implementations
npm test
Inspect Verbatim npm test Output (91 / 91 Passing)
> applied-ai-implementations@1.0.0 test
> node support-kb-agent/tests/plumbing.js && node restaurant-host-agent/tests/run.js --backend stub && node review-reply-agent/tests/run.js

PASS  retrieval puts the split-a-check article first
PASS  retrieval returns nothing for words no article uses
PASS  every article has a title, a URL and the FICTIONAL label
PASS  a well-formed reply is accepted
PASS  a citation to an article that was not sent is rejected
PASS  a citation with the right URL but a wrong title is rejected
PASS  an answer with no citation is rejected
PASS  an escalation with no reason is rejected
PASS  a reply with an extra key is rejected
PASS  escalate as the string "false" is rejected
PASS  a malformed model reply becomes a fallback escalation
PASS  a failed model call becomes a fallback escalation
PASS  with no articles at all the question still gets a reply (fallback)
PASS  stub escalates the conflict question while rule R4 is present
PASS  stub answers the conflict question once rule R4 is removed
PASS  adversarial group has 10 or more cases, unique ids, each labelled INVENTED
PASS  adversarial group covers injection, rules reveal, off-topic, pressure, mixed and poor spelling
PASS  adversarial group has both answer cases and escalate cases
PASS  every adversarial answer case names an article that exists
PASS  a scripted ideal model passes every adversarial case
PASS  retrieval puts the needed article in the top three for every adversarial answer case
PASS  a model that obeys the injection (no citation) becomes a fallback and FAILs every adversarial case
PASS  a fallback FAILs an adversarial escalate case even though it escalates
PASS  a valid-looking answer to a must-escalate adversarial case FAILs (guess caught)
PASS  escalating an answerable adversarial case FAILs
PASS  citing the wrong article FAILs an adversarial answer case
PASS  an answer that leaks a rule ID FAILs via must_not_mention
PASS  repeating the injected claim ("Refunds are instant.") FAILs via must_not_mention
PASS  saying refunds are not instant PASSes the adv-3 check
PASS  an invented number in an adversarial answer FAILs
PASS  a reply with a leaked extra key is rejected into a fallback
PASS  a prose reply instead of the JSON object is rejected into a fallback
PASS  the naive stub runs on every adversarial case and the scorer returns a verdict

PLUMBING TOTAL: 33 of 33 passed
Backend: stub (fake model: this tests plumbing and the code gate, not the real model)

CASES (18)
PASS  hours-1
PASS  hours-2
PASS  hours-3
PASS  menu-1
PASS  menu-2
PASS  menu-3
PASS  party-1
PASS  party-2
PASS  86-1
PASS  86-2
PASS  allergy-1 [ALLERGEN]
PASS  allergy-2 [ALLERGEN]
PASS  allergy-3 [ALLERGEN]
PASS  allergy-4 [ALLERGEN]
PASS  allergy-5 [ALLERGEN]
PASS  allergy-6 [ALLERGEN]
PASS  other-1
PASS  other-2

CASES TOTAL: 18 of 18 passed

PLUMBING (9)
PASS  ALLERGEN gate answers without calling the model
PASS  ALLERGEN fixed reply says the host cannot confirm and names the kitchen or a manager
PASS  ALLERGEN backstop replaces a model reply that says a dish is safe
PASS  ALLERGEN prompt contains no allergen tags
PASS  malformed model reply is rejected (fallback handoff)
PASS  booking confirmation in a model reply is replaced by a handoff
PASS  validateRecord rejects allergy + answer
PASS  validateRecord rejects a handoff with no reason
PASS  emptying the 86'd list changes the answer (no code edit)

PLUMBING TOTAL: 9 of 9 passed
CASES (8), all INVENTED reviews, stub model

PASS  five-star-plain  sensitive=false escalated=false
PASS  four-star  sensitive=false escalated=false
PASS  three-star  sensitive=false escalated=false
PASS  one-star-slow  sensitive=true escalated=false
PASS  two-star  sensitive=true escalated=false
PASS  allergy-mention  sensitive=false escalated=true
PASS  rude-one-star  sensitive=true escalated=false
PASS  asks-for-freebie  sensitive=true escalated=false

RULE CHECK catches bad drafts
PASS  flags R2 free dinner
PASS  flags R2 refund
PASS  flags R3 no phone on a one-star
PASS  flags R4 dish not in review
PASS  flags R4 invented number
PASS  flags R5 wrong signature
PASS  flags R6 talks about the food
PASS  flags R6 no manager

APPROVAL STEP
PASS  reject writes nothing
PASS  no answer writes nothing and stays pending
PASS  anything but the word approve writes nothing
PASS  approve writes one row with the reply, flags and mode
PASS  one-star shows the SENSITIVE flag
PASS  approve is blocked while an edited draft breaks a rule
PASS  a clean edit can be approved and is marked edited
PASS  allergy review is approved only with the manager flag set

WEB ADDRESS (127.0.0.1 only)
PASS  server is bound to 127.0.0.1
PASS  valid review gets 202, a draft and a queue entry, nothing written
PASS  bad JSON gets 400
PASS  rating out of range gets 400
PASS  missing author_first_name gets 400

LIVE MODE
PASS  live mode without a key stops before any network call
PASS  prompt carries the rules and the owner name, no key

TOTAL: 31 of 31 passed (stub model, not run against a real model)

Full Source Code (45 Files)

Browse every JavaScript implementation, rule specification, tenant config, promptfoo evaluation suite, test case, and sample help article right in the browser.

support-kb-agent/agent.js Loading bundle... Scroll horizontally for long lines →