Commit 95d9952
feat: add to_state() method to RunResult for resuming runs
This commit adds a method to convert a RunResult back into a RunState,
enabling the resume workflow for interrupted runs.
**Changes:**
1. **to_state() Method** (result.py:125-165)
- Added method to RunResult class
- Creates a new RunState from the result's data
- Populates generated_items, model_responses, and guardrail results
- Includes comprehensive docstring with usage example
**How to Use:**
```python
# Run agent until it needs approval
result = await Runner.run(agent, "Use the delete_file tool")
if result.interruptions:
# Convert result to state
state = result.to_state()
# Approve the tool call
state.approve(result.interruptions[0])
# Resume the run
result = await Runner.run(agent, state)
```
**Complete HITL Flow:**
1. Run agent with tool that needs_approval=True
2. Run pauses, returns RunResult with interruptions
3. User calls result.to_state() to get RunState
4. User calls state.approve() or state.reject()
5. User passes state back to Runner.run() to resume
6. Run continues from where it left off
**Remaining Work:**
- Add comprehensive tests
- Create example demonstrating HITL
- Add documentation
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent d7136af commit 95d9952
1 file changed
+42
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
178 | 220 | | |
179 | 221 | | |
180 | 222 | | |
| |||
0 commit comments