agentMET4FOF agent network¶
-
class
agentMET4FOF.network.
AgentNetwork
(ip_addr='0.0.0.0', port=3333, connect=False, log_filename='log_file.csv', dashboard_modules=True, dashboard_extensions=[], dashboard_update_interval=3, dashboard_max_monitors=10, dashboard_port=8050, backend='osbrain', mesa_update_interval=0.1, network_stylesheet=[{'selector': 'node', 'style': {'label': 'data(id)', 'shape': 'rectangle', 'text-valign': 'center', 'text-halign': 'center', 'color': '#FFF', 'text-outline-width': 1.5, 'text-outline-color': '#000232'}}, {'selector': 'edge', 'style': {'curve-style': 'unbundled-bezier', 'mid-target-arrow-shape': 'triangle', 'arrow-scale': 2, 'line-color': '#4287f5', 'mid-target-arrow-color': '#4287f5', 'label': 'data(channel)', 'text-outline-width': 1.5, 'text-outline-color': '#000232', 'color': '#FFF', 'text-margin-x': '10px', 'text-margin-y': '20px'}}, {'selector': '.rectangle', 'style': {'shape': 'rectangle'}}, {'selector': '.triangle', 'style': {'shape': 'triangle'}}, {'selector': '.octagon', 'style': {'shape': 'octagon'}}, {'selector': '.ellipse', 'style': {'shape': 'ellipse'}}, {'selector': '.bluebackground', 'style': {'background-color': '#c4fdff'}}, {'selector': '.blue', 'style': {'background-color': '#006db5'}}, {'selector': '.coalition', 'style': {'background-color': '#c4fdff', 'text-valign': 'top', 'text-halign': 'center'}}, {'selector': '.coalition-edge', 'style': {'line-style': 'dashed'}}, {'selector': '.outline', 'style': {'color': '#fff', 'text-outline-color': '#888', 'text-outline-width': 2}}], **dashboard_kwargs)[source]¶ Object for starting a new Agent Network or connect to an existing Agent Network
An existing Agent Network can be specified by ip & port. Provides function to add agents, (un)bind agents, query agent network state, set global agent states Interfaces with an internal _AgentController which is hidden from user.
-
class
Coalition
(name='Coalition', agents=[])[source]¶ A special class for grouping agents.
It is rendered as a parent group on the dashboard, along with its member agents.
-
class
_AgentController
(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]¶ Unique internal agent to provide control to other agents
Automatically instantiated when starting server. Provides global control to all agents in network.
-
class
_Logger
(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]¶ An internal logger agent which is instantiated with each AgentNetwork
It collects all the logs which are sent to it, and print them and optionally save them into a csv log file. Since the user is not expected to directly access the logger agent, its initialisation option and interface are provided via the AgentNetwork object.
When log_info of any agent is called, the agent will send the data to the logger agent.
-
_set_mode
(state)[source]¶ Internal method to set mode of Agent Controller :param state: State of AgentController to set. :type state: str
-
add_agent
(name=' ', agentType=<class 'agentMET4FOF.agents.base_agents.AgentMET4FOF'>, log_mode=True, buffer_size=1000, ip_addr=None, loop_wait=None, **kwargs)[source]¶ Instantiates a new agent in the network.
Parameters: - name (str, optional) – Unique name of agent, defaults to the agent’s class name.
- agentType (AgentMET4FOF, optional) – Agent class to be instantiated in the network. Defaults to
AgentMET4FOF
- log_mode (bool, optional) – Determines if messages will be logged to background Logger Agent.
Defaults to
True
.
Returns: Newly instantiated agent
Return type:
-
agents
(filter_agent: Optional[str] = None) → List[str][source]¶ Returns all or subset of agents’ names connected to agent network
Parameters: filter_agent (str, optional) – if present, only those names are returned which contain filter_agent
’s valueReturns: requested names of agents Return type: list[str]
-
bind_agents
(source, target, channel='default')[source]¶ Binds two agents’ communication channel in a unidirectional manner
Any subsequent calls of source.send_output() will reach target agent’s message queue.
Parameters: - source (AgentMET4FOF) – Source agent whose Output channel will be binded to target
- target (AgentMET4FOF) – Target agent whose Input channel will be binded to source
-
connect
(ip_addr='127.0.0.1', port=3333, verbose=True)[source]¶ Only for osbrain backend. Connects to an existing AgentNetwork.
Parameters:
-
get_agent
(agent_name)[source]¶ Returns a particular agent connected to Agent Network.
Parameters: agent_name (str) – Name of agent to search for in the network
-
set_agents_state
(filter_agent=None, state='Idle')[source]¶ Blanket operation on all agents to set their current_state to given state
Can be used to define different states of operation such as “Running”, “Idle, “Stop”, etc.. Users will need to define their own flow of handling each type of self.current_state in the agent_loop.
Parameters:
-
set_running_state
(filter_agent=None)[source]¶ Blanket operation on all agents to set their current_state to “Running”
Users will need to define their own flow of handling each type of self.current_state in the agent_loop.
Parameters: filter_agent (str) – (Optional) Filter name of agents to set the states
-
set_stop_state
(filter_agent=None)[source]¶ Blanket operation on all agents to set their current_state attribute to “Stop”
Users will need to define their own flow of handling each type of self.current_state in the agent_loop.
Parameters: filter_agent (str) – (Optional) Filter name of agents to set the states
-
start_server_mesa
()[source]¶ Starts a new AgentNetwork for Mesa and initializes
_controller
Handles the initialisation for
backend
== "mesa"
. Involves spawning two nested objectsmesa_model
and_controller
and callsstart_mesa_timer()
.
-
start_server_osbrain
(ip_addr: str = '127.0.0.1', port: int = 3333)[source]¶ Starts a new AgentNetwork for osBrain and initializes
_controller
Parameters:
-
unbind_agents
(source, target)[source]¶ Unbinds two agents communication channel in a unidirectional manner
This is the reverse of bind_agents()
Parameters: - source (AgentMET4FOF) – Source agent whose Output channel will be unbinded from target
- target (AgentMET4FOF) – Target agent whose Input channel will be unbinded from source
-
class