class Teste(Agent): def __init__(self, aid): Agent.__init__(self, aid) def on_start on_start(self): Agent.on_start on_start(self) display_message(self.aid.name, "Hello World") if 'Bob' in self.aid.name: message = ACLMessage(ACLMessage.INFORM) message.add_receiver(AID('Alice')) message.set_content('Hello Alice!') self.send(message) def react(self, message): Agent.react(self, message) display_message(self.aid.name, message.get_message()) if __name__ == '__main__': set_ams('localhost', 8000) agente = Teste(AID('Alice')) agente.set_ams('localhost', 8000) agente.start() agente = Teste(AID('Bob')) agente.set_ams('localhost', 8000) agente.start() start_loop()
message.set_protocol(ACLMessage.FIPA_CONTRACT_NET_PROTOCOL) message.set_content(dumps(pedido)) message.add_receiver('participant_agent_1') message.add_receiver('participant_agent_2') behaviour = InitiatorProtocol(self, message) self.addBehaviour(behaviour) class ParticipantAgent(Agent): def __init__(self, aid, power_values): Agent.__init__(self, aid) behaviour = ParticipantProtocol(self, power_values) self.addBehaviour(behaviour) if __name__ == '__main__': set_ams('localhost', 8000) agent_participant_1 = ParticipantAgent(AID('participant_agent_1'), {'value' : 100.0}) agent_participant_1.set_ams('localhost', 8000) agent_participant_1.start() agent_participant_2 = ParticipantAgent(AID('participant_agent_2'), {'value' : 200.0}) agent_participant_2.set_ams('localhost', 8000) agent_participant_2.start() agent_initiator = InitiatorAgent(AID('initiator_agent')) agent_initiator.set_ams('localhost', 8000) agent_initiator.start() start_loop()
self.addBehaviour(behaviour_1) def on_start on_start(self): Agent.on_start on_start(self) class Agent_Participant(Agent): def __init__(self, aid): Agent.__init__(self, aid) behaviour_1 = RequestParticipant(self) self.addBehaviour(behaviour_1) def on_start on_start(self): Agent.on_start on_start(self) if __name__ == '__main__': set_ams(8000) agent_participant_1 = Agent_Participant(AID('agent_participant_1')) agent_participant_1.set_ams('localhost', 8000) agent_participant_1.start() agent_initiator = Agent_Initiator(AID('agent_initiator')) agent_initiator.set_ams('localhost', 8000) agent_initiator.start() start_loop()
self.addBehaviour(comportamento_1) def on_start on_start(self): Agent.on_start on_start(self) class Agent_Participant(Agent): def __init__(self, aid): Agent.__init__(self, aid) comportamento_1 = RequestParticipante(self) self.addBehaviour(comportamento_1) def on_start on_start(self): Agent.on_start on_start(self) if __name__ == '__main__': set_ams(8000) agent_participant_1 = Agent_Participant(AID('agent_participant_1')) agent_participant_1.set_ams('localhost', 8000) agent_participant_1.start() agent_initiator = Agent_Initiator(AID('agent_initiator')) agent_initiator.set_ams('localhost', 8000) agent_initiator.start() start_loop()