Skip to content

academy.context

ActionContext

ActionContext(
    source_id: EntityId,
    exchange_client: AgentExchangeClient[Any, Any],
)

Action invocation context.

Source code in academy/context.py
def __init__(
    self,
    source_id: EntityId,
    exchange_client: AgentExchangeClient[Any, Any],
) -> None:
    self._source_id = source_id
    self._exchange_client = exchange_client
    self._source_handle: Handle[Any] | None = None

source_id property

source_id: EntityId

ID of the source that requested the action.

source_handle property

source_handle: Handle[Any]

Get a handle to the source agent of the request.

Returns:

  • Handle[Any]

    Handle to the agent that made the request.

Raises:

  • TypeError

    If the source is a user entity.

is_agent_source

is_agent_source() -> bool

Is the source an agent.

Source code in academy/context.py
def is_agent_source(self) -> bool:
    """Is the source an agent."""
    return isinstance(self.source_id, AgentId)

is_user_source

is_user_source() -> bool

Is the source a user.

Source code in academy/context.py
def is_user_source(self) -> bool:
    """Is the source a user."""
    return isinstance(self.source_id, UserId)

AgentContext dataclass

AgentContext(
    agent_id: AgentId[BehaviorT],
    exchange_client: AgentExchangeClient[BehaviorT, Any],
    shutdown_event: Event,
)

Bases: Generic[BehaviorT]

Agent runtime context.

agent_id instance-attribute

agent_id: AgentId[BehaviorT]

ID of the exchange as registered with the exchange.

exchange_client instance-attribute

exchange_client: AgentExchangeClient[BehaviorT, Any]

Client used by agent to communicate with the exchange.

shutdown_event instance-attribute

shutdown_event: Event

Shutdown event used to signal the agent to shutdown.