academy.exchange.redis¶
RedisAgentRegistration
dataclass
¶
RedisExchangeTransport
¶
RedisExchangeTransport(
mailbox_id: EntityId,
redis_client: Redis,
*,
redis_info: _RedisConnectionInfo
)
Bases: ExchangeTransportMixin, NoPickleMixin
Redis exchange transport bound to a specific mailbox.
Source code in academy/exchange/redis.py
new
async
classmethod
¶
new(
*,
mailbox_id: EntityId | None = None,
name: str | None = None,
redis_info: _RedisConnectionInfo
) -> Self
Instantiate a new transport.
Parameters:
-
mailbox_id(EntityId | None, default:None) –Bind the transport to the specific mailbox. If
None, a new user entity will be registered and the transport will be bound to that mailbox. -
name(str | None, default:None) –Display name of the redistered entity if
mailbox_idisNone. -
redis_info(_RedisConnectionInfo) –Redis connection information.
Returns:
-
Self–An instantiated transport bound to a specific mailbox.
Raises:
-
ConnectionError–If the Redis server is not reachable.
Source code in academy/exchange/redis.py
RedisExchangeFactory
¶
Bases: ExchangeFactory[RedisExchangeTransport]
Redis exchange client factory.
Parameters:
-
hostname(str) –Redis server hostname.
-
port(int) –Redis server port.
-
redis_kwargs(Any, default:{}) –Extra keyword arguments to pass to
redis.Redis().
Source code in academy/exchange/redis.py
create_agent_client
async
¶
create_agent_client(
registration: AgentRegistration[AgentT],
request_handler: RequestHandler[RequestT_co],
) -> AgentExchangeClient[AgentT, ExchangeTransportT]
Create a new agent exchange client.
An agent must be registered with the exchange before an exchange client can be created. For example:
factory = ExchangeFactory(...)
user_client = factory.create_user_client()
registration = user_client.register_agent(...)
agent_client = factory.create_agent_client(registration, ...)
Parameters:
-
registration(AgentRegistration[AgentT]) –Registration information returned by the exchange.
-
request_handler(RequestHandler[RequestT_co]) –Agent request message handler.
Returns:
-
AgentExchangeClient[AgentT, ExchangeTransportT]–Agent exchange client.
Raises:
-
BadEntityIdError–If an agent with
registration.agent_idis not already registered with the exchange.
Source code in academy/exchange/factory.py
create_user_client
async
¶
create_user_client(
*, name: str | None = None, start_listener: bool = True
) -> UserExchangeClient[ExchangeTransportT]
Create a new user in the exchange and associated client.
Parameters:
-
name(str | None, default:None) –Display name of the client on the exchange.
-
start_listener(bool, default:True) –Start a message listener thread.
Returns:
-
UserExchangeClient[ExchangeTransportT]–User exchange client.