Commit d300cbb
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 <[email protected]>1 parent 0e61987 commit d300cbb
1 file changed
+99
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
200 | 201 | | |
201 | 202 | | |
202 | 203 | | |
| |||
213 | 214 | | |
214 | 215 | | |
215 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
| |||
229 | 234 | | |
230 | 235 | | |
231 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
232 | 245 | | |
233 | 246 | | |
234 | 247 | | |
| |||
244 | 257 | | |
245 | 258 | | |
246 | 259 | | |
247 | | - | |
| 260 | + | |
248 | 261 | | |
249 | 262 | | |
250 | 263 | | |
| |||
339 | 352 | | |
340 | 353 | | |
341 | 354 | | |
342 | | - | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
343 | 380 | | |
344 | 381 | | |
345 | 382 | | |
| |||
751 | 788 | | |
752 | 789 | | |
753 | 790 | | |
| 791 | + | |
754 | 792 | | |
755 | 793 | | |
756 | 794 | | |
| |||
930 | 968 | | |
931 | 969 | | |
932 | 970 | | |
933 | | - | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
934 | 1030 | | |
935 | 1031 | | |
936 | 1032 | | |
| |||
0 commit comments