academy.launcher¶
Launcher
¶
Launcher that wraps a concurrent.futures.Executor
.
Parameters:
-
executor
(Executor
) –Executor used for launching agents. Note that this class takes ownership of the
executor
. -
close_exchange
(bool
, default:True
) –Passed along to the
Agent
constructor. This should typically beTrue
, the default, when the executor runs agents in separate processes, but should beFalse
for theThreadPoolExecutor
to avoid closing shared exchange objects. -
max_restarts
(int
, default:0
) –Maximum times to restart an agent if it exits with an error.
Source code in academy/launcher.py
close
¶
Close the launcher.
Warning
This will not return until all agents have exited. It is the caller's responsibility to shutdown agents prior to closing the launcher.
Source code in academy/launcher.py
launch
¶
launch(
behavior: BehaviorT,
exchange: Exchange,
*,
agent_id: AgentId[BehaviorT] | None = None,
name: str | None = None
) -> RemoteHandle[BehaviorT]
Launch a new agent with a specified behavior.
Parameters:
-
behavior
(BehaviorT
) –Behavior the agent should implement.
-
exchange
(Exchange
) –Exchange the agent will use for messaging.
-
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. -
name
(str | None
, default:None
) –Readable name of the agent. Ignored if
agent_id
is provided.
Returns:
-
RemoteHandle[BehaviorT]
–Handle (unbound) used to interact with the agent.
Source code in academy/launcher.py
running
¶
Get a set of IDs for all running agents.
Returns:
-
set[AgentId[Any]]
–Set of agent IDs corresponding to all agents launched by this launcher that have not completed yet.
Source code in academy/launcher.py
wait
¶
Wait for a launched agent to exit.
Note
Calling wait()
is only valid after launch()
has succeeded.
Parameters:
-
agent_id
(AgentId[Any]
) –ID of launched agent.
-
ignore_error
(bool
, default:False
) –Ignore any errors raised by the agent.
-
timeout
(float | None
, default:None
) –Optional timeout in seconds to wait for agent.
Raises:
-
BadEntityIdError
–If an agent with
agent_id
was not launched by this launcher. -
TimeoutError
–If
timeout
was exceeded while waiting for agent. -
Exception
–Any exception raised by the agent if
ignore_error=False
.
Source code in academy/launcher.py
ThreadLauncher
¶
Bases: Launcher
Launcher that wraps a default concurrent.futures.ThreadPoolExecutor
.
Parameters:
-
max_workers
(int | None
, default:None
) –The maximum number of threads (i.e., agents) in the pool.
-
max_restarts
(int
, default:0
) –Maximum times to restart an agent if it exits with an error.
Source code in academy/launcher.py
close
¶
Close the launcher.
Warning
This will not return until all agents have exited. It is the caller's responsibility to shutdown agents prior to closing the launcher.
Source code in academy/launcher.py
launch
¶
launch(
behavior: BehaviorT,
exchange: Exchange,
*,
agent_id: AgentId[BehaviorT] | None = None,
name: str | None = None
) -> RemoteHandle[BehaviorT]
Launch a new agent with a specified behavior.
Parameters:
-
behavior
(BehaviorT
) –Behavior the agent should implement.
-
exchange
(Exchange
) –Exchange the agent will use for messaging.
-
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. -
name
(str | None
, default:None
) –Readable name of the agent. Ignored if
agent_id
is provided.
Returns:
-
RemoteHandle[BehaviorT]
–Handle (unbound) used to interact with the agent.
Source code in academy/launcher.py
running
¶
Get a set of IDs for all running agents.
Returns:
-
set[AgentId[Any]]
–Set of agent IDs corresponding to all agents launched by this launcher that have not completed yet.
Source code in academy/launcher.py
wait
¶
Wait for a launched agent to exit.
Note
Calling wait()
is only valid after launch()
has succeeded.
Parameters:
-
agent_id
(AgentId[Any]
) –ID of launched agent.
-
ignore_error
(bool
, default:False
) –Ignore any errors raised by the agent.
-
timeout
(float | None
, default:None
) –Optional timeout in seconds to wait for agent.
Raises:
-
BadEntityIdError
–If an agent with
agent_id
was not launched by this launcher. -
TimeoutError
–If
timeout
was exceeded while waiting for agent. -
Exception
–Any exception raised by the agent if
ignore_error=False
.