Agent

How a dispute turn runs: the graph, the policy that decides, the tools that act and the models.

The LLM understands, the rules decide, the tools act, verification confirms, a person closes.

Every view on this page is generated from the repository's code and contracts; the tests fail when one drifts.

Architecture

Agent on LangGraph Platform, customer tools as an MCP server, case state in Postgres.

  • Request (HTTPS)
  • Agent run and tools
  • LLM call
  • Data
  • Delivery (CI/CD)
Overview
Services architecture: 10 services and 11 request paths, from the browser to the data and the models.Browsercustomer · analystGitHubActions · repoCaddyTLS + routingweb · Next.jspagesapi · FastAPIsessions · casesLangGraphPlatform · LangSmithmcp · FastMCP16 customer toolsPostgrescase state · auditgold · DuckDBParquet, read-onlyAmazon BedrockClaude · us-east-2
Request paths, in order

Static view (SVG) · the original drawing, which also shows the notifications and the S3 bucket.

Graph dispute_intake

15 nodes from START to END; a branch follows the policy engine, a tool read or the understood input, never the LLM's text.

  • Branch on a policy engine decision
  • Branch on a tool read or verification result
  • Branch on a understood input
  • Always next

Scroll sideways to see the whole graph; the table below lists the same nodes.

Graph dispute_intake: 17 nodes and 29 edges from START to END. Each node can be focused to read what it does.STARTidentitygreetunderstandrouteretrievestatusdeciderefuseclarifyplanactverifyduplicateconnectrespondEND
View as table (Graph nodes)
#NodeWhat it doesNext
1identityReads the session, mode and arm from the run config the api injects; never from the customer's text.greet
2greetFirst turn of a verified session: greets with the first name returned by get_customer_profile.understand
3understandLanguage, injection flag, intent and slots with the B0 rules; below τ, arms S1/S2 ask the LLM, only in a verified session.route
4routeSpec 02 rules 1–4 through the policy engine's screen(); the engine, not the graph, picks the branch.one of refuse (reauthenticate | deny) · connect (connect_person) · retrieve (screen() = none) · status (answer_status) · respond (no intent | other_language)
5refuseDeny or re-authenticate with no data and a way forward; the denial is recorded in policy_denials.respond
6connectRegisters a call request where the policy says, on the active case or a general one; never refused.respond
7retrieveFinds the customer's transaction with search_transaction; for exactly one, reads its card, score, amount and any active case.one of decide (no read_failed) · respond (read_failed)
8decideRuns the policy engine's decide() on tool facts only; the graph follows its result, never a rule of its own.one of clarify (ask) · refuse (deny) · plan (no existing_case) · duplicate (existing_case) · connect (request_call) · respond (no request_call)
9planStates the numbered steps before acting; in the confirm state it asks before anything is done.one of act (decision ≠ confirm) · respond (decision = confirm)
10actRuns only the writes decide() allowed: open_case first, then block_card when allowed, each with an idempotency key.verify
11verifyReads each write's post-condition with its verifying tool: verified only with a V- id, otherwise not confirmed and escalated.one of connect (request_call) · respond (row = reauthenticate | no request_call)
12duplicateThe charge already has an active case: nothing is opened; the case and its stored deadlines come from get_case.one of connect (request_call) · respond (no request_call)
13clarifyOne question, nothing done: up to the allowed number of option cards, or a request for the details.respond
14statusRe-reads cards or cases in this turn and answers with tool facts and the time of the reading.respond
15respondBuilds the reply, the receipt and the handoff card from templates and tool results; the grounding gate drops any fact no tool returned.END

Policies

The bank's fraud score picks a zone, the zone picks the action, and a case opens in every zone.

Fraud score
no score
Human

< 30

Medium

30–49

High

≥ 50

Also zone human, whatever the number

Amount gate

  • Amount gateApproval modechanges
  • Amount gateRegulatory clocknever changes

The amount only makes a money action's approval stricter; the legal deadline comes from the country table alone.

[data] score bands as of today, from the EDA (policies.yaml zones)

View as table (Policy ids)
Policy idWhat it decidesGuardrail
POL-SESSIONsession expired or unverified → reauthenticate, before any other ruleG-SES-01
POL-INJECTIONinput flagged by the injection detector → denyG-IN-01
POL-CROSS-CUSTOMERrequest targets another customer's data → denyG-SES-02
POL-HUMAN-REQUEST
intent human_request → connect_person with a call request; never refused. Full rule

intent human_request → connect_person with a call request; never refused. If it also reports a charge on one card transaction the customer did not reject, and the intent confidence is at least clarify.intent_confidence_min, the call goes on that transaction's case, which opens in review and is never blocked in that turn nor later while the call is open (D-029, D-042): in the high zone with person_requested, so the analyst decides the block after the call (amount_over_case_gate or supervised_mode when the block needs a person anyway); in the medium and human zones with the zone's handoff reason. After the mode check, check() denies a money action when call_requested is true; block_card reads it from the store, true until the analyst runs approve_block, resolve or close_case on the case; take, request_customer_info, mark_ambiguous and any other analyst action keep it (D-042, ADR 0024). Below that confidence, only the call

