Using get_fast_api_app to run my agents here it throws ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x16b6d1d30> ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x16b51bf50> #2840
Replies: 2 comments 1 reply
-
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: The Hello! Thank you for your question. The The While You can achieve this by creating an instance of your Here is an example of how you can modify your main application file: import asyncio
from fastapi import FastAPI
from google.adk.cli.fast_api import get_fast_api_app
from google.adk.tools.mcp_tool import McpToolset, SseConnectionParams
# 1. Create your McpToolset instance
# Replace with your actual connection parameters
mcp_toolset = McpToolset(
connection_params=SseConnectionParams(
url="http://localhost:8080/mcp",
# Add other necessary parameters here
)
)
# 2. Get the FastAPI app from ADK
# Make sure your agent is configured to use the 'mcp_toolset' instance
app: FastAPI = get_fast_api_app(
agents_dir="./agents",
# ... other parameters
)
# 3. Add a shutdown event handler to close the toolset
@app.on_event("shutdown")
async def shutdown_event():
print("Shutting down and closing MCP toolset...")
await mcp_toolset.close()
print("MCP toolset closed.")
# In your agent definition, you would pass the created toolset:
#
# from my_app import mcp_toolset
#
# root_agent = Agent(
# ...,
# tools=[mcp_toolset]
# ) By implementing this shutdown hook, you ensure that the Let me know if you have any other questions! [1] |
Beta Was this translation helpful? Give feedback.
-
i have commented out MCP related stuff and still it is throwing the same error. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Using get_fast_api_app to run my agents here it throws ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x16b6d1d30> ERROR:asyncio:Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x16b51bf50>
While the same code works perfectly with ADK Web, it throws errors when using get_fast_api_app, causing the agent execution to stop unexpectedly. Is there a workaround for this? This is happening so frequently, like more than 80% of the time, and I am using the MCP toolset with SSE.
Beta Was this translation helpful? Give feedback.
All reactions