Skip to content

Commit 2345c4c

Browse files
committed
refactor: update use of AsyncExitStack in Agent
1 parent 5608a0d commit 2345c4c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pydantic_ai_slim/pydantic_ai/agent.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,9 +1792,11 @@ async def __aenter__(self) -> Self:
17921792
"""
17931793
async with self._enter_lock:
17941794
if self._entered_count == 0:
1795-
self._exit_stack = AsyncExitStack()
1796-
toolset = self._get_toolset()
1797-
await self._exit_stack.enter_async_context(toolset)
1795+
async with AsyncExitStack() as exit_stack:
1796+
toolset = self._get_toolset()
1797+
await exit_stack.enter_async_context(toolset)
1798+
1799+
self._exit_stack = exit_stack.pop_all()
17981800
self._entered_count += 1
17991801
return self
18001802

0 commit comments

Comments
 (0)