OFFIS-DAI / mango

Modular Python-based agent framework to implement multi-agent systems
https://mango-agents.readthedocs.io/
MIT License
12 stars 2 forks source link

allow initialization of agents without a running event loop #119

Closed maurerle closed 2 weeks ago

maurerle commented 2 weeks ago

Before, we received the error "no running event loop" when attaching an agent outside of an async context.

We solve this by assigning an event loop to all container types, making it possible to create agents in a sync setting where no event loop is running (yet). The solution is to attach the inbox task to a precreated asyncio.loop which is used later on.

Eventually, there is a smarter way to do this. Evenetually we should let the MQTT server have a second loop which is independent of ours?

(Note: this PR goes into feature-topology for now for better readability)

maurerle commented 2 weeks ago

@rcschrg I did not find a decent way to make both - the doctests, as well as my test run without errors.

It makes sense though to be able to register an agent to the container without the existance of the async context, so it would be cool to have this

maurerle commented 2 weeks ago

Eventually it is necessary to defer the creation of the inbox task right before the on_setup function?

rcschrg commented 2 weeks ago

I agree that this feature would be useful, I will check after I am finished with my current feature

rcschrg commented 2 weeks ago

It would be possible to work around with invisible testcode blocks (for some reason testsetup does not work, I don't know why). However, this would require to use asyncio.get_event_loop().run_until_complete instead of asyncio.run, because asyncio.run will create a new loop, but as the old loop is referenced in mango internally it crashes.

So, I think moving the inbox task creation is a good solution here. I will close the PR and propose one myself