—
POL-PIIcustomer text with a card number, CVV or password → deny; nothing is stored and the agent asks not to send itG-IN-04
POL-STATUS
intent status_inquiry → answer_status; read-only, no case opened. Full rule

intent status_inquiry → answer_status; read-only, no case opened. If it also reports a charge and the customer has no active case, the turn goes on like a dispute (rules 4-9)

—
POL-OUT-OF-SCOPEintent out_of_scope with no reported charge, or the identified transaction's product is not a card → deny (polite abstention)G-IN-04
POL-CLARIFYintent confidence below clarify.intent_confidence_min, not exactly one candidate, or an out_of_scope intent that reports a charge → askG-IN-03
POL-CLARIFY-EXHAUSTEDstill unclear after clarify.max_clarification_turns → handoff (clarification_exhausted)G-IN-03
POL-SCORE-NULLno fraud score → zone human; the case is still opened—
POL-SCORE-LLMscore from the llm provider → zone human; an LLM score never decides a block—
POL-SCORE-SOURCEscore from a source not in scoring.deciding_sources → zone human—
POL-ZONE-HIGH
score in zones.high → block_and_open_case: the high zone blocks and verifies, unless the customer asked for a person in that turn: the case opens, the call is registered and the analyst decides the block after the call. Full rule

score in zones.high → block_and_open_case: the high zone blocks and verifies, unless the customer asked for a person in that turn: the case opens, the call is registered and the analyst decides the block after the call (D-029: connect_person, person_requested; held until the analyst approves the block, resolves or closes the case, D-042). When the block needs a person (amount tier, supervised mode): a handoff, or connect_person on a call request

—
POL-ZONE-MEDIUMscore in zones.medium → confirm with the customer, then open the case and hand off proposing approve_block; a call request opens the case without asking; never a block—
POL-ZONE-HUMANscore in zones.human → open the case and hand off (zone_human); no block—
POL-ZONE-MISMATCHopen_case called with a zone other than the one computed from get_fraud_score for that transaction → deny; the zone comes from the score, never from the agent or the customerG-IN-02
POL-TICKET-ALWAYSopen_case runs with mode auto in every zone; registering is not a money decision—
POL-AMOUNT-GATEthe amount tier made a money action's approval mode stricter; it never changes a deadlineG-TOOL-02
POL-AMOUNT-UNKNOWNno tier applies (country without a gate, amount missing, negative or not finite, other currency) → human_requiredG-TOOL-02
POL-SUPERVISEDsupervised_mode forced human_required on a money actionG-TOOL-02
POL-DEFAULT-DENYno rule allows the action → denyG-POL-01
POL-CLOCK-UNKNOWNno verified regulatory_clock entry for the country → case opened, no deadline, routed to a person—
POL-QUEUE-TRANSITIONanalyst transition not listed in case_queue.transitions → denyG-POL-01
POL-CLOSE-HUMANclose requested by a non-human actor → denyG-POL-01
POL-REEVAL-WINDOWre-evaluation requested after reevaluation.window_days → deny; the agent offers a callG-POL-01

Customer tools

16 tools are the agent's only way to data; every write is read back before it counts as verified.

Read 10

Reads the customer's own data; changes nothing.

Act 2

The writes the graph's act node runs on a new dispute.

Follow up 3

Writes on a case that already exists.

Notify 1

Sends to a channel the customer confirmed.

View as table (Customer tools)
ToolKindPurposeVerified with
get_customer_profileReadFirst name, language, country, display currency, confirmed channels—
search_transactionReadFind the disputed charge (gold; plus demo_transactions in live)—
get_fraud_scoreReadThe bank's score with its source and version—
compute_deadlineReadLegal deadline for a new case, with source_url, verified_on and deadline_source_label in the session's language—
open_caseWriteOpen the caseget_case
block_cardWriteBlock the cardget_product_status
get_product_statusReadOne card: type, last 4, status, read_at—
list_my_cardsReadThe customer's cards with status—
get_caseReadCustomer view of a case: status label, stored deadlines with source, deadline_source_label in the session's language and deadline_verified_on, visible timeline, taken_by_person, related_case_id, read_at—
list_my_casesReadThe customer's cases—
add_case_infoWriteCustomer adds information to an active caseget_case
request_callWriteCustomer asks a person to callget_case
request_reevaluationWriteRe-evaluate a resolved case (→ review) or open a related case for a closed oneget_case
convert_amountReadAmount in the display currency, with rate, source and date—
send_case_summaryNotificationSend the receipt template to a confirmed channellist_my_notifications
list_my_notificationsReadNotifications with masked address and delivery status—

Guardrails

15 guardrails, each in code with a case in the evaluation set.

input

session

tools

policy

output

operations

