Clean up resources, especially the HTTP client if owned by this agent.
(self)
| 817 | yield |
| 818 | |
| 819 | async def cleanup(self) -> None: |
| 820 | """Clean up resources, especially the HTTP client if owned by this agent.""" |
| 821 | if self._httpx_client_needs_cleanup and self._httpx_client: |
| 822 | try: |
| 823 | await self._httpx_client.aclose() |
| 824 | logger.debug("Closed HTTP client for agent %s", self.name) |
| 825 | except Exception as e: |
| 826 | logger.warning( |
| 827 | "Failed to close HTTP client for agent %s: %s", |
| 828 | self.name, |
| 829 | e, |
| 830 | ) |
| 831 | finally: |
| 832 | self._httpx_client = None |