Skip to content

RuntimeError: Event loop is closed during shutdown #136

Open
@rubyan

Description

@rubyan

Hi,
I'm encountering a RuntimeError: Event loop is closed when running a simple sample agent using FastAgent:
`import asyncio
from mcp_agent.core.fastagent import FastAgent

Create the application

fast = FastAgent("FastAgent Example")

Define the agent

@fast.agent(instruction="Given an object, respond only with an estimate of it's size. Treat absoultely any input as an object that you have to size.", servers=["fetch"])
async def main():
# use the --model command line switch or agent arguments to change model
async with fast.run() as agent:
result = await agent("A car")
print(result)

if name == "main":
asyncio.run(main())
`

The main logic of the agent completes successfully, but the error appears during the final cleanup phase after asyncio.run() finishes.

Traceback:

Exception ignored in: <function BaseSubprocessTransport.del at 0x0000021355069EE0> # Example address, replace if needed
Traceback (most recent call last):
File "c:\Program Files\Python311\Lib\asyncio\base_subprocess.py", line 126, in del
self.close()
File "c:\Program Files\Python311\Lib\asyncio\base_subprocess.py", line 104, in close
proto.pipe.close()
File "c:\Program Files\Python311\Lib\asyncio\proactor_events.py", line 109, in close
self._loop.call_soon(self._call_connection_lost, None)
File "c:\Program Files\Python311\Lib\asyncio\base_events.py", line 761, in call_soon
self._check_closed()
File "c:\Program Files\Python311\Lib\asyncio\base_events.py", line 519, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

Version: 0.2.19

Thanks!

Metadata

Metadata

Assignees

Labels

defectSomething isn't workingfixed - releaseIssue has been fixed, and has been releasedfixed - testingIssue has been fixed, and is in testing or awaiting release

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions