RongJie G 94110e5dce
fix(subagents): close stream before releasing resources (#5221)
Co-authored-by: CorgiBoyG <CorgiBoyG@users.noreply.github.com>
2026-09-18 14:23:06 +08:00

15 lines
365 B
Python

from __future__ import annotations
import inspect
from typing import Any
async def close_agent_stream(stream: Any) -> None:
"""Close an agent stream when its runtime exposes asynchronous cleanup."""
close = getattr(stream, "aclose", None)
if close is None:
return
result = close()
if inspect.isawaitable(result):
await result