Added coroutines to start agents from within other agents.
Loading branch information
@@ -51,7 +51,9 @@ Features
**spade_bokeh** (bokeh plots for agents):
- Code: https://github.com/javipalanca/spade_bokeh
- Documentation: https://spade-bokeh.readthedocs.io/
@@ -13,7 +13,7 @@ attributes defined in the template must be equal in the message for this to matc
The attributes that can be set in a template are:
**to**: the jid string of the receiver of the message.
** the jid string of the sender of the message. from**
** the jid string of the sender of the message. sender**
**body**: the body of the message.
**thread**: the thread id of the conversation.
**metadata**: a (key, value) dictionary of strings to define metadata of the message. This is useful, for example, to include ` FIPA <http://www.fipa.org>`_ attributes like *ontology*, *performative*, *language*, etc.
@@ -92,7 +92,7 @@ To develop this example mixin you should do the following::
async def senf_p2p(self, msg):
async def send_p2p(self, msg):
@@ -59,4 +59,3 @@ spade.web module
@@ -204,3 +204,27 @@ And the output of this example would be::
If a exception occurs inside an
``on_start``, ``run`` or ``on_end`` coroutines, the behaviour will be
automatically killed and the exception will be stored as its
Creating an agent from within another agent
There is a common use case where you may need to create an agent from within another agent, that is, from within another
agent's behaviour. This is a
*special* case because you can't create a new event loop when you have a loop already
running. For this special case you can use the
``loop`` argument in the ``Agent`` constructor to share an event loop
between more than one agent. There is also a coroutine that allows you to start the agent from a behaviour. This is the
``async_start`` coroutine, which accepts the same arguments as the ``start`` method. Example::
async def run(self):
agent2 = Agent("agent2@fake_server", "fake_password", loop=self.agent.loop)
agent1 = Agent("agent1@fake_server", "fake_password")
warning:: If you call the ``start`` method (instead of the ``async_start`` coroutine) from within a behaviour, you'll
get an error.
Oops, something went wrong.