Build Your First Workflow
This tutorial walks through the smallest useful platform flow:
- Define a workflow
- Load it with
WorkflowEngine - Execute it with patient context
- Inspect the result
Step 1: Define the workflow
id: first-thyroid-workflow-v1
name: First Thyroid Workflow
version: 1.0.0
steps:
- id: check-tsh
type: check_biomarker
action:
type: check_value
params:
biomarker: TSH
threshold: 2.5
operator: ">"
- id: recommend-selenium
type: recommend_supplement
condition: "check-tsh.result === true"
action:
type: recommend
params:
supplement: Selenium
dosage: 200mcgStep 2: Load the workflow
import { WorkflowEngine } from '@loop/workflow-engine';
const workflow = WorkflowEngine.load(`
id: first-thyroid-workflow-v1
name: First Thyroid Workflow
version: 1.0.0
steps:
- id: check-tsh
type: check_biomarker
action:
type: check_value
params:
biomarker: TSH
threshold: 2.5
operator: ">"
- id: recommend-selenium
type: recommend_supplement
condition: "check-tsh.result === true"
action:
type: recommend
params:
supplement: Selenium
dosage: 200mcg
`);Step 3: Execute with context
const result = await workflow.execute({
patientId: 'patient-42',
data: {
biomarker: { TSH: 4.2 },
},
});Step 4: Inspect output
console.log(result.executedSteps);
console.log(result.recommendations);Example output:
{
"executedSteps": ["check-tsh", "recommend-selenium"],
"recommendations": [
{
"type": "supplement",
"details": {
"supplement": "Selenium",
"dosage": "200mcg"
}
}
]
}Step 5: Test the negative branch
const result = await workflow.execute({
patientId: 'patient-42',
data: {
biomarker: { TSH: 1.9 },
},
});
console.log(result.stepResults['recommend-selenium']?.result);
// "skipped"Why this workflow is a good first example
- It uses a real built-in step type
- It shows a prior-step condition
- It produces a concrete recommendation
- It is easy to test and reason about
Next steps
- Expand the context with Patient Graph Workflow Guide
- Add tests with Testing Workflows
- Keep the field list handy in DSL Reference