[docs]classStateRunning(State):""" This class contains the Running state of the common SMIA. """
[docs]asyncdefrun(self):""" This method implements the running state of the common SMIA. Here all requests services are handled, from ACL of another SMIA. """_logger.info("## STATE 2: RUNNING ## (Initial state)")# SMIA is in the Running statussmia_archive_utils.update_status('Running')# On the one hand, a behaviour is required to handle ACL messagesacl_handling_behav=ACLHandlingBehaviour(self.agent)self.agent.add_behaviour(acl_handling_behav,SMIAInteractionInfo.SVC_STANDARD_ACL_TEMPLATE)# On the other hand, a behaviour is required to handle interaction messages# TODO revisar, ya que en el nuevo enfoque no hay AAS Core# interaction_handling_behav = InteractionHandlingBehaviour(self.agent)# self.agent.add_behaviour(interaction_handling_behav)# Besides, the negotiation behaviour has to be added to the agentagent_behaviours_classes=awaitself.add_agent_capabilities_behaviours()# Wait until the behaviour has finished. Is a CyclicBehaviour, so it will not end until an error occurs or, if# desired, it can be terminated manually using "behaviour.kill()".awaitacl_handling_behav.join()# await interaction_handling_behav.join()ifagent_behaviours_classes:# TODO revisar si esto se quiere hacer asi (pensar en las transciones entre estados)forbehav_classinagent_behaviours_classes:awaitbehav_class.join()# If the Execution Running State has been completed, the agent can move to the next state_logger.info(f"{self.agent.jid} agent has finished it Running state.")self.set_next_state(SMIAGeneralInfo.STOPPING_STATE_NAME)
[docs]asyncdefadd_agent_capabilities_behaviours(self):""" This method adds all the behaviors associated to the agent capabilities. In case of being an ExtensibleAgent, it is necessary to analyze if new behaviors have been added through the extension mechanisms. Returns: behaviours_instances: all instances of behavior to know that these are part of the Running state. """behaviours_instances=[]agent_capabilities=awaitself.agent.css_ontology.get_ontology_instances_by_class_iri(CapabilitySkillOntologyInfo.CSS_ONTOLOGY_AGENT_CAPABILITY_IRI)forcapability_instanceinagent_capabilities:ifcapability_instance.name=='Negotiation':# The negotiation behaviour has to be added to the agent_logger.info("This SMIA has negotiation capability.")negotiation_behav=NegotiatingBehaviour(self.agent)self.agent.add_behaviour(negotiation_behav,SMIAInteractionInfo.NEG_STANDARD_ACL_TEMPLATE)behaviours_instances.append(negotiation_behav)elifcapability_instance.name=='OtherAgentCapability':# TODO pensarlopassfromsmia.agents.extensible_smia_agentimportExtensibleSMIAAgent# Local import to avoid circular import errorifisinstance(self.agent,ExtensibleSMIAAgent):iflen(self.agent.extended_agent_capabilities)!=0:_logger.info("Extended agent capabilities will be added for the ExtensibleSMIAAgent.")forbehav_instanceinself.agent.extended_agent_capabilities:self.agent.add_behaviour(behav_instance)behaviours_instances.append(behav_instance)returnbehaviours_instances