def __init__(self, name: str, oef_addr: str, oef_port: int, agent_timeout: float = 1.0, private_key_pem_path: Optional[str] = None, expected_version_id: str = str(random.randint(0, 10000))): """Agent initialization.""" super().__init__(name, private_key_pem_path, agent_timeout) self.mailbox = OEFMailBox(self.crypto.public_key, oef_addr, oef_port) self.expected_version_id = expected_version_id raise NotImplementedError("Your agent must implement the interface defined in Agent.")
def __init__( self, name: str, oef_addr: str, oef_port: int, dashboard: Optional[AgentDashboard] = None, private_key_pem: Optional[str] = None, agent_timeout: Optional[float] = 1.0, debug: bool = False, ): """ Initialize a participant agent. :param name: the name of the agent. :param oef_addr: the TCP/IP address of the OEF node. :param oef_port: the TCP/IP port of the OEF node. :param agent_timeout: the time in (fractions of) seconds to time out an agent between act and react. :param dashboard: a Visdom dashboard to visualize agent statistics during the competition. :param private_key_pem: the path to a private key in PEM format. :param debug: if True, run the agent in debug mode. """ super().__init__(name, oef_addr, oef_port, private_key_pem, agent_timeout, debug=debug) self.mailbox = OEFMailBox(self.crypto.public_key, oef_addr, oef_port)
def __init__(self, name: str, oef_addr: str, oef_port: int, strategy: Strategy, expected_version_id: str, agent_timeout: float = 1.0, max_reactions: int = 100, services_interval: int = 10, pending_transaction_timeout: int = 30, dashboard: Optional[AgentDashboard] = None, private_key_pem: Optional[str] = None, debug: bool = False): """ Initialize a participant agent. :param name: the name of the agent. :param oef_addr: the TCP/IP address of the OEF node. :param oef_port: the TCP/IP port of the OEF node. :param strategy: the strategy object that specify the behaviour during the competition. :param expected_version_id: the expected version of the TAC. :param agent_timeout: the time in (fractions of) seconds to time out an agent between act and react. :param max_reactions: the maximum number of reactions (messages processed) per call to react. :param services_interval: the number of seconds between different searches. :param pending_transaction_timeout: the timeout for cleanup of pending negotiations and unconfirmed transactions. :param dashboard: a Visdom dashboard to visualize agent statistics during the competition. :param private_key_pem: the path to a private key in PEM format. :param debug: if True, run the agent in debug mode. """ super().__init__(name, private_key_pem, agent_timeout, debug=debug) self.mailbox = OEFMailBox(self.crypto.public_key, oef_addr, oef_port) self._game_instance = GameInstance( name, strategy, self.mailbox.mail_stats, expected_version_id, services_interval, pending_transaction_timeout, dashboard) self.max_reactions = max_reactions self.controller_handler = ControllerHandler(self.crypto, self.liveness, self.game_instance, self.mailbox, self.name) self.oef_handler = OEFHandler(self.crypto, self.liveness, self.game_instance, self.mailbox, self.name) self.dialogue_handler = DialogueHandler(self.crypto, self.liveness, self.game_instance, self.mailbox, self.name)
def __init__(self, name: str, oef_addr: str, oef_port: int, tac_parameters: TACParameters, monitor: Monitor, agent_timeout: Optional[float] = 1.0, max_reactions: int = 100, private_key_pem: Optional[str] = None, debug: bool = False, **kwargs): """ Initialize a participant agent. :param name: the name of the agent. :param oef_addr: the TCP/IP address of the OEF node. :param oef_port: the TCP/IP port of the OEF node. :param strategy: the strategy object that specify the behaviour during the competition. :param agent_timeout: the time in (fractions of) seconds to time out an agent between act and react. :param max_reactions: the maximum number of reactions (messages processed) per call to react. :param monitor: a Visdom dashboard to visualize agent statistics during the competition. :param private_key_pem: the path to a private key in PEM format. :param debug: if True, run the agent in debug mode. """ super().__init__(name, private_key_pem, agent_timeout, debug=debug) self.mailbox = OEFMailBox(self.crypto.public_key, oef_addr, oef_port) self.oef_handler = OEFHandler( self.crypto, self.liveness, self.mailbox, self.name, tac_parameters.version_id, ) self.agent_message_dispatcher = AgentMessageDispatcher(self) self.game_handler = GameHandler(name, self.crypto, self.mailbox, monitor, tac_parameters) self.max_reactions = max_reactions self.last_activity = datetime.datetime.now() logger.debug( "[{}]: Initialized myself as Controller Agent :\n{}".format( self.name, pprint.pformat(vars()))) set_controller_state(self.game_handler.tac_parameters.version_id, ControllerAgentState.STARTING)
def __init__(self): """Initialize the test agent.""" super().__init__("test_agent") self.mailbox = OEFMailBox(self.crypto.public_key, "127.0.0.1", 10000)
# ------------------------------------------------------------------------------ """This script waits until the OEF is up and running.""" import argparse import logging from aea.crypto.base import Crypto from aea.channels.oef.connection import OEFMailBox logger = logging.getLogger(__name__) parser = argparse.ArgumentParser("oef_healthcheck", description=__doc__) parser.add_argument("addr", type=str, help="IP address of the OEF node.") parser.add_argument("port", type=int, help="Port of the OEF node.") if __name__ == "__main__": try: args = parser.parse_args() host = args.addr port = args.port print("Connecting to {}:{}".format(host, port)) crypto = Crypto() mailbox = OEFMailBox(crypto.public_key, oef_addr=host, oef_port=port) mailbox.connect() mailbox.disconnect() print("OK!") exit(0) except Exception as e: print(str(e)) exit(1)
def test_example(network_node): """Test the mailbox.""" crypto1 = Crypto() crypto2 = Crypto() mailbox1 = OEFMailBox(crypto1.public_key, "127.0.0.1", 10000) mailbox2 = OEFMailBox(crypto2.public_key, "127.0.0.1", 10000) mailbox1.connect() mailbox2.connect() msg = DefaultMessage(type=DefaultMessage.Type.BYTES, content=b"hello") msg_bytes = DefaultSerializer().encode(msg) mailbox1.outbox.put( Envelope( to=crypto2.public_key, sender=crypto1.public_key, protocol_id=DefaultMessage.protocol_id, message=msg_bytes, )) msg = FIPAMessage( message_id=0, dialogue_id=0, target=0, performative=FIPAMessage.Performative.CFP, query=None, ) msg_bytes = FIPASerializer().encode(msg) mailbox1.outbox.put( Envelope( to=crypto2.public_key, sender=crypto1.public_key, protocol_id=FIPAMessage.protocol_id, message=msg_bytes, )) msg = FIPAMessage( message_id=0, dialogue_id=0, target=0, performative=FIPAMessage.Performative.PROPOSE, proposal=[], ) msg_bytes = FIPASerializer().encode(msg) mailbox1.outbox.put( Envelope( to=crypto2.public_key, sender=crypto1.public_key, protocol_id=FIPAMessage.protocol_id, message=msg_bytes, )) msg = FIPAMessage( message_id=0, dialogue_id=0, target=0, performative=FIPAMessage.Performative.ACCEPT, ) msg_bytes = FIPASerializer().encode(msg) mailbox1.outbox.put( Envelope( to=crypto2.public_key, sender=crypto1.public_key, protocol_id=FIPAMessage.protocol_id, message=msg_bytes, )) msg = FIPAMessage( message_id=0, dialogue_id=0, target=0, performative=FIPAMessage.Performative.DECLINE, ) msg_bytes = FIPASerializer().encode(msg) mailbox1.outbox.put( Envelope( to=crypto2.public_key, sender=crypto1.public_key, protocol_id=FIPAMessage.protocol_id, message=msg_bytes, )) time.sleep(5.0) envelope = mailbox2.inbox.get(block=True, timeout=2.0) msg = DefaultSerializer().decode(envelope.message) assert msg.get("content") == b"hello" envelope = mailbox2.inbox.get(block=True, timeout=2.0) msg = FIPASerializer().decode(envelope.message) assert envelope.protocol_id == "fipa" assert msg.get("performative") == FIPAMessage.Performative.CFP envelope = mailbox2.inbox.get(block=True, timeout=2.0) msg = FIPASerializer().decode(envelope.message) assert envelope.protocol_id == "fipa" assert msg.get("performative") == FIPAMessage.Performative.PROPOSE envelope = mailbox2.inbox.get(block=True, timeout=2.0) msg = FIPASerializer().decode(envelope.message) assert envelope.protocol_id == "fipa" assert msg.get("performative") == FIPAMessage.Performative.ACCEPT envelope = mailbox2.inbox.get(block=True, timeout=2.0) msg = FIPASerializer().decode(envelope.message) assert envelope.protocol_id == "fipa" assert msg.get("performative") == FIPAMessage.Performative.DECLINE mailbox1.disconnect() mailbox2.disconnect()