ServiceRequest resource type of the tool in Retrieve patient data.
The CPOE lifecycle: search, select, complete, and prepare. The clinician confirms before anything is placed.
additionalProperties: false, required, const, enum, transition, and how to attach a tool to your agent. What is new here: two tools that chain through the client, anyOf branches tagged by an action field, values that are both required and nullable, and a search that ends in input_required followed by an order tool that ends in complete.
Build the order tools
The target: the clinician asks for a CRP, and the agent searches the catalog, adds C-Reactive Protein to an order, fills the order’s mandatory fields, and prepares the order for the clinician to review. Ordering works against one order, identified by anorderId.
Split the job into two tools that chain
search_cpoe_catalog finds candidate services in the catalog, and make_cpoe_order acts on the order. Each is a complete schema tool with its own transition:orderId, in a new message on the same contextId, as described in Send a message to an agent. The agent then calls make_cpoe_order with fields copied from those candidates.The transition is declared per connector, not per action. So every call to make_cpoe_order ends the run, select included, and the client sends a new message to start the run that performs the next action.Put the rule for a field in its description
The search schema is a
requests array, one entry per distinct service the clinician asked for. A description can sit on any property, not only on the tool, and the model reads it when it fills that field:orderId is not in required, so its description carries the rule for when to send it. minItems: 1 on both requests and keywords means every search carries at least one entry, and every entry at least one term.Give each action its own shape, tagged by action
The order schema is an
items array, and each item is one of five actions: select, complete, prepare-for-review, remove, or cancel. The actions carry different fields, so items is an anyOf with one closed branch per action. Each branch requires an action field pinned by a one-value enum, which tells the client which branch an item matched:anyOf checks each item on its own, so the schema cannot require that all items in one call share one action. That rule goes in the tool’s description instead: “All items in a single call must be the same action.”The complete action fills the order’s mandatory fields. It is unrelated to the complete transition, which ends the run after every action.Copy service fields from the search response
select and remove carry a services array, and every field in it comes from the search response. The agent does not compose them:id, not on the title, which is carried for traceability only. code pairs the service’s code with the system it belongs to. category is example vocabulary: yours would be your own catalog’s top-level split. sourceSystem names the back-end system that holds the catalog entry, such as central-lab, and the client uses it to look the service up.Require every key, and allow null
complete carries a values array, one entry per mandatory field value. All four keys are required, and two of them accept null through the type ["string", "null"]:serviceId and targetId, either with a value or with an explicit null. The client never has to guess whether a missing key means “empty” or “forgotten”. serviceId is the id of a service already on the order. title in services[] follows the same required-and-nullable pattern.The full bodies
Attach both schema tools to one agent, in the sameconnectors array. Order needs no registry connector, so the array holds only these two bodies. Attach it with the coding connector shows the connectors array and where to send it.
The search tool
* Differs slightly from FHIR R4, where a simpler field is easier for the agent to fill.
The order tool
items is one of five actions against the shared orderId. All items in a single call must share one action. The happy path is select, then complete, then prepare-for-review. remove and cancel handle changes and abandonment.
Service and value fields
Service and value fields
Each service in
services[], for select and remove. All five fields are copied from the search response.Each value in
values[], for complete:* Differs slightly from FHIR R4, where a simpler field is easier for the agent to fill.
Point the system prompt at the tools
The schema tools define what the agent can emit. The system prompt routes each request to the right tool and carries the lifecycle. This is the minimal prompt for order:make_cpoe_order ends the run, so the agent must not mix actions, or skip ahead, within one call’s items. If the agent stalls mid-lifecycle, check that the client sends the next message after each action before adding prompt rules.
Run it: flow, example, and the client's apply-step
Run it: flow, example, and the client's apply-step
A clinician asks for a CRP. The agent walks the order through its lifecycle: search the catalog, select services, complete their mandatory fields, and prepare the order for the clinician to review. The system prompt and the two tools’ descriptions produce this sequence. Each step below is one run: the call ends the run, and the client sends the next message.1. Search the catalog. The agent calls 2. Select services into the order. The agent calls 3. Complete the mandatory fields. The agent calls 4. Prepare the order for review. The agent calls Two paths branch off the happy path.
search_cpoe_catalog with one entry per distinct service, each with short lowercase keywords. This is a new order, so the entry has no orderId. The transition is input_required, and the client returns the candidates, with the orderId, in the next message.make_cpoe_order with action select: the item lists each chosen service in services[], with the identifying fields copied from the search response, and carries the orderId returned with the search results.make_cpoe_order with action complete, supplying the mandatory values for each service on the order.make_cpoe_order with action prepare-for-review. This is the terminal action: it hands the finished order to the clinician, who reviews it, confirms, and places it. The agent places nothing.remove takes services back out of an active order when the clinician changes their mind before completion. cancel abandons the order altogether. Both are single actions against the same orderId, and both end the run.The client owns the apply-step at every point where the agent stops:- After the search, the client resolves the keywords against your catalog and returns the candidates, with the
orderId, in a new message on the samecontextId. A task ininput_requiredis not finished: the new message resumes it, as described in Task lifecycle. - After each order action, the client applies the action to the order, resolving each selected service by its
id, and sends the next message. Afterselect, that message lists the order’s mandatory properties still to fill. The run that message starts performs the next action. - After
prepare-for-review, the client shows the finished order for review, and places it through your order system only when the clinician confirms.
Adapt it
- Replace the
categoryenum with your own catalog’s top-level categories. - Do not hardcode mandatory properties such as
priorityin the schema. Discover them from the order when the agent performscomplete. - Tune the
keywordsguidance in the search tool’sdescriptionand field description to how your catalog search tokenizes. - Edit both tools’
descriptionprose to match how your clinicians ask for orders. - Keep the transitions:
input_requiredon the search, so the client can return the candidates, and thecompletetransition on the order tool, so each action is one run and nothing is placed until the clinician confirms.