Exemple #1
0
 def test__is_affordable_positive(self, *mocks):
     """Test for _is_affordable positive result."""
     ledger_apis = LedgerApis({FETCHAI: DEFAULT_FETCHAI_CONFIG}, FETCHAI)
     dm = DecisionMaker("agent-name", 1, "OutBox", "Wallet", ledger_apis)
     tx_message = mock.Mock()
     tx_message.ledger_id = OFF_CHAIN
     dm._is_affordable(tx_message)
Exemple #2
0
 def test__is_affordable_positive(self, *mocks):
     """Test for _is_affordable positive result."""
     private_key_pem_path = os.path.join(CUR_PATH, "data",
                                         "fet_private_key.txt")
     wallet = Wallet({FETCHAI: private_key_pem_path})
     ledger_apis = LedgerApis({FETCHAI: DEFAULT_FETCHAI_CONFIG}, FETCHAI)
     identity = Identity("agent_name",
                         addresses=wallet.addresses,
                         default_address_key=FETCHAI)
     dm = DecisionMaker(identity, wallet, ledger_apis)
     tx_message = mock.Mock()
     tx_message.ledger_id = OFF_CHAIN
     dm._is_affordable(tx_message)
    def setup(cls):
        """Initialise the decision maker."""
        cls._patch_logger()
        cls.wallet = Wallet(
            {
                COSMOS: COSMOS_PRIVATE_KEY_PATH,
                ETHEREUM: ETHEREUM_PRIVATE_KEY_PATH,
                FETCHAI: FETCHAI_PRIVATE_KEY_PATH,
            }
        )
        cls.agent_name = "test"
        cls.identity = Identity(
            cls.agent_name, addresses=cls.wallet.addresses, default_address_key=COSMOS,
        )
        cls.decision_maker_handler = DecisionMakerHandler(
            identity=cls.identity, wallet=cls.wallet
        )
        cls.decision_maker = DecisionMaker(cls.decision_maker_handler)

        cls.tx_sender_addr = "agent_1"
        cls.tx_counterparty_addr = "pk"
        cls.info = {"some_info_key": "some_info_value"}
        cls.ledger_id = FETCHAI

        cls.decision_maker.start()
Exemple #4
0
    def setup_class(cls):
        """Initialise the decision maker."""
        cls._patch_logger()
        cls.multiplexer = Multiplexer([_make_dummy_connection()])
        private_key_pem_path = os.path.join(CUR_PATH, "data",
                                            "fet_private_key.txt")
        eth_private_key_pem_path = os.path.join(CUR_PATH, "data",
                                                "fet_private_key.txt")
        cls.wallet = Wallet({
            FETCHAI: private_key_pem_path,
            ETHEREUM: eth_private_key_pem_path
        })
        cls.ledger_apis = LedgerApis({FETCHAI: DEFAULT_FETCHAI_CONFIG},
                                     FETCHAI)
        cls.agent_name = "test"
        cls.identity = Identity(cls.agent_name,
                                addresses=cls.wallet.addresses,
                                default_address_key=FETCHAI)
        cls.ownership_state = OwnershipState()
        cls.preferences = Preferences()
        cls.decision_maker = DecisionMaker(
            identity=cls.identity,
            wallet=cls.wallet,
            ledger_apis=cls.ledger_apis,
        )
        cls.multiplexer.connect()

        cls.tx_id = "transaction0"
        cls.tx_sender_addr = "agent_1"
        cls.tx_counterparty_addr = "pk"
        cls.info = {"some_info_key": "some_info_value"}
        cls.ledger_id = "fetchai"

        cls.decision_maker.start()
Exemple #5
0
    def setup_class(cls):
        """Initialise the decision maker."""
        cls._patch_logger()
        private_key_pem_path = os.path.join(CUR_PATH, "data",
                                            "fet_private_key.txt")
        eth_private_key_pem_path = os.path.join(CUR_PATH, "data",
                                                "fet_private_key.txt")
        cls.wallet = Wallet({
            FetchAICrypto.identifier:
            private_key_pem_path,
            EthereumCrypto.identifier:
            eth_private_key_pem_path,
        })
        cls.agent_name = "test"
        cls.identity = Identity(
            cls.agent_name,
            addresses=cls.wallet.addresses,
            default_address_key=FetchAICrypto.identifier,
        )
        cls.decision_maker_handler = DecisionMakerHandler(
            identity=cls.identity, wallet=cls.wallet)
        cls.decision_maker = DecisionMaker(cls.decision_maker_handler)

        cls.tx_sender_addr = "agent_1"
        cls.tx_counterparty_addr = "pk"
        cls.info = {"some_info_key": "some_info_value"}
        cls.ledger_id = "fetchai"

        cls.decision_maker.start()
