aea.aea_builder

This module contains utilities for building an AEA.

AEABuilder Objects

class AEABuilder()

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()

__init__

 | __init__(with_default_packages: bool = True)

Initialize the builder.

Arguments:

  • with_default_packages: add the default packages.

reset

 | 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.

Returns:

None

set_timeout

 | set_timeout(timeout: Optional[float]) -> "AEABuilder"

Set agent loop idle timeout in seconds.

Arguments:

  • timeout: timeout in seconds

Returns:

self

set_execution_timeout

 | 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

 | 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

 | set_decision_maker_handler(decision_maker_handler_dotted_path: str, file_path: Path) -> "AEABuilder"

Set decision maker handler class.

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

Returns:

self

set_skill_exception_policy

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

Set skill exception policy.

Arguments:

  • skill_exception_policy: the policy

Returns:

self

set_default_routing

 | 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

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

Set the loop mode.

Arguments:

  • loop_mode: the agent loop mode

Returns:

self

set_runtime_mode

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

Set the runtime mode.

Arguments:

  • runtime_mode: the agent runtime mode

Returns:

self

set_search_service_address

 | 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

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

Set the name of the agent.

Arguments:

  • name: the name of the agent.

Returns:

the AEABuilder

set_default_connection

 | set_default_connection(public_id: PublicId) -> "AEABuilder"

Set the default connection.

Arguments:

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

Returns:

the AEABuilder

add_private_key

 | 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

 | 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
 | private_key_paths() -> Dict[str, Optional[str]]

Get the private key paths.

connection_private_key_paths

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

Get the connection private key paths.

set_default_ledger

 | set_default_ledger(identifier: str) -> "AEABuilder"

Set a default ledger API to use.

Arguments:

  • identifier: the identifier of the ledger api

Returns:

the AEABuilder

add_component

 | 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. | or if there's a missing dependency.

Returns:

the AEABuilder

add_component_instance

 | 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.

:params component: Component instance already initialized.

set_context_namespace

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

Set the context namespace.

remove_component

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

Remove a component.

Arguments:

  • component_id: the public id of the component.

Returns:

the AEABuilder

add_protocol

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

Add a protocol to the agent.

Arguments:

  • directory: the path to the protocol directory

Returns:

the AEABuilder

remove_protocol

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

Remove protocol.

Arguments:

  • public_id: the public id of the protocol

Returns:

the AEABuilder

add_connection

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

Add a connection to the agent.

Arguments:

  • directory: the path to the connection directory

Returns:

the AEABuilder

remove_connection

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

Remove a connection.

Arguments:

  • public_id: the public id of the connection

Returns:

the AEABuilder

add_skill

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

Add a skill to the agent.

Arguments:

  • directory: the path to the skill directory

Returns:

the AEABuilder

remove_skill

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

Remove protocol.

Arguments:

  • public_id: the public id of the skill

Returns:

the AEABuilder

add_contract

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

Add a contract to the agent.

Arguments:

  • directory: the path to the contract directory

Returns:

the AEABuilder

remove_contract

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

Remove protocol.

Arguments:

  • public_id: the public id of the contract

Returns:

the AEABuilder

build

 | build(connection_ids: Optional[Collection[PublicId]] = 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.

Returns:

the AEA object.

Raises:

  • ValueError: if we cannot

set_from_configuration

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

Set builder variables from AgentConfig.

:params agent_configuration: AgentConfig to get values from. :params aea_project_path: PathLike root directory of the agent project.

Arguments:

  • skip_consistency_check: if True, the consistency check are skipped.

Returns:

None

from_aea_project

 | @classmethod
 | from_aea_project(cls, aea_project_path: PathLike, skip_consistency_check: bool = False) -> "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.

Returns:

an AEABuilder.

make_logger

make_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.