Why Use Interrupts
Interrupts are essential for:- Human approval: Review agent actions before execution
- Input collection: Gather additional information from users
- Quality control: Verify outputs before continuing
- Safety: Prevent unwanted actions in production
- Debugging: Inspect state at specific points
Basic Interrupts
Interrupt Before Nodes
Pause before executing specific nodes:Interrupt After Nodes
Pause after executing specific nodes:Interrupt on All Nodes
Pause at every node for debugging:Reviewing State
Inspect state when interrupted:Modifying State
Update state before resuming:Manual Interrupt
Trigger interrupts programmatically from nodes:Common Patterns
Tool Approval
Review tool calls before execution:Multi-Step Approval
Require approval at multiple stages:Edit and Resume
Edit agent output before continuing:Conditional Interrupts
Only interrupt when certain conditions are met:Dynamic Interrupts with Command
UseCommand for advanced control:
Streaming with Interrupts
Handle interrupts during streaming:Timeout Handling
Implement timeouts for human input:Best Practices
- Use checkpointers: Interrupts require a checkpointer to save state
- Clear communication: Provide context about why the interrupt occurred
- Validate input: Check user input before resuming
- Handle rejection: Have fallback logic when approval is denied
- Test interrupt paths: Verify behavior when interrupted and resumed
- Document interrupt points: Make it clear where interrupts can occur
- Implement timeouts: Don’t wait indefinitely for human input
- Log interrupts: Track when and why interrupts happen
Debugging Interrupts
Trace interrupt behavior:Next Steps
- Learn about Deployment for production interrupt handling
- Explore Debugging to trace interrupt behavior
- Review Persistence for managing interrupted states