View as table (Guardrails)
IdLayerGuardrailHowCited by
G-IN-01inputdirect and indirect prompt injectioncustomer text and tool outputs as delimited data; injection classifier (rules + LR) → human zonePOL-INJECTION
G-IN-02inputcustomer-invented dataamount/date/merchant only for searching; score, product and country come from goldPOL-ZONE-MISMATCH
G-IN-03inputlanguage and ambiguityES/PT detection with a threshold; low confidence → ask, then humanPOL-CLARIFY · POL-CLARIFY-EXHAUSTED
G-IN-04inputPII and out of scopePAN/CVV/password regex → reject and ask not to send it; topic outside disputes → abstainPOL-PII · POL-OUT-OF-SCOPE
G-SES-01sessionidentity and scopemock OTP TTL 15 min; customer_id only from the session; expired → no dataPOL-SESSION
G-SES-02sessionaccess to another customerthe tool filters by session; another customer's record answers NOT_FOUND, as an unknown id does, and is logged as a policy_denials row with POL-CROSS-CUSTOMER (D-052)POL-CROSS-CUSTOMER
G-TOOL-01toolsallowlist and strict schemasthe agent only sees customer tools; Pydantic rejects unexpected arguments; rate limit per session—
G-TOOL-02toolscontrolled writesapproval mode per action; idempotency key; mandatory post-condition; credit never autoPOL-AMOUNT-GATE · POL-AMOUNT-UNKNOWN · POL-SUPERVISED
G-POL-01policydefault deny and loggingversioned policies.yaml; every denial is a row in policy_denialsPOL-DEFAULT-DENY · POL-QUEUE-TRANSITION · POL-CLOSE-HUMAN · POL-REEVAL-WINDOW
G-OUT-01outputgroundingevery number, date, ID or status in the answer exists in a tool result or in the policy; otherwise it is dropped and logged—
G-OUT-02outputverified only'blocked' only when get_product_status == Blocked; 'case #' only when get_case returns the case_id with read_at—
G-OUT-03outputleaks of other customers' data and secretsoutput filter rejects IDs/amounts that are not from the session; never YAML or keys—
G-OUT-04outputtone and abstentionno promises of money or deadlines the policy did not give; explicit abstention—
G-OPS-01operationsbudget and retriestoken cap per conversation and per day, checked before calling; 2 retries; 800 ms timeout—
G-OPS-02operationsimmutable auditevery event with actor, trace_id and input hash; nothing is deleted—

Models and decision engines

Everything that understands, scores, decides, checks or advises, with its version.

Understand

Score

Decide

Check

Advise

View as table (Model inventory)
EngineKindVersionRoleSource
Policy engineRulespolicies.yaml v2Decides every action, default deny; the LLM never reads or edits it.contracts/policies.yaml · spec 02
Regulatory clockRules (data table)policies.yaml v2The legal deadline per country and product, each entry with source_url and verified_on; no entry → POL-CLOCK-UNKNOWN.contracts/policies.yaml regulatory_clock · ADR 0019
Fraud scoreBank's score (vendor)dataset · gold-v1Places the case in a zone; only the deciding sources below can.contracts/policies.yaml scoring
Intent classifier and injection rules (B0)Rulesb0-v1Language, intent, slots and the injection flag in the understand node; the graph loads arm B0.packages/nick_of_time/nlu/rules.py · spec 11
Intent classifier (B1)TF-IDF + logistic regressionb1-v1Learned arm measured by the spec 11 protocol; not loaded by the graph.packages/nick_of_time/nlu/learned.py · spec 11
LLM arm S1LLM · Amazon Bedrockus.anthropic.claude-haiku-4-5-20251001-v1:0Intent and slots below τ in a verified session when the run's arm is S1; also the demo persona's opening message.packages/nick_of_time/config · spec 15
LLM arm S2LLM · Amazon Bedrockus.anthropic.claude-sonnet-4-6The same step on the quality-ceiling model when the run's arm is S2.packages/nick_of_time/config · spec 15 §4.3
JudgeLLM · advisoryClaude Haiku 4.5 until the spec 15 benchmark picks the judge's modelA second opinion for the analyst on cases in review, every reason tied to evidence; never decides or changes state.packages/nick_of_time/audit/judge.py · spec 18 · spec 15 Q4
Outcome auditorDeterministic checksA1–A10Re-derives each run's decision, deadline, verified actions and facts from its records; findings go to audit_findings.packages/nick_of_time/audit · spec 18 §4.1
View as table (Score providers)
ProviderVersionCan place a zoneNote
datasetgold-v1yesreads transactions.fraud_score from gold for preset transactions; demo default
rulesrules-v0yesheuristic: amount vs the customer's p95, channel, hour, different country; no training
modelmodel-v0yesplan B: GBM/LR on transactions features against is_fraud, temporal held-out; only if Slack says the score is not available in real time
llmllm-v0no, zone humandemo illustration only; NEVER decides a block (zone forced to human when it is the source)
syntheticsynthetic-v0yeslive mode only: the score generated with a labeled synthetic transaction in demo_transactions (ADR 0020); never in replay, eval or a pitch number; shown as [simulated] on the receipt, handoff and console