Skip to content

aea.aea_builder

This module contains utilities for building an AEA.

_DependenciesManager Objects

class _DependenciesManager()

Class to manage dependencies of agent packages.

__init__

def __init__() -> None

Initialize the dependency graph.

all_dependencies

@property
def all_dependencies() -> Set[ComponentId]

Get all dependencies.

dependencies_highest_version

@property
def dependencies_highest_version() -> Set[ComponentId]

Get the dependencies with highest version.

get_components_by_type

def get_components_by_type(
    component_type: ComponentType
) -> Dict[ComponentId, ComponentConfiguration]

Get the components by type.

protocols

@property
def protocols() -> Dict[ComponentId, ProtocolConfig]

Get the protocols.

connections

@property
def connections() -> Dict[ComponentId, ConnectionConfig]

Get the connections.

skills

@property
def skills() -> Dict[ComponentId, SkillConfig]

Get the skills.

contracts

@property
def contracts() -> Dict[ComponentId, ContractConfig]

Get the contracts.

add_component

def add_component(configuration: ComponentConfiguration) -> None

Add a component to the dependency manager.

Arguments:

  • configuration: the component configuration to add.

remove_component

def remove_component(component_id: ComponentId) -> None

Remove a component.

Arguments:

  • component_id: the component id

Raises:

  • ValueError: if some component depends on this package.

pypi_dependencies

@property
def pypi_dependencies() -> Dependencies

Get all the PyPI dependencies.

We currently consider only dependency that have the default PyPI index url and that specify only the version field.

Returns:

the merged PyPI dependencies

install_dependencies

def install_dependencies() -> None

Install extra dependencies for components.

AEABuilder Objects

class AEABuilder(WithLogger)

This class helps to build an AEA.

It follows the fluent interface. Every method of the builder returns the instance of the builder itself.

Note: the method 'build()' is guaranteed of being re-entrant with respect to the 'add_component(path)' method. That is, you can invoke the building method many times against the same builder instance, and the returned agent instance will not share the components with other agents, e.g.:

builder = AEABuilder() builder.add_component(...) ...

first call

my_aea_1 = builder.build()

following agents will have different components.

my_aea_2 = builder.build() # all good

However, if you manually loaded some of the components and added them with the method 'add_component_instance()', then calling build more than one time is prevented:

builder = AEABuilder() builder.add_component_instance(...) ... # other initialization code

first call

my_aea_1 = builder.build()

second call to build() would raise a Value Error.

call reset

builder.reset()

re-add the component and private keys

builder.add_component_instance(...) ... # add private keys

second call

my_aea_2 = builder.builder()

DEFAULT_AGENT_ACT_PERIOD

seconds

__init__

def __init__(with_default_packages: bool = True,
             registry_dir: str = DEFAULT_REGISTRY_NAME,
             build_dir_root: Optional[str] = None) -> None

Initialize the builder.

Arguments:

  • with_default_packages: add the default packages.
  • registry_dir: the registry directory.
  • build_dir_root: the root of the build directory.

reset

def reset(is_full_reset: bool = False) -> None

Reset the builder.

A full reset causes a reset of all data on the builder. A partial reset only resets: - name, - private keys, and - component instances

Arguments:

  • is_full_reset: whether it is a full reset or not.

set_period

def set_period(period: Optional[float]) -> "AEABuilder"

Set agent act period.

Arguments:

  • period: period in seconds

Returns:

self

set_execution_timeout

def set_execution_timeout(execution_timeout: Optional[float]) -> "AEABuilder"

Set agent execution timeout in seconds.

Arguments:

  • execution_timeout: execution_timeout in seconds

Returns:

self

set_max_reactions

def set_max_reactions(max_reactions: Optional[int]) -> "AEABuilder"

Set agent max reaction in one react.

Arguments:

  • max_reactions: int

Returns:

self

set_decision_maker_handler_details

def set_decision_maker_handler_details(decision_maker_handler_dotted_path: str,
                                       file_path: str,
                                       config: Dict[str, Any]) -> "AEABuilder"

Set error handler details.

Arguments:

  • decision_maker_handler_dotted_path: the dotted path to the decision maker handler
  • file_path: the file path to the file which contains the decision maker handler
  • config: the configuration passed to the decision maker handler on instantiation

Returns:

self

set_error_handler_details

def set_error_handler_details(error_handler_dotted_path: str, file_path: str,
                              config: Dict[str, Any]) -> "AEABuilder"

Set error handler details.

Arguments:

  • error_handler_dotted_path: the dotted path to the error handler
  • file_path: the file path to the file which contains the error handler
  • config: the configuration passed to the error handler on instantiation

Returns:

self

set_skill_exception_policy

def set_skill_exception_policy(
        skill_exception_policy: Optional[ExceptionPolicyEnum]) -> "AEABuilder"

Set skill exception policy.

Arguments:

  • skill_exception_policy: the policy

Returns:

self

set_connection_exception_policy

def set_connection_exception_policy(
    connection_exception_policy: Optional[ExceptionPolicyEnum]
) -> "AEABuilder"

Set connection exception policy.

Arguments:

  • connection_exception_policy: the policy

