Skip to Content

Workflow Examples

This page shows complete workflow definitions you can adapt. Every example uses step types and condition syntax that exist in @loop/workflow-engine today.

Example 1: Thyroid review

This is the smallest useful workflow: check a biomarker, then add a recommendation when the condition is met.

id: thyroid-review-v1 name: Thyroid Review version: 1.0.0 triggers: - type: biomarker_result params: biomarker: TSH 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

Run it with patient data:

import { WorkflowEngine } from '@loop/workflow-engine'; const workflow = WorkflowEngine.load(thyroidYaml); const result = await workflow.execute({ patientId: 'patient-42', data: { biomarker: { TSH: 4.2, }, }, }); console.log(result.recommendations);

Example 2: Contraindication-aware recommendation

This flow checks a biomarker first, then inspects current medications before allowing a recommendation.

id: vitamin-k-review-v1 name: Vitamin K Review version: 1.0.0 steps: - id: check-inflammation type: check_biomarker action: type: check_value params: biomarker: hsCRP threshold: 1.0 operator: ">" - id: check-warfarin type: check_contraindication condition: "check-inflammation.result === true" action: type: check params: medication: warfarin supplement: Vitamin K - id: recommend-vitamin-k type: recommend_supplement condition: "check-warfarin.result.hasContraindication === false" action: type: recommend params: supplement: Vitamin K dosage: 100mcg

Example context:

const result = await workflow.execute({ patientId: 'patient-99', data: { biomarker: { hsCRP: 2.1 }, medications: ['metformin'], }, });

Example 3: Branching with next

By default, the engine walks steps sequentially. Use next when you want a non-linear flow.

id: follow-up-routing-v1 name: Follow-Up Routing version: 1.0.0 steps: - id: check-glucose type: check_biomarker next: notify-patient action: type: check_value params: biomarker: fastingGlucose threshold: 100 operator: ">" - id: order-a1c type: order_lab action: type: order params: test: a1c priority: normal - id: notify-patient type: send_notification action: type: notify params: channel: email message: "Your glucose review is ready."

In this definition, check-glucose routes directly to notify-patient, skipping order-a1c.

Example 4: Tool-eligible workflow

run_tool is useful when a workflow needs a named capability, but the current executor returns a stubbed result. This is best used to prove the contract and reserve a stable tool ID.

id: risk-evaluation-v1 name: Risk Evaluation version: 1.0.0 steps: - id: invoke-risk-tool type: run_tool action: type: tool params: toolId: risk-calculator labPanel: advanced-metabolic

Execution context:

const result = await workflow.execute({ patientId: 'patient-101', tools: ['risk-calculator'], });

Current output shape:

{ "executed": true, "toolId": "risk-calculator", "params": { "toolId": "risk-calculator", "labPanel": "advanced-metabolic" } }

Example 5: Scheduled workflow

Triggers are declarative metadata and can be used by an external scheduler or orchestration layer.

id: quarterly-labs-v1 name: Quarterly Labs Reminder version: 1.0.0 triggers: - type: schedule params: cron: "0 9 1 */3 *" steps: - id: order-panel type: order_lab action: type: order params: test: comprehensive_metabolic_panel priority: normal - id: notify-patient type: send_notification action: type: notify params: channel: email message: "Your quarterly lab panel is ready to order."

Picking the right pattern

NeedPattern
Threshold checkcheck_biomarker
Recommendation outputrecommend_supplement
Operational next steporder_lab or send_notification
Medication gatecheck_contraindication
Future external capabilityrun_tool

Next steps