Skip to content

aea.agent_loop

This module contains the implementation of an agent loop using asyncio.

AgentLoopException Objects

class AgentLoopException(AEAException)

Exception for agent loop runtime errors.

AgentLoopStates Objects

class AgentLoopStates(Enum)

Internal agent loop states.

BaseAgentLoop Objects

class BaseAgentLoop(Runnable, WithLogger, ABC)

Base abstract agent loop class.

__init__

def __init__(agent: AbstractAgent,
             loop: Optional[AbstractEventLoop] = None,
             threaded: bool = False) -> None

Init loop.

Arguments:

  • agent: Agent or AEA to run.
  • loop: optional asyncio event loop. if not specified a new loop will be created.
  • threaded: if True, run in threaded mode, else async

agent

@property
def agent() -> AbstractAgent

Get agent.

state

@property
def state() -> AgentLoopStates

Get current main loop state.

wait_state

async def wait_state(
        state_or_states: Union[Any, Sequence[Any]]) -> Tuple[Any, Any]

Wait state to be set.

Arguments:

  • state_or_states: state or list of states.

Returns:

tuple of previous state and new state.

is_running

@property
def is_running() -> bool

Get running state of the loop.

set_loop

def set_loop(loop: AbstractEventLoop) -> None

Set event loop and all event loop related objects.

run

async def run() -> None

Run agent loop.

send_to_skill

@abstractmethod
def send_to_skill(message_or_envelope: Union[Message, Envelope],
                  context: Optional[EnvelopeContext] = None) -> None

Send message or envelope to another skill.

If message passed it will be wrapped into envelope with optional envelope context.

Arguments:

  • message_or_envelope: envelope to send to another skill.
  • context: envelope context

skill2skill_queue

@property
@abstractmethod
def skill2skill_queue() -> Queue

Get skill to skill message queue.

AsyncAgentLoop Objects

class AsyncAgentLoop(BaseAgentLoop)

Asyncio based agent loop suitable only for AEA.

NEW_BEHAVIOURS_PROCESS_SLEEP

check new behaviours registered every second.

__init__

def __init__(agent: AbstractAgent,
             loop: Optional[AbstractEventLoop] = None,
             threaded: bool = False) -> None

Init agent loop.

Arguments:

  • agent: AEA instance
  • loop: asyncio loop to use. optional
  • threaded: is a new thread to be started for the agent loop

skill2skill_queue

@property
def skill2skill_queue() -> Queue

Get skill to skill message queue.

send_to_skill

def send_to_skill(message_or_envelope: Union[Message, Envelope],
                  context: Optional[EnvelopeContext] = None) -> None

Send message or envelope to another skill.

If message passed it will be wrapped into envelope with optional envelope context.

Arguments:

  • message_or_envelope: envelope to send to another skill.
  • context: envelope context

SyncAgentLoop

temporary solution!