Service coordination manages dependencies and interactions across a multi-step service pipeline, keeping application logic focused on business behavior while infrastructure handles recovery, retries, state, and observability. section 2.1.7 section 1.3
A coordinated patient-intake workflow can:
- Create or retrieve a session and conversation history. section 2.1.7
- Validate input before processing and validate generated output before delivery. section 2.1.7
- Retrieve clinic policies, generate a response with registered tools, and execute requested tool calls. section 2.1.7
- Retry failed services, handle flagged responses, preserve workflow state, and expose step-level timing, failures, and cost. section 2.1.7
Patient-intake coordination
A patient question passes through input safety checks, session retrieval, knowledge-base search, model generation, tool execution, output validation, and persistence. A workflow decorator turns this sequence into a managed process, so a knowledge-base timeout can trigger an automatic retry and a flagged response can be sanitized or regenerated. section 2.1.7
Listing 2.9 Multi-step workflow coordinating all platform services
@workflow(name="patient_intake") #A
def handle_patient_question( #A
question, #A
patient_id, #A
session_id #A
): #A
session = platform.sessions.get_or_create( #B
patient_id, session_id #B
) #B
safety_check = platform.guardrails.validate_input( #C
question, #C
checks=["no_medical_advice"] #C
) #C
if not safety_check["allowed"]: #C
return {"response": safety_check["denial_reason"]} #C
prompt = platform.models.get_prompt("patient_intake") #D
conversation_history, _ = platform.sessions.get_messages( #D
session_id, limit=10 #D
) #D
history_messages = [ #D
{"role": m.role, "content": m.content} #D
for m in conversation_history #D
] #D
relevant_info = platform.data.search( #E
query=question, #E
index_name="patient_procedures" #E
) #E
policy_text = "\n".join( #E
r.text for r in relevant_info #E
) #E
messages = history_messages + [ #F
{"role": "system", "content": prompt["content"]}, #F
{"role": "system", #F
"content": f"Relevant clinic policies:\n{policy_text}"}, #F
{"role": "user", "content": question} #F
] #F
tools, _ = platform.tools.build_model_tools( #G
names=["appointment_scheduler"] #G
) #G
response = platform.models.chat( #G
messages=messages, #G
model="gpt-4o", #G
tools=tools #G
) #G
if response.tool_calls: #H
for tool_call in response.tool_calls: #H
result = platform.tools.execute( #H
tool_call["function"]["name"], #H
arguments=json.loads(
tool_call["function"]["arguments"]) #H
) #H
messages.append({ #H
"role": "tool", #H
"content": str(result.result), #H
"tool_call_id": tool_call["id"] #H
}) #H
response = platform.models.chat( #H
messages=messages,
model="gpt-4o"
) #H
output_check = platform.guardrails.filter_output( #I
response.content, #I
filters=[ #I
"no_medical_advice", #I
"pii_redaction" #I
] #I
) #I
platform.sessions.add_messages( #J
session_id, #J
[{"role": "user", "content": question}, #J
{"role": "assistant", #J
"content": output_check["content"]}] #J
) #J
return {
"response": output_check["content"],
"sources": [r.document_id for r in relevant_info]
}Inspect the workflow interface that connects sessions, guardrails, prompts, data retrieval, model calls, tools, and persistence. section 2.1.7
