aea.decision_maker.base

This module contains the decision maker class.

OwnershipState

class OwnershipState(ABC)

Represent the ownership state of an agent.

set

 | @abstractmethod
 | set(**kwargs) -> None

Set values on the ownership state.

Arguments:

  • kwargs: the relevant keyword arguments

Returns:

None

apply_delta

 | @abstractmethod
 | apply_delta(**kwargs) -> None

Apply a state update to the ownership state.

This method is used to apply a raw state update without a transaction.

Arguments:

  • kwargs: the relevant keyword arguments

Returns:

None

is_initialized

 | @property
 | @abstractmethod
 | is_initialized() -> bool

Get the initialization status.

is_affordable_transaction

 | @abstractmethod
 | is_affordable_transaction(tx_message: TransactionMessage) -> bool

Check if the transaction is affordable (and consistent).

Arguments:

  • tx_message: the transaction message

Returns:

True if the transaction is legal wrt the current state, false otherwise.

apply_transactions

 | @abstractmethod
 | apply_transactions(transactions: List[TransactionMessage]) -> "OwnershipState"

Apply a list of transactions to (a copy of) the current state.

Arguments:

  • transactions: the sequence of transaction messages.

Returns:

the final state.

__copy__

 | @abstractmethod
 | __copy__() -> "OwnershipState"

Copy the object.

LedgerStateProxy

class LedgerStateProxy(ABC)

Class to represent a proxy to a ledger state.

is_initialized

 | @property
 | @abstractmethod
 | is_initialized() -> bool

Get the initialization status.

is_affordable_transaction

 | @abstractmethod
 | is_affordable_transaction(tx_message: TransactionMessage) -> bool

Check if the transaction is affordable on the default ledger.

Arguments:

  • tx_message: the transaction message

Returns:

whether the transaction is affordable on the ledger

Preferences

class Preferences(ABC)

Class to represent the preferences.

set

 | @abstractmethod
 | set(**kwargs, ,) -> None

Set values on the preferences.

Arguments:

  • kwargs: the relevant key word arguments

is_initialized

 | @property
 | @abstractmethod
 | is_initialized() -> bool

Get the initialization status.

Returns True if exchange_params_by_currency_id and utility_params_by_good_id are not None.

marginal_utility

 | @abstractmethod
 | marginal_utility(ownership_state: OwnershipState, **kwargs, ,) -> float

Compute the marginal utility.

Arguments:

  • ownership_state: the ownership state against which to compute the marginal utility.
  • kwargs: optional keyword argyments

Returns:

the marginal utility score

utility_diff_from_transaction

 | @abstractmethod
 | utility_diff_from_transaction(ownership_state: OwnershipState, tx_message: TransactionMessage) -> float

Simulate a transaction and get the resulting utility difference (taking into account the fee).

Arguments:

  • ownership_state: the ownership state against which to apply the transaction.
  • tx_message: a transaction message.

Returns:

the score.

__copy__

 | @abstractmethod
 | __copy__() -> "Preferences"

Copy the object.

ProtectedQueue

class ProtectedQueue(Queue)

A wrapper of a queue to protect which object can read from it.

__init__

 | __init__(access_code: str)

Initialize the protected queue.

Arguments:

  • access_code: the access code to read from the queue

put

 | put(internal_message: Optional[InternalMessage], block=True, timeout=None) -> None

Put an internal message on the queue.

If optional args block is true and timeout is None (the default), block if necessary until a free slot is available. If timeout is a positive number, it blocks at most timeout seconds and raises the Full exception if no free slot was available within that time. Otherwise (block is false), put an item on the queue if a free slot is immediately available, else raise the Full exception (timeout is ignored in that case).

Arguments:

  • internal_message: the internal message to put on the queue :raises: ValueError, if the item is not an internal message

Returns:

None

put_nowait

 | put_nowait(internal_message: Optional[InternalMessage]) -> None

Put an internal message on the queue.

Equivalent to put(item, False).

Arguments:

  • internal_message: the internal message to put on the queue :raises: ValueError, if the item is not an internal message

Returns:

None

get

 | get(block=True, timeout=None) -> None

Inaccessible get method.

:raises: ValueError, access not permitted.

Returns:

None

get_nowait

 | get_nowait() -> None

Inaccessible get_nowait method.

:raises: ValueError, access not permitted.

Returns:

None

protected_get

 | protected_get(access_code: str, block=True, timeout=None) -> Optional[InternalMessage]

Access protected get method.

Arguments:

  • access_code: the access code
  • block: If optional args block is true and timeout is None (the default), block if necessary until an item is available.
  • timeout: If timeout is a positive number, it blocks at most timeout seconds and raises the Empty exception if no item was available within that time. :raises: ValueError, if caller is not permitted

Returns:

internal message

DecisionMakerHandler

class DecisionMakerHandler(ABC)

This class implements the decision maker.

__init__

 | __init__(identity: Identity, wallet: Wallet, **kwargs)

Initialize the decision maker handler.

Arguments:

  • identity: the identity
  • wallet: the wallet
  • kwargs: the key word arguments

identity

 | @property
 | identity() -> Identity

The identity of the agent.

wallet

 | @property
 | wallet() -> Wallet

The wallet of the agent.

context

 | @property
 | context() -> SimpleNamespace

Get the context.

message_out_queue

 | @property
 | message_out_queue() -> AsyncFriendlyQueue

Get (out) queue.

handle

 | @abstractmethod
 | handle(message: InternalMessage) -> None

Handle an internal message from the skills.

Arguments:

  • message: the internal message

Returns:

None

DecisionMaker

class DecisionMaker()

This class implements the decision maker.

__init__

 | __init__(decision_maker_handler: DecisionMakerHandler)

Initialize the decision maker.

Arguments:

  • agent_name: the agent name
  • decision_maker_handler: the decision maker handler

message_in_queue

 | @property
 | message_in_queue() -> ProtectedQueue

Get (in) queue.

message_out_queue

 | @property
 | message_out_queue() -> AsyncFriendlyQueue

Get (out) queue.

decision_maker_handler

 | @property
 | decision_maker_handler() -> DecisionMakerHandler

Get the decision maker handler.

start

 | start() -> None

Start the decision maker.

stop

 | stop() -> None

Stop the decision maker.

execute

 | execute() -> None

Execute the decision maker.

Performs the following while not stopped:

  • gets internal messages from the in queue and calls handle() on them

Returns:

None

handle

 | handle(message: InternalMessage) -> None

Handle an internal message from the skills.

Arguments:

  • message: the internal message

Returns:

None