Repository navigation
Closed
Labels
live[Component] This issue is related to live, voice and video chat[Component] This issue is related to live, voice and video chat
Description
async for event in runner.run_async(
user_id=user_id,
session_id=session_id,
new_message=new_message,
state_delta=state_delta,
run_config=run_config, # Stream=True模式
):
if some_condition:
return None`
Problem: When the runner's events are not fully iterated (ending prematurely), it can cause a leak in the LLM request connection. Below is the test code based on LiteLLM. This code is consistent with the streaming output invocation method currently used in the ADK↓↓↓
async def test_acompletion_resource_cleanup(end):
# Make an async completion call
cnt = 1
async for el in await litellm.acompletion(
model="deepseek/deepseek-chat",
api_key="...",
base_url="https://api.deepseek.com/v1",
messages=[
{
"role": "user",
"content": "一次不差的复述下下方短文内容:在这个信息爆炸的时代,静下心来读一本书,成了一种奢侈。手机、社交媒体、短视频接连不断地抢占我们的注意力,使我们越来越难以集中精力去做一件事情。很多人开始感到焦虑,仿佛每天都很忙,却不知忙了些什么。其实,我们真正需要的,是一种“慢下来”的勇气。在快节奏的生活中,抽出时间去散步、阅读、与亲人交流,这些看似平凡的小事,恰恰是我们获得内心安宁的关键。当我们暂时放下外界的喧嚣,才更容易听见内心的声音。慢,不是懒惰,而是一种自我掌控的表现。它让我们重新掌握生活的节奏,不再被外界牵着走。因此,学会在忙碌中寻找片刻的安静,是每个人都该修炼的生活智慧。",
}
],
stream=True,
):
print(f"{end} {el}")
if end:
cnt += 1
if cnt > 3:
break
# await litellm.close_litellm_async_clients()
# lsof -i @api.deepseek.com | grep -c "https"
async def main():
# Run the test
"""
await test_acompletion_resource_cleanup(True)
await test_acompletion_resource_cleanup(False)
print("✅ All tests passed!")
"""
# Run the tests concurrently
await asyncio.gather(
test_acompletion_resource_cleanup(True),
test_acompletion_resource_cleanup(False)
)
print("✅ All tests passed!")
if __name__ == "__main__":
asyncio.run(main())
Here's a personal perspective:
When adk calls lite_llm and obtains a CustomStreamWrapper, if it returns prematurely, the CustomStreamWrapper cannot correctly execute the final release logic because it lacks aclose and aexit methods—it relies on anext for this purpose.
如果你遇到AttributeError: 'Choices'对象没有'logprobs'属性的错误,可以修改代码为逐个使用await,避免使用gather。
Metadata
Metadata
Assignees
Labels
live[Component] This issue is related to live, voice and video chat[Component] This issue is related to live, voice and video chat
Activity
[-]connect leak[/-][+] leak problem[/+]growmuye commentedon Jul 24, 2025
@hangfei
Hello, the context for my question is that I have a task with a lengthy automated process that outputs critical information to users. Users can STOP at any time or chat with the AI after stopping and then resume the AI's work. I want to achieve this functionality with just one STOP capability, similar to most LLM software, especially in stream mode.
Is there any plan for the ADK to support a "stop" feature? Below is my temporary implementation, but I'm unsure if there are any HTTP leakage issues, even after reviewing the code and consulting DeepWiki (ADK and LiteLLM).
adk version=1.5.0