You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
0 commit comments