Why contracts come first
The tools are the only way the advisory and documentation components can touch the clinical record. Their contracts are the stable layer: the Microsoft Foundry build and the LangGraph build both call the same operations, and the evaluation set checks the same arguments. A strict contract makes the system testable and limits what a manipulated model can do.
- Arguments are typed, bounded and validated by the clinical systems gateway, never trusted from the model.
- Every tool declares whether it changes anything, whether it is safe to retry and what scope it needs.
- AI-facing tools can read and propose. Signing a plan, confirming an excision and filing a note are acts of a named clinician.
- No tool, and no path from any tool, can send a command to the robot arms or the nanobots. The control system is not reachable from the AI side.
The tool catalogue
| Tool | Purpose | Changes data | Safe to retry | Scope | Needs approval |
|---|---|---|---|---|---|
| get_case_summary | Read case facts with identity masked | No | Yes | case.read | No |
| get_imaging_study | Read imaging pointers and metadata | No | Yes | imaging.read | No |
| get_pathology_result | Read margin status and orientation | No | Yes | pathology.read | No |
| get_reconciliation_status | Read nanobot counts and status | No | Yes | device.read | No |
| search_protocols | Retrieve protocols and instructions for use with citation and version | No | Yes | knowledge.read | No |
| propose_margin | Record an advisory margin outline with uncertainty | Yes, a proposal only | Yes, by key | margin.propose | The surgeon reviews and signs |
| draft_operative_note | Create a draft note from structured facts | Yes, a draft only | Yes, by key | note.draft | The surgeon signs before filing |
| draft_followup_tasks | Create follow-up task drafts | Yes, a draft only | Yes, by key | task.draft | The team confirms |
| draft_patient_summary | Create a plain-language summary draft | Yes, a draft only | Yes, by key | summary.draft | The clinician reviews before it is shared |
| file_note | File a note to the record | Yes | Yes, by key | note.file | Surgeon signature required; not callable by AI |
| sign_plan | Sign the plan and geofence | Yes | Yes, by key | plan.sign | Surgeon only; not callable by AI |
An operation, in OpenAPI
Proposing a margin is the most consequential AI-facing write, and it is only a proposal. The operation requires an idempotency key, model version, uncertainty and evidence, and refuses anything that looks like a device command.
openapi: 3.1.0
info: { title: Surgical planning tools, version: 1.2.0 }
paths:
/procedures/{procedure_id}/margin-proposals:
post:
operationId: propose_margin
summary: Record an advisory margin outline. A proposal only: it changes nothing and cannot be sent to any device.
parameters:
- { name: procedure_id, in: path, required: true, schema: { type: string } }
- { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 16 } }
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [model_version, outline, uncertainty, evidence]
properties:
model_version: { type: string }
outline: { type: array, description: Polygon in the study's coordinate frame, items: { type: array, items: { type: number } } }
uncertainty: { type: array, description: Per-vertex uncertainty in millimetres, items: { type: number, minimum: 0 } }
evidence: { type: array, description: Pointers to the images used, items: { type: string } }
responses:
"201": { description: Recorded as a proposal for the surgeon }
"200": { description: Same Idempotency-Key replayed; returns the original proposal }
"422": { description: Outline missing uncertainty, or an attempt to include device commands }
"403": { description: Caller scope failed }A read tool, as an MCP definition
The platform sees tools through the Model Context Protocol. The definition repeats the constraints that matter: required fields, an enumerated list of what to include, no identity and read-only hints.
{
"name": "get_pathology_result",
"description": "Read the margin result for a specimen, with orientation. Read only. No patient identity.",
"inputSchema": {
"type": "object",
"required": ["procedure_id"],
"properties": {
"procedure_id": { "type": "string" },
"include": { "type": "array", "maxItems": 3,
"items": { "enum": ["margin_status", "orientation", "closest_margin_mm"] } }
}
},
"annotations": { "readOnlyHint": true, "idempotentHint": true }
}Error model
| Code | Meaning | What the platform does |
|---|---|---|
| invalid_argument | A field failed validation | Route to a clinician with the reason; never retry unchanged |
| not_found | Case, study or result unknown | Check the identifier; do not guess |
| conflict | A plan or note already signed or filed | Re-read state; never overwrite a signed record |
| forbidden | Scope or signature check failed | Do not retry; route to a clinician; raise a security event |
| rate_limited | Too many calls | Back off, then queue |
| unavailable | Backend down or timed out | Retry once with the same key, then fall back to manual documentation |
Rules every tool follows
Idempotency
Every write takes an idempotency key. A replay returns the original result and never creates a second one.
Propose, never decide
AI-facing writes create proposals and drafts. Signing, confirming and filing are acts of a named clinician with strong authentication.
Uncertainty always
A proposal without a stated uncertainty and its evidence is refused.
Versioning
Contracts are versioned. A breaking change is a new major version, run side by side until the evaluation set passes on it.
Audit
Each call writes an audit record with the arguments hash, the caller, the model version, the outcome and the trace identifier.
Contract tests
- Every tool definition validates against the schema and has an owner, a scope and a retry rule.
- Property tests send out-of-range, oversized and malformed arguments and expect invalid_argument, never a partial write.
- A replay test sends each write twice with the same key and expects one result.
- A reachability test proves that no AI-facing credential or route can reach the control system or the nanobot unit.
- The Foundry build and the LangGraph build run the same contract suite against a mock backend.
Build this for your business
This example is speculative and not an approved device, but the same pattern, deterministic safety for every hard duty, a governed gateway, runtime security, advisory-only AI and measured quality, fits any safety-critical service. We can scope a pilot on your own systems.
Book a discovery call