Returns:

self

set_default_routing

def set_default_routing(
        default_routing: Dict[PublicId, PublicId]) -> "AEABuilder"

Set default routing.

This is a map from public ids (protocols) to public ids (connections).

Arguments:

  • default_routing: the default routing mapping

Returns:

self

set_loop_mode

def set_loop_mode(loop_mode: Optional[str]) -> "AEABuilder"

Set the loop mode.

Arguments:

  • loop_mode: the agent loop mode

Returns:

self

set_runtime_mode

def set_runtime_mode(runtime_mode: Optional[str]) -> "AEABuilder"

Set the runtime mode.

Arguments:

  • runtime_mode: the agent runtime mode

Returns:

self

set_task_manager_mode

def set_task_manager_mode(task_manager_mode: Optional[str]) -> "AEABuilder"

Set the task_manager_mode.

Arguments:

  • task_manager_mode: the agent task_manager_mode

Returns:

self

set_storage_uri

def set_storage_uri(storage_uri: Optional[str]) -> "AEABuilder"

Set the storage uri.

Arguments:

  • storage_uri: storage uri

Returns:

self

set_data_dir

def set_data_dir(data_dir: Optional[str]) -> "AEABuilder"

Set the data directory.

Arguments:

  • data_dir: path to directory where to store data.

Returns:

self

set_logging_config

def set_logging_config(logging_config: Dict) -> "AEABuilder"

Set the logging configurations.

The dictionary must satisfy the following schema:

https://docs.python.org/3/library/logging.config.html#logging-config-dictschema

Arguments:

  • logging_config: the logging configurations.

Returns:

self

set_search_service_address

def set_search_service_address(search_service_address: str) -> "AEABuilder"

Set the search service address.

Arguments:

  • search_service_address: the search service address

Returns:

self

set_name

def set_name(name: str) -> "AEABuilder"

Set the name of the agent.

Arguments:

  • name: the name of the agent.

Returns:

the AEABuilder

set_default_connection

def set_default_connection(
        public_id: Optional[PublicId] = None) -> "AEABuilder"

Set the default connection.

Arguments:

  • public_id: the public id of the default connection package.

Returns:

the AEABuilder

add_private_key

def add_private_key(identifier: str,
                    private_key_path: Optional[PathLike] = None,
                    is_connection: bool = False) -> "AEABuilder"

Add a private key path.

Arguments:

  • identifier: the identifier for that private key path.
  • private_key_path: an (optional) path to the private key file. If None, the key will be created at build time.
  • is_connection: if the pair is for the connection cryptos

Returns:

the AEABuilder

remove_private_key

def remove_private_key(identifier: str,
                       is_connection: bool = False) -> "AEABuilder"

Remove a private key path by identifier, if present.

Arguments:

  • identifier: the identifier of the private key.
  • is_connection: if the pair is for the connection cryptos

Returns:

the AEABuilder

private_key_paths

@property
def private_key_paths() -> Dict[str, Optional[str]]

Get the private key paths.

connection_private_key_paths

@property
def connection_private_key_paths() -> Dict[str, Optional[str]]

Get the connection private key paths.

set_default_ledger

def set_default_ledger(identifier: Optional[str]) -> "AEABuilder"

Set a default ledger API to use.

Arguments:

  • identifier: the identifier of the ledger api

Returns:

the AEABuilder

set_required_ledgers

def set_required_ledgers(
        required_ledgers: Optional[List[str]]) -> "AEABuilder"

Set the required ledger identifiers.

These are the ledgers for which the AEA requires a key pair.

Arguments:

  • required_ledgers: the required ledgers.

Returns:

the AEABuilder.

set_build_entrypoint

def set_build_entrypoint(build_entrypoint: Optional[str]) -> "AEABuilder"

Set build entrypoint.

Arguments:

  • build_entrypoint: path to the builder script.

Returns:

the AEABuilder

set_currency_denominations

def set_currency_denominations(
        currency_denominations: Dict[str, str]) -> "AEABuilder"

Set the mapping from ledger ids to currency denominations.

Arguments:

  • currency_denominations: the mapping

Returns:

the AEABuilder

add_component

def add_component(component_type: ComponentType,
                  directory: PathLike,
                  skip_consistency_check: bool = False) -> "AEABuilder"

Add a component, given its type and the directory.

Arguments:

  • component_type: the component type.
  • directory: the directory path.
  • skip_consistency_check: if True, the consistency check are skipped.

Raises:

  • AEAException: if a component is already registered with the same component id. # noqa: DAR402 | or if there's a missing dependency. # noqa: DAR402

Returns:

the AEABuilder

add_component_instance

def add_component_instance(component: Component) -> "AEABuilder"

Add already initialized component object to resources or connections.

Please, pay attention, all dependencies have to be already loaded.

Notice also that this will make the call to 'build()' non re-entrant. You will have to reset() the builder before calling build() again.

Arguments:

  • component: Component instance already initialized.

Returns:

self

set_context_namespace

def set_context_namespace(context_namespace: Dict[str, Any]) -> "AEABuilder"

Set the context namespace.

set_agent_pypi_dependencies

