Commit 76b3eeb
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 <noreply@anthropic.com>1 parent 7c57af4 commit 76b3eeb
1 file changed
+42
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
125 | 167 | | |
126 | 168 | | |
127 | 169 | | |
| |||
0 commit comments