Describe the bug
Agent objects accumulate in memory during long-running workflows because RunItem objects hold strong references that are never released.
Debug information
- Agents SDK version: v0.6.4
- Python version: Python 3.12
Repro steps
Run an agent multiple times in a loop. Agent objects accumulate in memory instead of being garbage collected.
In src/agents/run.py (line 774), lists are cleared without releasing agent references:
turn_result.pre_step_items.clear()
turn_result.new_step_items.clear()
The SDK has a release_agent() method for this, but it's never called.
Expected behavior
Memory should stay constant across multiple runs, not grow indefinitely.
Describe the bug
Agent objects accumulate in memory during long-running workflows because
RunItemobjects hold strong references that are never released.Debug information
Repro steps
Run an agent multiple times in a loop. Agent objects accumulate in memory instead of being garbage collected.
In
src/agents/run.py(line 774), lists are cleared without releasing agent references:turn_result.pre_step_items.clear()
turn_result.new_step_items.clear()
The SDK has a release_agent() method for this, but it's never called.
Expected behavior
Memory should stay constant across multiple runs, not grow indefinitely.