Commit 0928afa
feat: integrate HITL approval checking into run execution loop
This commit integrates the human-in-the-loop infrastructure into the
actual run execution flow, making tool approval functional.
**Changes:**
1. **NextStepInterruption Type** (_run_impl.py:205-210)
- Added NextStepInterruption dataclass
- Includes interruptions list (ToolApprovalItems)
- Added to NextStep union type
2. **ProcessedResponse Enhancement** (_run_impl.py:167-192)
- Added interruptions field
- Added has_interruptions() method
3. **Tool Approval Checking** (_run_impl.py:773-848)
- Check needs_approval before tool execution
- Support dynamic approval functions
- If approval needed:
* Check approval status via context
* If None: Create ToolApprovalItem, return for interruption
* If False: Return rejection message
* If True: Continue with execution
4. **Interruption Handling** (_run_impl.py:311-333)
- After tool execution, check for ToolApprovalItems
- If found, create NextStepInterruption and return immediately
- Prevents execution of remaining tools when approval pending
**Flow:**
Tool Call → Check needs_approval → Check approval status →
If None: Create interruption, pause run →
User approves/rejects → Resume run →
If approved: Execute tool
If rejected: Return rejection message
**Remaining Work:**
- Update Runner.run() to accept RunState
- Handle interruptions in result creation
- Add tests
- Add documentation/examples
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 2925b42 commit 0928afa
1 file changed
+99
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
| 175 | + | |
175 | 176 | | |
176 | 177 | | |
177 | 178 | | |
| |||
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
189 | 194 | | |
190 | 195 | | |
191 | 196 | | |
| |||
202 | 207 | | |
203 | 208 | | |
204 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
205 | 218 | | |
206 | 219 | | |
207 | 220 | | |
| |||
217 | 230 | | |
218 | 231 | | |
219 | 232 | | |
220 | | - | |
| 233 | + | |
221 | 234 | | |
222 | 235 | | |
223 | 236 | | |
| |||
295 | 308 | | |
296 | 309 | | |
297 | 310 | | |
298 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
299 | 336 | | |
300 | 337 | | |
301 | 338 | | |
| |||
583 | 620 | | |
584 | 621 | | |
585 | 622 | | |
| 623 | + | |
586 | 624 | | |
587 | 625 | | |
588 | 626 | | |
| |||
762 | 800 | | |
763 | 801 | | |
764 | 802 | | |
765 | | - | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
766 | 862 | | |
767 | 863 | | |
768 | 864 | | |
| |||
0 commit comments