def _crete_agent_config(ctx: Context, agent_name: str, set_author: str) -> AgentConfig: """ Create agent config. :param ctx: context object. :param agent_name: agent name. :param set_author: author name to set. :return: AgentConfig object. """ agent_config = AgentConfig( agent_name=agent_name, aea_version=aea.__version__, author=set_author, version=DEFAULT_VERSION, license_=DEFAULT_LICENSE, registry_path=os.path.join("..", DEFAULT_REGISTRY_PATH), description="", ) agent_config.default_connection = str(DEFAULT_CONNECTION) agent_config.default_ledger = DEFAULT_LEDGER with open(os.path.join(agent_name, DEFAULT_AEA_CONFIG_FILE), "w") as config_file: ctx.agent_loader.dump(agent_config, config_file) return agent_config
def _create_aea(click_context, agent_name: str, set_author: str, local: bool) -> None: ctx = cast(Context, click_context.obj) path = Path(agent_name) ctx.clean_paths.append(str(path)) # we have already checked that the directory does not exist. path.mkdir(exist_ok=False) try: # set up packages directories. _setup_package_folder(Path(agent_name, "protocols")) _setup_package_folder(Path(agent_name, "contracts")) _setup_package_folder(Path(agent_name, "connections")) _setup_package_folder(Path(agent_name, "skills")) # set up a vendor directory Path(agent_name, "vendor").mkdir(exist_ok=False) Path(agent_name, "vendor", "__init__.py").touch(exist_ok=False) # create a config file inside it click.echo("Creating config file {}".format(DEFAULT_AEA_CONFIG_FILE)) config_file = open(os.path.join(agent_name, DEFAULT_AEA_CONFIG_FILE), "w") agent_config = AgentConfig( agent_name=agent_name, aea_version=aea.__version__, author=set_author, version=DEFAULT_VERSION, license=DEFAULT_LICENSE, registry_path=os.path.join("..", DEFAULT_REGISTRY_PATH), description="", ) agent_config.default_connection = DEFAULT_CONNECTION # type: ignore agent_config.default_ledger = DEFAULT_LEDGER ctx.agent_loader.dump(agent_config, config_file) # next commands must be done from the agent's directory -> overwrite ctx.cwd ctx.agent_config = agent_config ctx.cwd = agent_config.agent_name click.echo("Adding default packages ...") if local: ctx.set_config("is_local", True) _add_item(click_context, "connection", DEFAULT_CONNECTION) _add_item(click_context, "skill", DEFAULT_SKILL) except Exception as e: raise click.ClickException(str(e))
def test_agent_config_to_json_with_optional_configurations(): """Test agent config to json with optional configurations.""" agent_config = AgentConfig( "name", "author", timeout=0.1, execution_timeout=1.0, max_reactions=100, decision_maker_handler=dict(dotted_path="", file_path=""), skill_exception_policy="propagate", default_routing={"author/name:0.1.0": "author/name:0.1.0"}, loop_mode="sync", runtime_mode="async", ) agent_config.default_connection = "author/name:0.1.0" agent_config.default_ledger = DEFAULT_LEDGER agent_config.json
def test_agent_config_to_json_with_optional_configurations(): """Test agent config to json with optional configurations.""" agent_config = AgentConfig( "name", "author", period=0.1, execution_timeout=1.0, max_reactions=100, decision_maker_handler=dict(dotted_path="", file_path=""), error_handler=dict(dotted_path="", file_path=""), skill_exception_policy="propagate", connection_exception_policy="propagate", default_routing={"author/name:0.1.0": "author/name:0.1.0"}, currency_denominations={"fetchai": "fet"}, loop_mode="sync", runtime_mode="async", storage_uri="some_uri_to_storage", ) agent_config.default_connection = "author/name:0.1.0" agent_config.default_ledger = DEFAULT_LEDGER agent_config.json assert agent_config.package_id == PackageId.from_uri_path( "agent/author/name/0.1.0")
def create(click_context, agent_name, author, local): """Create an agent.""" try: _check_is_parent_folders_are_aea_projects_recursively() except Exception: logger.error( "The current folder is already an AEA project. Please move to the parent folder." ) sys.exit(1) if author is not None: if local: do_init(author, False, False) else: raise click.ClickException( "Author is not set up. Please use 'aea init' to initialize.") config = _get_or_create_cli_config() set_author = config.get(AUTHOR, None) if set_author is None: click.echo( "The AEA configurations are not initialized. Uses `aea init` before continuing or provide optional argument `--author`." ) sys.exit(1) ctx = cast(Context, click_context.obj) path = Path(agent_name) click.echo("Initializing AEA project '{}'".format(agent_name)) click.echo("Creating project directory './{}'".format(agent_name)) # create the agent's directory try: path.mkdir(exist_ok=False) # set up packages directories. _setup_package_folder(Path(agent_name, "protocols")) _setup_package_folder(Path(agent_name, "contracts")) _setup_package_folder(Path(agent_name, "connections")) _setup_package_folder(Path(agent_name, "skills")) # set up a vendor directory Path(agent_name, "vendor").mkdir(exist_ok=False) Path(agent_name, "vendor", "__init__.py").touch(exist_ok=False) # create a config file inside it click.echo("Creating config file {}".format(DEFAULT_AEA_CONFIG_FILE)) config_file = open(os.path.join(agent_name, DEFAULT_AEA_CONFIG_FILE), "w") agent_config = AgentConfig( agent_name=agent_name, aea_version=aea.__version__, author=set_author, version=DEFAULT_VERSION, license=DEFAULT_LICENSE, registry_path=os.path.join("..", DEFAULT_REGISTRY_PATH), description="", ) agent_config.default_connection = DEFAULT_CONNECTION agent_config.default_ledger = DEFAULT_LEDGER ctx.agent_loader.dump(agent_config, config_file) # next commands must be done from the agent's directory -> overwrite ctx.cwd ctx.agent_config = agent_config ctx.cwd = agent_config.agent_name click.echo("Adding default packages ...") if local: ctx.set_config("is_local", True) _add_item(click_context, "connection", DEFAULT_CONNECTION) _add_item(click_context, "skill", DEFAULT_SKILL) except OSError: logger.error("Directory already exist. Aborting...") sys.exit(1) except ValidationError as e: logger.error(str(e)) shutil.rmtree(agent_name, ignore_errors=True) sys.exit(1) except Exception as e: logger.exception(e) shutil.rmtree(agent_name, ignore_errors=True) sys.exit(1)