adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

with get_fast_api_app method agent running stops in between with error:Unclosed client session.

Open pavan-moe opened this issue 1 year ago • 4 comments

** Please make sure you read the contribution guide and file the issues in the right place. ** Contribution guide.

Describe the bug While using the FastAPI app, the requests stop suddenly, which is quite random. However, with ADK Web, it is running correctly.

INFO:google_genai.models:AFC is enabled with max remote calls: 10.
ERROR:asyncio: Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x16f898d10>
INFO:google_adk.google.adk.models.google_llm:Sending out request, model: gemini-2.5-flash, backend: GoogleLLMVariant.GEMINI_API, stream: True

This error is being thrown.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MAC OS 15.5
  • Python version(python -V): 3.12
  • ADK version(pip show google-adk):Name: google-adk Version: 1.13.0

Model Information: using 2.5-pro and 2.5-flash

from google.adk.cli.fast_api import get_fast_api_app
from config import config

agent_config = config.get_agent_config()
app = get_fast_api_app(
    agents_dir=agent_config["agents_dir"],
    session_service_uri=agent_config["session_service_uri"],
    allow_origins=["*"],
    web=agent_config["web"],
)

pavan-moe avatar Aug 31 '25 15:08 pavan-moe

I think this is happening due to mcp session : WARNING:google_adk.google.adk.tools.mcp_tool.mcp_session_manager:Error during disconnected session cleanup: Attempted to exit cancel scope in a different task than it was entered in

pavan-moe avatar Aug 31 '25 16:08 pavan-moe

Warning: Error during MCP session cleanup for session_d455dce1265f1d4431834ee0aa46db7c: Attempted to exit cancel scope in a different task than it was entered in

client_session: <aiohttp.client.ClientSession object at 0x16b6d1d30>
ERROR:asyncio:Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x16b51bf50>```

with adk web it is working fine only with get_fast_api_app implementation this is giving this error : and due to that app just stops.

pavan-moe avatar Sep 03 '25 19:09 pavan-moe

can you attach the agent.py file you used and instructions to reproduce the issue?

wukath avatar Nov 06 '25 18:11 wukath

Closing due to inactivity.

hangfei avatar Nov 11 '25 04:11 hangfei