Exemple #6
0
    def setup_class(cls):
        """Initialise the decision maker."""
        cls._patch_logger()
        cls.multiplexer = Multiplexer(
            [DummyConnection(connection_id=DUMMY_CONNECTION_PUBLIC_ID)])
        cls.outbox = OutBox(cls.multiplexer)
        private_key_pem_path = os.path.join(CUR_PATH, "data",
                                            "fet_private_key.txt")
        eth_private_key_pem_path = os.path.join(CUR_PATH, "data",
                                                "fet_private_key.txt")
        cls.wallet = Wallet({
            FETCHAI: private_key_pem_path,
            ETHEREUM: eth_private_key_pem_path
        })
        cls.ledger_apis = LedgerApis({FETCHAI: DEFAULT_FETCHAI_CONFIG},
                                     FETCHAI)
        cls.agent_name = "test"
        cls.ownership_state = OwnershipState()
        cls.preferences = Preferences()
        cls.decision_maker = DecisionMaker(
            agent_name=cls.agent_name,
            max_reactions=MAX_REACTIONS,
            outbox=cls.outbox,
            wallet=cls.wallet,
            ledger_apis=cls.ledger_apis,
        )
        cls.multiplexer.connect()

        cls.tx_id = "transaction0"
        cls.tx_sender_addr = "agent_1"
        cls.tx_counterparty_addr = "pk"
        cls.info = {"some_info_key": "some_info_value"}
        cls.ledger_id = "fetchai"

        cls.decision_maker.start()
Exemple #7
0
    def __init__(
        self,
        identity: Identity,
        connections: List[Connection],
        wallet: Wallet,
        ledger_apis: LedgerApis,
        resources: Resources,
        loop: Optional[AbstractEventLoop] = None,
        timeout: float = 0.0,
        is_debug: bool = False,
        is_programmatic: bool = True,
        max_reactions: int = 20,
    ) -> None:
        """
        Instantiate the agent.

        :param identity: the identity of the agent
        :param connections: the list of connections of the agent.
        :param loop: the event loop to run the connections.
        :param wallet: the wallet of the agent.
        :param ledger_apis: the ledger apis of the agent.
        :param resources: the resources of the agent.
        :param timeout: the time in (fractions of) seconds to time out an agent between act and react
        :param is_debug: if True, run the agent in debug mode.
        :param is_programmatic: if True, run the agent in programmatic mode (skips loading of resources from directory).
        :param max_reactions: the processing rate of messages per iteration.

        :return: None
        """
        super().__init__(
            identity=identity,
            connections=connections,
            loop=loop,
            timeout=timeout,
            is_debug=is_debug,
            is_programmatic=is_programmatic,
        )

        self.max_reactions = max_reactions
        self._task_manager = TaskManager()
        self._decision_maker = DecisionMaker(
            self.name, self.max_reactions, self.outbox, wallet, ledger_apis
        )
        self._context = AgentContext(
            self.identity,
            ledger_apis,
            self.multiplexer.connection_status,
            self.outbox,
            self.decision_maker.message_in_queue,
            self.decision_maker.ownership_state,
            self.decision_maker.preferences,
            self.decision_maker.goal_pursuit_readiness,
            self.task_manager,
        )
        self._resources = resources
        self._filter = Filter(self.resources, self.decision_maker.message_out_queue)
Exemple #8
0
    def __init__(self,
                 name: str,
                 connections: List[Connection],
                 wallet: Wallet,
                 ledger_apis: LedgerApis,
                 resources: Resources,
                 loop: Optional[AbstractEventLoop] = None,
                 timeout: float = 0.0,
                 debug: bool = False,
                 max_reactions: int = 20) -> None:
        """
        Instantiate the agent.

        :param name: the name of the agent
        :param connections: the list of connections of the agent.
        :param loop: the event loop to run the connections.
        :param wallet: the wallet of the agent.
        :param ledger_apis: the ledger apis of the agent.
        :param resources: the resources of the agent.
        :param timeout: the time in (fractions of) seconds to time out an agent between act and react
        :param debug: if True, run the agent in debug mode.
        :param max_reactions: the processing rate of messages per iteration.

        :return: None
        """
        super().__init__(name=name,
                         wallet=wallet,
                         connections=connections,
                         loop=loop,
                         timeout=timeout,
                         debug=debug)

        self.max_reactions = max_reactions
        self._decision_maker = DecisionMaker(self.name, self.max_reactions,
                                             self.outbox, self.wallet,
                                             ledger_apis)
        self._context = AgentContext(
            self.name, self.wallet.public_keys, self.wallet.addresses,
            ledger_apis, self.multiplexer.connection_status, self.outbox,
            self.decision_maker.message_in_queue,
            self.decision_maker.ownership_state,
            self.decision_maker.preferences,
            self.decision_maker.goal_pursuit_readiness)
        self._resources = resources
        self._filter = Filter(self.resources,
                              self.decision_maker.message_out_queue)
