on_start- Before workflow execution beginson_end- After workflow execution completes
Child workflows and agents also have their own
on_start and on_end hooks.Defining hooks
Create hooks using the@hook decorator:
ctx-WorkflowContextwith execution metadatahook_context-HookContextwith current execution state- Returns -
HookResultindicating what action to take
Hook results
Hooks returnHookResult with three options:
1. Continue without changes
2. Continue with modifications
3. Fail and stop execution
Attaching hooks to workflows
Hook context
Hooks receiveHookContext with execution state:
Multiple hooks
Hooks run in order. If any hook fails, execution stops:validate_input_hook fails, redact_pii_hook and add_metadata_hook never run.