Skip to content

[!WARNING] The latest version uses a client/server remote model based on the repository /external/ecm_communications please refer to that repository for updated docs.

ECM Server/Client

The ECM algorithms designed in this repository are aimed to be executed remotely, this is, to have a computer or machine that reasons, loads and computes all the cognitive layers ($A_1$) and a client machine that listens and executes all the functions sent by the server ($A_2$), this can be easily activated without affecting the core architecture by using the modules integrated in this repository.

The Client/Server modules use RabbitMQ in order to stablish a connection between the two machines, to start this protocol you only need to start listening with the client as follows:

import action_space.experimental.mouse.actions # noqa
import action_space.experimental.screenshot.actions # noqa
from ecm.remote.client import EcmClient

if __name__ == "__main__":
    client = EcmClient()
    client.listen()

Note that we must import the actions we want to be enabled in the client machine in order to be auto-detected when received from the server. Warning: If the client is not connected, the server will fail when trying to send the correspondent action.

Synchronizing the ItemRegistry

After having the client connected, we can use the ItemRegistry to send tasks to the client. For using the ItemRegistry appropriately you must differentiate between two types of capabilites:

  • Registering Functions: This is the base function for sending actions to the client. When loading AI agents, the names of this functions and multiple descriptions on how to use them are loaded in order to let the AI decide when and why to send an action to the client. Registering an action can be done as follows:

python @ItemRegistry.register_function def do_something(element: str): """Does something using the element. Usage do_something('foo')""" ...

  • Registering utils: Utils can be also sent to the client, though they won't be notified to the AI's, so you can use this tools to execute AI-hiden algorithms, such as taking screenshots for sending them to the AI, computing calculations, or obtaining information. This actions do not have to be AI-friendly.

python @ItemRegistry.register_util def restart(arg1, arg2, arg3): ...

Finally, if you want to use your functions in the host machine, just don't apply changes, in the contrary, if you want to execute utils or functions in the remote machine, use the following command to automatically synchronize with the client:

# The actions my AI will find
from action_space.experimental.mouse.agent import MouseAgent # noqa

from ecm.tools.registry import ItemRegistry
if __name__ == "__main__":
    ItemRegistry.transfer_execution_to_client()
    ...
    # execute your algorithms normally...

Warning: ItemRegistryV2 has deprecated this function. The replaced function is EcmServer.wrap_item_registry()

All the functions/utils will be sent to the client when trying to access them through the ItemRegistry.

Warning: If you try to hard-access the functions without the ItemRegistry, they will be executed in the host machine. For this reason, multiple times you will see ItemRegistry._utils["my_func"](args...) instead of calling the function directly.

Modifying connection

All the properties such as protocol, ip, etc, can be changed at the .env file. Do not share that file with anyone, it gives access to executing remote code to your machine.

For configuring this file you must create a RabbitMQ user by using the following commands:

# Add a new user
sudo rabbitmqctl add_user <USER> <PASSWORD>

# Giving access to the client
sudo rabbitmqctl set_user_tags <USER> administrator
sudo rabbitmqctl set_permissions -p / <USER> ".*" ".*" ".*"