Early Stopping
How to early stop workflows
Workflows support early termination when specific conditions are met, preventing unnecessary processing and implementing safety gates. Any step can trigger early termination by returning StepOutput(stop=True), immediately halting the entire workflow execution.
Example
1from kern.workflow import Step, Workflow, StepInput, StepOutput23def security_gate(step_input: StepInput) -> StepOutput:4 """Security gate that stops deployment if vulnerabilities found"""5 security_result = step_input.previous_step_content or ""6 7 if "VULNERABLE" in security_result.upper():8 return StepOutput(9 content="SECURITY ALERT: Critical vulnerabilities detected. Deployment blocked.",10 stop=True # Stop the entire workflow11 )12 else:13 return StepOutput(14 content="Security check passed. Proceeding with deployment...",15 stop=False16 )1718# Secure deployment pipeline19workflow = Workflow(20 name="Secure Deployment Pipeline",21 steps=[22 Step(name="Security Scan", agent=security_scanner),23 Step(name="Security Gate", executor=security_gate), # May stop here24 Step(name="Deploy Code", agent=code_deployer), # Only if secure25 Step(name="Setup Monitoring", agent=monitoring_agent), # Only if deployed26 ]27)2829# Test with vulnerable code - workflow stops at security gate30workflow.print_response("Scan this code: exec(input('Enter command: '))")