Drug-Safety Agent on Databricks · Desk and approval · Hand-offs
Hand-offs to a person
Several paths end with "a person will pick this up": the scientist asked for one, the loop ran out of steps, the model was unavailable, or a draft failed a check. Each is now recorded with a reason and a reference, the scientist is told the reference, and the case shows on the desk for a person to take.
| Why a person is asked | How it is recorded | In the specification? |
|---|---|---|
| The scientist asks for a person | asked-for-human | Yes |
| The loop used up its steps, money or time | loop-exhausted | Yes |
| The model was unavailable (for example a rate limit) | model-unavailable | No: a finding. The specification only names the budget cases. |
| The model answered but not with a valid draft | no-draft | No: a finding. |
| A number in the draft did not match the data | grounding-failed | No: a finding. |
Told once. The same reason for the same request is recorded once. Asking twice returns the same reference and says it is already with a person.
A retry that works closes the old hand-off. If a rate-limited case is run again and succeeds, the earlier hand-off is closed so a person is not left chasing a ghost.
Seen for real. When the weekly screen ran on a free model tier, some cases hit the provider's tokens-per-minute limit. They became hand-offs, not lost work, and the job's pause setting fixed the rest. The three reasons marked as findings are to be written back into the specification.
The real code
Cut from the repository each time this site is built, so it always matches what runs. Each header names the file and the line it was cut from.
src/drugsafety/entrypoint.py:74Which reason a failure is recorded underdef _reason_for(termination: str) -> str:
"""The AOAS names `loop-exhausted` for the budget terminations only; the other reasons are findings for the spec."""
if termination in LOOP_EXHAUSTED:
return "loop-exhausted"
return "model-unavailable" if "unavailable" in termination else "no-draft"src/drugsafety/store.py:158Recorded once per request and reason def escalate(self, reason: str, request: str, *, raised_by: str) -> tuple[str, bool]:
"""Record that a person is needed. The same reason for the same request is recorded once, so a person is told once
(P-ESC-ONCE). Returns (id, created)."""
eid = "ESC-" + hashlib.sha1(f"{reason}|{request}|{raised_by}".encode()).hexdigest()[:6].upper()
if self.db.execute("SELECT 1 FROM escalations WHERE id=?", (eid,)).fetchone():
return eid, False
self.db.execute(
"INSERT INTO escalations(id,reason,request,raised_by,created_at) VALUES (?,?,?,?,?)",
(eid, reason, request, raised_by, _now()),
)
self._audit(raised_by, "escalated", eid, reason)
self.db.commit()
return eid, True