def set_agent_pypi_dependencies(dependencies: Dependencies) -> "AEABuilder"

Set agent PyPI dependencies.

Arguments:

  • dependencies: PyPI dependencies for the agent.

Returns:

the AEABuilder.

remove_component

def remove_component(component_id: ComponentId) -> "AEABuilder"

Remove a component.

Arguments:

  • component_id: the public id of the component.

Returns:

the AEABuilder

add_protocol

def add_protocol(directory: PathLike) -> "AEABuilder"

Add a protocol to the agent.

Arguments:

  • directory: the path to the protocol directory

Returns:

the AEABuilder

remove_protocol

def remove_protocol(public_id: PublicId) -> "AEABuilder"

Remove protocol.

Arguments:

  • public_id: the public id of the protocol

Returns:

the AEABuilder

add_connection

def add_connection(directory: PathLike) -> "AEABuilder"

Add a connection to the agent.

Arguments:

  • directory: the path to the connection directory

Returns:

the AEABuilder

remove_connection

def remove_connection(public_id: PublicId) -> "AEABuilder"

Remove a connection.

Arguments:

  • public_id: the public id of the connection

Returns:

the AEABuilder

add_skill

def add_skill(directory: PathLike) -> "AEABuilder"

Add a skill to the agent.

Arguments:

  • directory: the path to the skill directory

Returns:

the AEABuilder

remove_skill

def remove_skill(public_id: PublicId) -> "AEABuilder"

Remove protocol.

Arguments:

  • public_id: the public id of the skill

Returns:

the AEABuilder

add_contract

def add_contract(directory: PathLike) -> "AEABuilder"

Add a contract to the agent.

Arguments:

  • directory: the path to the contract directory

Returns:

the AEABuilder

remove_contract

def remove_contract(public_id: PublicId) -> "AEABuilder"

Remove protocol.

Arguments:

  • public_id: the public id of the contract

Returns:

the AEABuilder

call_all_build_entrypoints

def call_all_build_entrypoints() -> None

Call all the build entrypoints.

get_build_root_directory

def get_build_root_directory() -> str

Get build directory root.

run_build_for_component_configuration

@classmethod
def run_build_for_component_configuration(
        cls,
        config: ComponentConfiguration,
        logger: Optional[logging.Logger] = None) -> None

Run a build entrypoint script for component configuration.

install_pypi_dependencies

def install_pypi_dependencies() -> None

Install components extra dependencies.

build

def build(connection_ids: Optional[Collection[PublicId]] = None,
          password: Optional[str] = None) -> AEA

Build the AEA.

This method is re-entrant only if the components have been added through the method 'add_component'. If some of them have been loaded with 'add_component_instance', it can be called only once, and further calls are only possible after a call to 'reset' and re-loading of the components added via 'add_component_instance' and the private keys.

Arguments:

  • connection_ids: select only these connections to run the AEA.
  • password: the password to encrypt/decrypt the private key.

Returns:

the AEA object.

get_default_ledger

def get_default_ledger() -> str

Return default ledger.

Returns:

the default ledger identifier.

get_required_ledgers

def get_required_ledgers() -> List[str]

Get the required ledger identifiers.

These are the ledgers for which the AEA requires a key pair.

Returns:

the list of required ledgers.

check_project_dependencies

@staticmethod
def check_project_dependencies(agent_configuration: AgentConfig,
                               project_path: Path) -> None

Check project config for missing dependencies.

try_to_load_agent_configuration_file

@classmethod
def try_to_load_agent_configuration_file(
        cls,
        aea_project_path: Union[str, Path],
        apply_environment_variables: bool = True) -> AgentConfig

Try to load the agent configuration file..

set_from_configuration

def set_from_configuration(agent_configuration: AgentConfig,
                           aea_project_path: Path,
                           skip_consistency_check: bool = False) -> None

Set builder variables from AgentConfig.

Arguments:

  • agent_configuration: AgentConfig to get values from.
  • aea_project_path: PathLike root directory of the agent project.
  • skip_consistency_check: if True, the consistency check are skipped.

from_aea_project

@classmethod
def from_aea_project(cls,
                     aea_project_path: PathLike,
                     skip_consistency_check: bool = False,
                     apply_environment_variables: bool = False,
                     password: Optional[str] = None) -> "AEABuilder"

Construct the builder from an AEA project.

  • load agent configuration file
  • set name and default configurations
  • load private keys
  • load ledger API configurations
  • set default ledger
  • load every component

Arguments:

  • aea_project_path: path to the AEA project.
  • skip_consistency_check: if True, the consistency check are skipped.
  • apply_environment_variables: if True, environment variables are loaded.
  • password: the password to encrypt/decrypt private keys.

Returns:

an AEABuilder.

get_configuration_file_path

@staticmethod
def get_configuration_file_path(aea_project_path: Union[Path, str]) -> Path

Return path to aea-config file for the given AEA project path.

make_component_logger

def make_component_logger(configuration: ComponentConfiguration,
                          agent_name: str) -> Optional[logging.Logger]

Make the logger for a component.

Arguments:

  • configuration: the component configuration
  • agent_name: the agent name

Returns:

the logger.