Skip to main content
The clinician orders a service, a step EHRs call computerized provider order entry (CPOE). The agent searches your facility’s catalog of orderable services, selects the service, completes the order’s mandatory fields, and prepares the order for the clinician, who confirms before anything is placed. Reading existing orders is a different flow: use the ServiceRequest resource type of the tool in Retrieve patient data.
CPOE order lifecycle: the clinician asks to order, the agent searches the catalog, selects the service, completes the mandatory fields, and prepares the order. The clinician confirms before the order is placed.CPOE order lifecycle: the clinician asks to order, the agent searches the catalog, selects the service, completes the mandatory fields, and prepares the order. The clinician confirms before the order is placed.

The CPOE lifecycle: search, select, complete, and prepare. The clinician confirms before anything is placed.

This page builds on Build a schema tool, which explains the five fields of the connector body, 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 an orderId.
1

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:
The tools chain through the client. The agent calls the search, which emits a search request and returns no results inline. The client resolves the search against your catalog and returns the candidates, with the 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.
2

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.
3

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.
4

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:
This is where the two tools chain. The client resolves a selected service by matching on its 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.
5

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"]:
Required and nullable together means the agent always states 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 same connectors 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

Each item in 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.
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:
Add the rules every flow shares. Order is the flow likeliest to break the first of them, one tool call and never two: every call to 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.
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 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.
2. Select services into the order. The agent calls 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.
3. Complete the mandatory fields. The agent calls make_cpoe_order with action complete, supplying the mandatory values for each service on the order.
4. Prepare the order for review. The agent calls 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.
Two paths branch off the happy path. 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 same contextId. A task in input_required is 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. After select, 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 category enum with your own catalog’s top-level categories.
  • Do not hardcode mandatory properties such as priority in the schema. Discover them from the order when the agent performs complete.
  • Tune the keywords guidance in the search tool’s description and field description to how your catalog search tokenizes.
  • Edit both tools’ description prose to match how your clinicians ask for orders.
  • Keep the transitions: input_required on the search, so the client can return the candidates, and the complete transition on the order tool, so each action is one run and nothing is placed until the clinician confirms.