Exemple #9
0
 def setup_class(cls):
     """Initialise the decision maker."""
     cls._patch_logger()
     cls.multiplexer = Multiplexer([DummyConnection()])
     cls.outbox = OutBox(cls.multiplexer)
     private_key_pem_path = os.path.join(CUR_PATH, "data",
                                         "fet_private_key.txt")
     cls.wallet = Wallet({FETCHAI: private_key_pem_path})
     cls.ledger_apis = LedgerApis({FETCHAI: DEFAULT_FETCHAI_CONFIG})
     cls.agent_name = "test"
     cls.ownership_state = OwnershipState()
     cls.preferences = Preferences()
     cls.decision_maker = DecisionMaker(agent_name=cls.agent_name,
                                        max_reactions=MAX_REACTIONS,
                                        outbox=cls.outbox,
                                        wallet=cls.wallet,
                                        ledger_apis=cls.ledger_apis)
     cls.multiplexer.connect()
Exemple #10
0
    def __init__(self, name: str,
                 mailbox: MailBox,
                 private_key_pem_path: Optional[str] = None,
                 timeout: float = 0.0,
                 debug: bool = False,
                 max_reactions: int = 20,
                 directory: str = '') -> None:
        """
        Instantiate the agent.

        :param name: the name of the agent
        :param mailbox: the mailbox of the agent.
        :param private_key_pem_path: the path to the private key of the agent.
        :param timeout: the time in (fractions of) seconds to time out an agent between act and react
        :param debug: if True, run the agent in debug mode.
        :param max_reactions: the processing rate of messages per iteration.
        :param directory: the path to the agent's resource directory.
                        | If None, we assume the directory is in the working directory of the interpreter.

        :return: None
        """
        super().__init__(name=name, private_key_pem_path=private_key_pem_path, timeout=timeout, debug=debug)

        self.max_reactions = max_reactions
        self._directory = directory if directory else str(Path(".").absolute())

        self.mailbox = mailbox
        self._decision_maker = DecisionMaker(self.max_reactions, self.outbox)
        self._context = AgentContext(self.name,
                                     self.crypto.public_key,
                                     self.outbox,
                                     self.decision_maker.message_queue,
                                     self.decision_maker.ownership_state,
                                     self.decision_maker.preferences,
                                     self.decision_maker.is_ready_to_pursuit_goals)
        self._resources = None  # type: Optional[Resources]
Exemple #11
0
 def set_decision_maker(self, decision_maker_handler: DecisionMakerHandler) -> None:
     """Set decision maker with handler provided."""
     self._decision_maker = DecisionMaker(
         decision_maker_handler=decision_maker_handler
     )
