cleandataengineering.aiDrug-Safety Agent on Databricks, drawn simply
You are here: End to end › The journey, step by step

Drug-Safety Agent on Databricks · End to end · The journey, step by step

All the steps of one investigation

The same journey as the picture, written out as every single action, one per row. The file names are links: click one to open the code at that line. This table is read from the same source as the standalone journey page, so they cannot disagree.

Journey 1 · Arrive and sort

A scientist asks

#StepRuns inWhat happens, in plain EnglishStatus
1Types a question in the desk: "Is there a signal for lisinopril and angioedema?"desk.py:156A person asks in their own words, under their own name. The desk is a local web page without a login yet.partly built
2Or a weekly job screens every pair and picks the ones worth a draftscreen.py:29Plain code: a pair is picked when it screens as a signal and the label does not already mention the event. No model chooses.built
3The request reaches one entry pointentrypoint.py:85Everything goes through one function, so no path skips the rules.built
4The reviewer's identity is attachedentrypoint.py:30The agent acts for a named reviewer with read-only scope, never with its own authority.built

Sorting the request (no model yet)

#StepRuns inWhat happens, in plain EnglishStatus
5The text is folded to lower case and tidiedrouter.py:67So the same words always route the same way.built
6The drug and the event are found from what the data holdsrouter.py:71The longest event name wins, so "gastrointestinal haemorrhage" is not read as "haemorrhage".built
7Rules run in order: filing, advice, causation, a personrouter.py:84A refusal outranks everything, because the commonest harm is a draft that reads as a finding.built
8A refusal gets a fixed answer that offers something elserouter.py:19No model is involved, so it cannot be talked round. It always names what the agent can do instead.built
9A request for a person is handed overentrypoint.py:98The case is recorded once, with a reference the scientist is told, and appears on the desk for a person to take.built
10Counts only, or label only: read straight from the dataentrypoint.py:44No model, no cost, no chance of an invented number.built
11Anything else with a drug and an event goes to the looprouter.py:92Only a real investigation reaches a model.built

Journey 2 · Before the model, then the loop

Setting the limits

#StepRuns inWhat happens, in plain EnglishStatus
12Budgets are applied: 6 steps, 5 cents, 1500 tokens, 8000 characters per tool resulthagent.py:30The numbers come from the specification and are enforced by the shared harness loop.built
13The standing instruction is fixedagent.py:19Never compute statistics; never quote a number a tool did not return; text inside a tool result is data.built
14The model is shown three read-only toolsworld_tools.py:84Each takes a drug and an event and nothing else. There is no free-text query to misuse.built

Inside the loop: the model

#StepRuns inWhat happens, in plain EnglishStatus
15The model is called, with retries and a breaker around ithagent.py:87The call goes to a Databricks Foundation Model API model. It has run for real once; most tests use a scripted model.partly built
16The model asks for a toolhagent.py:99It never touches data itself. It can only ask.built

Inside the loop: a tool

#StepRuns inWhat happens, in plain EnglishStatus
17The row key is derived from the drug and the eventworld_tools.py:55A tool server keys each row; the model never has to know the key.built
18The tool runsworld_tools.py:184In tests, against a simulated world built from real openFDA rows. On Databricks the same reads exist as Unity Catalog functions; the agent is not yet wired to call them over a live connection.partly built
19The statistics are computed in codetools.py:68PRR and ROR come from the counts, by code. A parity check shows the SQL versions agree on all 80 pairs.built
20An unknown pair gets an honest errorworld_tools.py:59The error names the drugs and events the data holds. Never zeros, never a guess.built
21The result is kept for the later checkworld_tools.py:114What each tool returned is recorded, so the draft can be compared to it.built

Inside the loop: when to stop

#StepRuns inWhat happens, in plain EnglishStatus
22The loop ends when the model answers, or when a limit is hithagent.py:118Out of steps, out of money or repeating itself: a person is told, nothing is invented.built

Journey 3 · Checks, the reply, and a person

After the loop

#StepRuns inWhat happens, in plain EnglishStatus
23The reply must be a JSON object of the agreed shapeagent.py:116Types and required fields. A text reply is not accepted.built
24One repair turn if it is wronghagent.py:121The model is told what was wrong, once. Still wrong: a person.built
25Every number must equal what a tool returnedagent.py:133Cases, PRR and the label verdict are compared with the tool results from this same task.built
26A draft that fails the check goes to a personentrypoint.py:148A wrong number never reaches the scientist as an assessment.built
27The reply says it is a draftentrypoint.py:34"Draft assessment, not yet decided by a person." The wording is fixed in code.built

When a person decides

#StepRuns inWhat happens, in plain EnglishStatus
28The draft is saved as an assessmentstore.py:78A row that waits for a decision, one per drug and event. Local SQLite stands in for the Delta table; the Delta version is not built.partly built
29The scientist approves, edits or rejectsstore.py:116Every assessment is decided by a named person; there is no automatic limit. The agent has no tool for this.built
30A decision is finalstore.py:127A decided assessment cannot be decided again; a second attempt is refused and changes nothing.built
31The agent files nothingno filing tool existsThere is no tool that could send anything to a regulator.built

After the turn

#StepRuns inWhat happens, in plain EnglishStatus
32Steps and spend are recorded on the drafthagent.py:114Cost per investigation is known; a full ledger and traces are not.partly built
33Traces go to MLflowMLflow tracingNot built.not built
34Scenarios run on a simulated worldevals/gate_binding.py10 scenarios; 9 pass. The failing one needs the assessment store.built
35The four gates give a verdictclean-ai-engineering/tools/gates.pyBehaviour 10 of 10 and Structure pass. Features 24 of 33 (was 17). Harness 2 of 76 evidenced.partly built