Interrupt Hook#
Overview#
InterruptHook provides timeout and step limit controls for workflow execution, enabling automatic termination based on time or step count.
Its key features include:
Timeout Control
Timeout Monitoring:
Thread(target=monitor_executor, daemon=True)- Background timeout monitoringAutomatic Termination:
self.event.set()- Sets interrupt event on timeoutTermination Reason:
data.termination_reason = f"Timeout {self.timeout}s reached"
Step Limit Control
Step Counting:
len(data.history) > self.max_steps- Monitors step countMax Steps Enforcement: Terminates workflow when step limit exceeded
Step Validation: Validates step count against configured maximum
Exception Handling
LLM API Errors:
isinstance(data.last_exception, LLMAPIError)Context Length:
isinstance(data.last_exception, LLMMaxContextLengthExceeded)User Interruption:
isinstance(data.last_exception, LLMInterrupted)
Configuration#
This hook launches a background thread to monitor the execution time and step count. Users can configure the following parameters to control the behavior of the hook:
Timeout:
timeout: Optional[int]- Maximum execution time in secondsMax Steps:
max_steps: Optional[int]- Maximum number of workflow steps