Maplemx / Agently

[AI Agent Application Development Framework] - 🚀 Build AI agent native application in very few code 💬 Easy to interact with AI agent in code using structure data and chained-calls syntax 🧩 Enhance AI Agent using plugins instead of rebuild a whole new agent
http://agently.tech
Apache License 2.0
935 stars 105 forks source link

出现“RuntimeError: Event loop is closed”的小bug解决方案 #49

Closed aiwenForGit closed 4 months ago

aiwenForGit commented 4 months ago

之前在运行workflow时候多轮次中间经常出现,RuntimeError: Event loop is closed,但结果能够得到,为了解决这个问题,我找了写资料,发觉在agent.py里面改下代码即可,在214行,增加一个try finally即可。 def start_in_theard(): asyncio.set_event_loop(asyncio.new_event_loop()) loop = asyncio.get_event_loop() try: reply = asyncio.get_event_loop().run_until_complete(self.start_async(request_type)) reply_queue.put_nowait(reply) finally: loop.close()

reply = asyncio.get_event_loop().run_until_complete(self.start_async(request_type))

        #reply_queue.put_nowait(reply)

      这个错误是由于asyncio事件循环已经关闭导致的。通常在异步程序结束时,事件循环会自动关闭。但是在某些情况下,事件循环可能会意外关闭,从而导致这个错误。

虽然这个错误看起来很可怕,但实际上它不会影响程序的正常运行和输出结果。这只是一个警告信息,表示在程序结束时,事件循环已经关闭,因此无法正常关闭一些底层连接。

为了避免这个警告,你可以在程序结束前手动关闭事件循环,这样就不会触发这个错误了。

Maplemx commented 4 months ago

fixed in https://github.com/Maplemx/Agently/commit/647dc49e78df9c898ed2e5a11c6a33176f57f46d

Maplemx commented 4 months ago

optimized in https://github.com/Maplemx/Agently/commit/0fa3da4ebaf4e1b3f95fd56719ad73088059ef1c

Maplemx commented 4 months ago

published in https://github.com/Maplemx/Agently/releases/tag/v3.2.1.0

aiwenForGit commented 4 months ago

非常感谢莫总的认可,希望agently越来越好。