Exemple #12
0
    def __init__(
        self,
        identity: Identity,
        wallet: Wallet,
        resources: Resources,
        loop: Optional[AbstractEventLoop] = None,
        timeout: float = 0.05,
        execution_timeout: float = 0,
        max_reactions: int = 20,
        decision_maker_handler_class: Type[
            DecisionMakerHandler] = DefaultDecisionMakerHandler,
        skill_exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.
        propagate,
        loop_mode: Optional[str] = None,
        runtime_mode: Optional[str] = None,
        default_connection: Optional[PublicId] = None,
        default_routing: Optional[Dict[PublicId, PublicId]] = None,
        connection_ids: Optional[Collection[PublicId]] = None,
        search_service_address: str = "fetchai/soef:*",
        **kwargs,
    ) -> None:
        """
        Instantiate the agent.

        :param identity: the identity of the agent
        :param wallet: the wallet of the agent.
        :param resources: the resources (protocols and skills) of the agent.
        :param loop: the event loop to run the connections.
        :param timeout: the time in (fractions of) seconds to time out an agent between act and react
        :param exeution_timeout: amount of time to limit single act/handle to execute.
        :param max_reactions: the processing rate of envelopes per tick (i.e. single loop).
        :param decision_maker_handler_class: the class implementing the decision maker handler to be used.
        :param skill_exception_policy: the skill exception policy enum
        :param loop_mode: loop_mode to choose agent run loop.
        :param runtime_mode: runtime mode (async, threaded) to run AEA in.
        :param default_connection: public id to the default connection
        :param default_routing: dictionary for default routing.
        :param connection_ids: active connection ids. Default: consider all the ones in the resources.
        :param search_service_address: the address of the search service used.
        :param kwargs: keyword arguments to be attached in the agent context namespace.

        :return: None
        """
        super().__init__(
            identity=identity,
            connections=[],
            loop=loop,
            timeout=timeout,
            loop_mode=loop_mode,
            runtime_mode=runtime_mode,
        )

        self.max_reactions = max_reactions
        self._task_manager = TaskManager()
        decision_maker_handler = decision_maker_handler_class(
            identity=identity, wallet=wallet)
        self._decision_maker = DecisionMaker(
            decision_maker_handler=decision_maker_handler)
        self._context = AgentContext(
            self.identity,
            self.multiplexer.connection_status,
            self.outbox,
            self.decision_maker.message_in_queue,
            decision_maker_handler.context,
            self.task_manager,
            default_connection,
            default_routing if default_routing is not None else {},
            search_service_address,
            **kwargs,
        )
        self._execution_timeout = execution_timeout
        self._connection_ids = connection_ids
        self._resources = resources
        self._filter = Filter(self.resources,
                              self.decision_maker.message_out_queue)

        self._skills_exception_policy = skill_exception_policy

        self._setup_loggers()
Exemple #13
0
    def __init__(
        self,
        identity: Identity,
        connections: List[Connection],
        wallet: Wallet,
        ledger_apis: LedgerApis,
        resources: Resources,
        loop: Optional[AbstractEventLoop] = None,
        timeout: float = 0.05,
        execution_timeout: float = 0,
        is_debug: bool = False,
        max_reactions: int = 20,
        decision_maker_handler_class: Type[
            DecisionMakerHandler
        ] = DefaultDecisionMakerHandler,
        skill_exception_policy: ExceptionPolicyEnum = ExceptionPolicyEnum.propagate,
        loop_mode: Optional[str] = None,
        **kwargs,
    ) -> None:
        """
        Instantiate the agent.

        :param identity: the identity of the agent
        :param connections: the list of connections of the agent.
        :param wallet: the wallet of the agent.
        :param ledger_apis: the APIs the agent will use to connect to ledgers.
        :param resources: the resources (protocols and skills) of the agent.
        :param loop: the event loop to run the connections.
        :param timeout: the time in (fractions of) seconds to time out an agent between act and react
        :param exeution_timeout: amount of time to limit single act/handle to execute.
        :param is_debug: if True, run the agent in debug mode (does not connect the multiplexer).
        :param max_reactions: the processing rate of envelopes per tick (i.e. single loop).
        :param decision_maker_handler_class: the class implementing the decision maker handler to be used.
        :param skill_exception_policy: the skill exception policy enum
        :param loop_mode: loop_mode to choose agent run loop.
        :param kwargs: keyword arguments to be attached in the agent context namespace.

        :return: None
        """
        super().__init__(
            identity=identity,
            connections=connections,
            loop=loop,
            timeout=timeout,
            is_debug=is_debug,
            loop_mode=loop_mode,
        )

        self.max_reactions = max_reactions
        self._task_manager = TaskManager()
        decision_maker_handler = decision_maker_handler_class(
            identity=identity, wallet=wallet, ledger_apis=ledger_apis
        )
        self._decision_maker = DecisionMaker(
            decision_maker_handler=decision_maker_handler
        )
        self._context = AgentContext(
            self.identity,
            ledger_apis,
            self.multiplexer.connection_status,
            self.outbox,
            self.decision_maker.message_in_queue,
            decision_maker_handler.context,
            self.task_manager,
            **kwargs,
        )
        self._execution_timeout = execution_timeout
        self._resources = resources
        self._filter = Filter(self.resources, self.decision_maker.message_out_queue)

        self._skills_exception_policy = skill_exception_policy
Exemple #14
0
 def test__handle_tx_message_for_signing_positive(self, *mocks):
     """Test for _handle_tx_message_for_signing positive result."""
     ledger_apis = LedgerApis({FETCHAI: DEFAULT_FETCHAI_CONFIG}, FETCHAI)
     dm = DecisionMaker("agent-name", 1, "OutBox", "Wallet", ledger_apis)
     dm._handle_tx_message_for_signing("tx_message")