Launcher and configuration

Configuration and launch MicroAgents with shipped launcher. Configuration file is a python-file with 3 dictionaries: AGENT, BUS and BROKER, where specified all settings. Launcher can run microagents from one or several files.

$ marun myproject.app1 myproject.app2

Each microagent is launched in a separate os process, and the launcher works as a supervisor. All agents started by a single command are called a deployment group and start/stop at the same time. If one of the agents stops, the launcher stops the entire group.

import sys
import logging

logging.basicConfig(format=(
    '%(levelname)-8s [pid#%(process)d] %(asctime)s %(name)s '
    '%(filename)s:%(lineno)d %(message)s'
), stream=sys.stdout, level=logging.DEBUG)


BUS = {
    'redis': {
        'backend': 'microagent.tools.redis.RedisSignalBus',
        'dsn': 'redis://localhost/7',
        'prefix': 'PREF',
    },
}

BROKER = {
    'redis': {
        'backend': 'microagent.tools.redis.RedisBroker',
        'dsn': 'redis://localhost/7',
    },
}


AGENT = {
    'user_agent': {
        'backend': 'examples.user_agent.UserAgent',
        'bus': 'redis',
        'broker': 'redis',
    },
    'comment_agent': {
        'backend': 'examples.comment_agent.CommentAgent',
        'bus': 'redis',
        'broker': 'redis',
    },
    'email_agent': {
        'backend': 'examples.email_agent.EmailAgent',
        'broker': 'redis',
    },
}
class microagent.launcher.ServerInterrupt[source]

Graceful server interruption

microagent.launcher.load_configuration(config_path: str) Iterator[tuple[str, tuple[str, dict[str, Any]]]][source]

Load configuration from module and prepare it for initializing agents. Returns list of unfolded configs for each agent.

microagent.launcher.init_agent(backend: str, cfg: dict[str, Any]) MicroAgent[source]

Import and load all using backends from config, initialize it and returns not started MicroAgent instance

class microagent.launcher.AgentsManager(cfg: list[tuple[str, tuple[str, dict[str, Any]]]])[source]

AgentsManager is a supervisor for launching and control group of microagents. When we run AgentsManager, it fork daemon process, strat microagent in the it, and wait when it finished or failed, then send SIGTERM for all other working processes.

class microagent.launcher.GroupInterrupt[source]