agentscope.app.workspace_managerAppleContainerWorkspaceManager
class AppleContainerWorkspaceManager(WorkspaceManagerBase)
agentscope/app/workspace_manager/_applecontainer_workspace_manager.py:37–294Apple 容器工作区管理器,承载智能体的部署、调度与服务化运行。位于 agentscope.app.workspace_manager 包,继承自 WorkspaceManagerBase。核心成员包括 get_workspace、close、close_all。
The manager owns a single set of container parameters
(base_image, cpus, memory) shared by every workspace
it produces.
Use the manager as an async with context manager: entering it
starts the TTL sweeper task, exiting it stops the sweeper and then
closes every cached workspace via :meth:close_all.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(*, isolation: IsolationPolicy = IsolationPolicy.PER_AGENT, base_image: str = DEFAULT_BASE_IMAGE, cpus: int… | 初始化 `AppleContainerWorkspaceManager` 实例。 Initialize the Apple Container workspace manager. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
async def get_workspace(user_id: str, agent_id: str, session_id: str, workspace_id: str | None = None) -> AppleContaine…async | 获取工作区。 Return an initialised workspace, building one on cache miss. |
async def close(workspace_id: str) -> Noneasync | 关闭连接并释放相关资源。 Close and evict a single workspace from the cache. |
async def close_all() -> Noneasync | 关闭所有。 Close every cached workspace in parallel. |
async def __aenter__() -> Selfasync | 进入异步上下文并返回自身。 Start the TTL sweeper task. |
async def __aexit__(*exc: object) -> Noneasync | 退出异步上下文并清理资源。 Stop the TTL sweeper task, then close every cached workspace. |
构造器详情Constructor Detail
AppleContainerWorkspaceManager
def __init__(*, isolation: IsolationPolicy = IsolationPolicy.PER_AGENT, base_image: str = DEFAULT_BASE_IMAGE, cpus: int = DEFAULT_CPUS, memory: str = DEFAULT_MEMORY, gateway_port: int = DEFAULT_GATEWAY_PORT, env: dict[str, str] | None = None, extra_pip: list[str] | None = None, default_mcps: list[MCPClient] | None = None, skill_paths: list[str] | None = None, ttl: float = 3600.0, sweep_interval: float = DEFAULT_SWEEP_INTERVAL) -> None
初始化 AppleContainerWorkspaceManager 实例。
Initialize the Apple Container workspace manager.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
isolationkw默认default IsolationPolicy.PER_AGENT | IsolationPolicy | 隔离(类型 `IsolationPolicy`)。Isolation grain for :meth:`assign_workspace_id`. |
base_imagekw默认default DEFAULT_BASE_IMAGE | str | 基类图像(类型 `str`)。OCI image used for every workspace. |
cpuskw默认default DEFAULT_CPUS | int | cpus(类型 `int`)。Number of virtual CPUs per container. |
memorykw默认default DEFAULT_MEMORY | str | 记忆(类型 `str`)。Memory allocation per container (e.g. `"2G"`). |
gateway_portkw默认default DEFAULT_GATEWAY_PORT | int | 网关 port(类型 `int`)。TCP port the in-container gateway listens on. |
envkw默认default None | dict[str, str] | None | env(类型 `dict[str, str] | None`)。Environment variables set in every workspace's container. |
extra_pipkw默认default None | list[str] | None | extra pip(类型 `list[str] | None`)。Extra Python packages installed into the gateway venv during bootstrap. |
default_mcpskw默认default None | list[MCPClient] | None | 默认 mcps(类型 `list[MCPClient] | None`)。MCP clients seeded into brand-new workspaces. |
skill_pathskw默认default None | list[str] | None | 技能 paths(类型 `list[str] | None`)。Skill directories seeded into brand-new workspaces. |
ttlkw默认default 3600.0 | float | 存活时间(类型 `float`)。Seconds before an idle cached workspace is evicted and its container torn down. sweep_interval (`float`, defaults to `DEFAULT_SWEEP_INTERVAL`): How often (seconds) the background sweeper wakes up. |
sweep_intervalkw默认default DEFAULT_SWEEP_INTERVAL | float | sweep 间隔(类型 `float`)。The sweep interval. |
agentscope/app/workspace_manager/_applecontainer_workspace_manager.py:50–113方法详情Method Detail
get_workspace
async def get_workspace(user_id: str, agent_id: str, session_id: str, workspace_id: str | None = None) -> AppleContainerWorkspace
获取工作区。
Return an initialised workspace, building one on cache miss.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
user_id | str | 用户标识(类型 `str`)。Owning user identifier. |
agent_id | str | 智能体标识(类型 `str`)。Agent identifier. |
session_id | str | 会话标识(类型 `str`)。Session identifier (accepted for interface parity; not used here). |
workspace_id默认default None | str | None | 工作区标识(类型 `str | None`)。Stable workspace identifier — used as the cache key and container name suffix. When unset the manager falls back to :meth:`assign_workspace_id`. |
agentscope/app/workspace_manager/_applecontainer_workspace_manager.py:149–203close
async def close(workspace_id: str) -> None
关闭连接并释放相关资源。
No-op when the workspace_id is not tracked.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspace_id | str | 工作区到关闭。The workspace to close. |
agentscope/app/workspace_manager/_applecontainer_workspace_manager.py:205–219close_all
async def close_all() -> None
关闭所有。
Close every cached workspace in parallel.
agentscope/app/workspace_manager/_applecontainer_workspace_manager.py:221–231__aenter__
async def __aenter__() -> Self
进入异步上下文并返回自身。
Start the TTL sweeper task.
agentscope/app/workspace_manager/_applecontainer_workspace_manager.py:235–239__aexit__
async def __aexit__(*exc: object) -> None
退出异步上下文并清理资源。
Stop the TTL sweeper task, then close every cached workspace.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
exc | object | exc(类型 `object`)。The exc. |
agentscope/app/workspace_manager/_applecontainer_workspace_manager.py:241–250