Workflows
Workflows are the orchestration layer of the Health AI Platform. In this repository, they are implemented by @loop/workflow-engine and defined as data rather than hard-coded business logic.
That gives the platform three useful properties:
- Repeatable - the same input context produces the same step execution pattern
- Inspectable - workflow definitions can be reviewed as YAML or JSON
- Composable - patient context, step results, and available tools are combined at runtime
What a workflow looks like
id: thyroid-assessment-v1
name: Thyroid Assessment
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: 200mcgWorkflow lifecycle
- Load a workflow definition
- Validate IDs, step types, and flow references
- Execute steps against a
WorkflowContext - Collect step results, recommendations, and errors
- Hand off outputs to downstream systems such as notifications, APIs, or agent responses
Runtime model
interface WorkflowContext {
patientId: string;
data?: Record<string, unknown>;
tools?: string[];
}interface WorkflowResult {
success: boolean;
workflowId: string;
executedSteps: string[];
stepResults: Record<string, StepResult>;
recommendations: Recommendation[];
errors: WorkflowError[];
}Example execution
import { WorkflowEngine } from '@loop/workflow-engine';
WorkflowEngine.load({
id: 'thyroid-assessment-v1',
name: 'Thyroid Assessment',
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' },
},
},
],
});
const result = await WorkflowEngine.execute('thyroid-assessment-v1', {
patientId: 'patient-42',
data: {
biomarker: { TSH: 4.2 },
medications: ['metformin'],
},
});