academy.manager¶
Manager
¶
Manager(
exchange: Exchange,
launcher: Launcher | MutableMapping[str, Launcher],
*,
default_launcher: str | None = None
)
Bases: NoPickleMixin
Launch and manage running agents.
The manager is provided as convenience to reduce common boilerplate code for spawning agents and managing handles. Each manager registers itself as a client in the exchange (i.e., each manager has its own mailbox). Handles created by the manager are bound to this mailbox.
Tip
This class can be used as a context manager. Upon exiting the context, running agents will be shutdown, any agent handles created by the manager will be closed, and the exchange and launcher will be closed.
Note
The manager takes ownership of the exchange and launcher interfaces. This means the manager will be responsible for closing them once the manager is closed.
Parameters:
-
exchange
(Exchange
) –Exchange that agents and clients will use for communication.
-
launcher
(Launcher | MutableMapping[str, Launcher]
) –A mapping of names to launchers used to execute agents remotely. If a single launcher is provided directly, it is set as the default with name
'default'
, overriding any value ofdefault_launcher
. -
default_launcher
(str | None
, default:None
) –Specify the name of the default launcher to use when not specified in
launch()
.
Raises:
-
ValueError
–If
default_launcher
is specified but does not exist inlaunchers
.
Source code in academy/manager.py
close
¶
Close the manager and cleanup resources.
- Call shutdown on all running agents.
- Close all handles created by the manager.
- Close the mailbox associated with the manager.
- Close the exchange.
- Close all launchers.
Source code in academy/manager.py
add_launcher
¶
Add a launcher to the manager.
Note
It is not possible to remove a launcher as this could create complications if an agent was already launched using a given launcher.
Parameters:
Returns:
-
Self
–Self for chaining.
Raises:
-
ValueError
–If a launcher with
name
already exists.
Source code in academy/manager.py
set_default_launcher
¶
set_default_launcher(name: str | None) -> Self
Set the name of the default launcher.
Parameters:
-
name
(str | None
) –Name of the launcher to default to. If
None
, no default launcher is set and all calls tolaunch()
must specify the launcher.
Returns:
-
Self
–Self for chaining.
Raises:
-
ValueError
–If no launcher with
name
exists.
Source code in academy/manager.py
launch
¶
launch(
behavior: BehaviorT,
*,
agent_id: AgentId[BehaviorT] | None = None,
launcher: str | None = None,
name: str | None = None
) -> BoundRemoteHandle[BehaviorT]
Launch a new agent with a specified behavior.
Note
Compared to Launcher.launch()
, this method will inject the
exchange and return a client-bound handle.
Parameters:
-
behavior
(BehaviorT
) –Behavior the agent should implement.
-
agent_id
(AgentId[BehaviorT] | None
, default:None
) –Specify ID of the launched agent. If
None
, a new agent ID will be created within the exchange. -
launcher
(str | None
, default:None
) –Name of the launcher instance to use. In
None
, uses the default launcher if specified, otherwise raises an error. -
name
(str | None
, default:None
) –Readable name of the agent. Ignored if
agent_id
is provided.
Returns:
-
BoundRemoteHandle[BehaviorT]
–Handle (client bound) used to interact with the agent.
Raises:
-
ValueError
–If no default launcher is set and
launcher
is not specified.
Source code in academy/manager.py
shutdown
¶
Shutdown a launched agent.
Parameters:
-
agent_id
(AgentId[Any]
) –ID of launched agent.
-
blocking
(bool
, default:True
) –Wait for the agent to exit before returning.
-
timeout
(float | None
, default:None
) –Optional timeout is seconds when
blocking=True
.
Raises:
-
BadEntityIdError
–If an agent with
agent_id
was not launched by this launcher. -
TimeoutError
–If
timeout
was exceeded while blocking for agent.
Source code in academy/manager.py
wait
¶
wait(
agent: AgentId[Any] | RemoteHandle[Any],
*,
timeout: float | None = None
) -> None
Wait for a launched agent to exit.
Parameters:
-
agent
(AgentId[Any] | RemoteHandle[Any]
) –ID or handle to the launched agent.
-
timeout
(float | None
, default:None
) –Optional timeout in seconds to wait for agent.
Raises:
-
BadEntityIdError
–If the agent was not found. This likely means the agent was not launched by this launcher.
-
TimeoutError
–If
timeout
was exceeded while waiting for agent.