Tutorial 6 - Using a different backend

By default, osBrain backend offers real connectivity between agents (each agent has its own port & IP address) in distributed systems (e,g connecting agents from raspberry pis to PCs, etc.), which explains why it is harder to debug.

In the Mesa backend, there’s only one real timer which is started in the AgentNetwork, and every timer tick will advance the agent actions by calling step() which includes agent_loop and on_received_message. Moreover, in the Mesa backend, agents do not have their own port and IP addresses, they are simulated objects to emulate the behaviour of distributed agents. Hence, osBrain is closer to deployment phase, whereas Mesa is suited for the simulation/designing phase. To switch between the backends, simply pass one of the backend enums Backend.OSBRAIN or Backend.MESA in the AgentNetwork instantiation.

# %load tutorial_6_mesa_backend.py
from agentMET4FOF.agents import AgentNetwork, MonitorAgent, SineGeneratorAgent
from agentMET4FOF.utils import Backend

def demonstrate_mesa_backend():

    # Start agent network and specify backend via the corresponding keyword parameter.
    _agent_network = AgentNetwork(backend=Backend.MESA)

    # Initialize agents by adding them to the agent network.
    sine_agent = _agent_network.add_agent(agentType=SineGeneratorAgent)
    monitor_agent = _agent_network.add_agent(agentType=MonitorAgent, buffer_size=200)

    # Set all agents states to "Running".

    return _agent_network

if __name__ == "__main__":

|                                                            |
| Your agent network is starting up. Open your browser and   |
| visit the agentMET4FOF dashboard on |
|                                                            |

[2022-02-03 21:12:53.133404] (SineGeneratorAgent_1): INITIALIZED
[2022-02-03 21:12:53.133536] (MonitorAgent_1): INITIALIZED
[2022-02-03 21:12:53.133582] (SineGeneratorAgent_1): Connected output module: MonitorAgent_1
SET STATE:   Running