类class
agentscope.app.workspace_managerBubblewrapWorkspaceManager
class BubblewrapWorkspaceManager(WorkspaceManagerBase)
源码Source
agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:32–272Bubblewrap 工作区管理器,承载智能体的部署、调度与服务化运行。位于 agentscope.app.workspace_manager 包,继承自 WorkspaceManagerBase。核心成员包括 get_workspace、create_workspace、close、close_all。
Explicit workspace_id values must be globally unique across users;
the cache is keyed by workspace id while the host path also includes the
user id.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(basedir: str, *, isolation: IsolationPolicy = IsolationPolicy.PER_AGENT, gateway_port: int | None = DEFAUL… | 初始化 `BubblewrapWorkspaceManager` 实例。 Initialize the Bubblewrap workspace manager. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
async def get_workspace(user_id: str, agent_id: str, session_id: str, workspace_id: str | None = None) -> BubblewrapWor…async | 获取工作区。 Return an initialized workspace, creating it on cache miss. |
async def create_workspace(user_id: str, agent_id: str, session_id: str) -> BubblewrapWorkspaceasyncdeprecateddeprecated | 创建工作区。 Build a brand-new workspace and track it. |
async def close(workspace_id: str) -> Noneasync | 关闭连接并释放相关资源。 Close and evict a single workspace. |
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 sweeper, then close cached workspaces. |
构造器详情Constructor Detail
BubblewrapWorkspaceManager
def __init__(basedir: str, *, isolation: IsolationPolicy = IsolationPolicy.PER_AGENT, gateway_port: int | None = DEFAULT_GATEWAY_PORT, share_net: bool = True, 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
初始化 BubblewrapWorkspaceManager 实例。
Initialize the Bubblewrap workspace manager.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
basedir | str | basedir(类型 `str`)。Host root for per-user/per-workspace workdirs. |
isolationkw默认default IsolationPolicy.PER_AGENT | IsolationPolicy | 隔离(类型 `IsolationPolicy`)。Isolation grain for assigned workspace ids. |
gateway_portkw默认default DEFAULT_GATEWAY_PORT | int | None | 网关 port(类型 `int | None`)。In-sandbox MCP gateway port. `None` lets each workspace allocate an available loopback port during initialization. |
share_netkw默认default True | bool | share net(类型 `bool`)。Must be `True` for the current Bubblewrap workspace TCP gateway design. |
envkw默认default None | dict[str, str] | None | env(类型 `dict[str, str] | None`)。Extra environment variables for every workspace. |
extra_pipkw默认default None | list[str] | None | extra pip(类型 `list[str] | None`)。Extra gateway venv requirements. |
default_mcpskw默认default None | list[MCPClient] | None | 默认 mcps(类型 `list[MCPClient] | None`)。MCPs seeded into new workspaces. |
skill_pathskw默认default None | list[str] | None | 技能 paths(类型 `list[str] | None`)。Skill dirs seeded into new workspaces. |
ttlkw默认default 3600.0 | float | 存活时间(类型 `float`)。Seconds before an idle workspace is evicted. |
sweep_intervalkw默认default DEFAULT_SWEEP_INTERVAL | float | sweep 间隔(类型 `float`)。Seconds between sweeper ticks. |
源码Source
agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:40–103方法详情Method Detail
get_workspace
async def get_workspace(user_id: str, agent_id: str, session_id: str, workspace_id: str | None = None) -> BubblewrapWorkspace
async
获取工作区。
Return an initialized workspace, creating it on cache miss.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
user_id | str | 用户标识(类型 `str`)。The user id. |
agent_id | str | 智能体标识(类型 `str`)。The agent id. |
session_id | str | 会话标识(类型 `str`)。The session id. |
workspace_id默认default None | str | None | 工作区标识(类型 `str | None`)。The workspace id. |
BubblewrapWorkspace
返回BubblewrapWorkspace。Returns bubblewrap workspace.
源码Source
agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:143–171create_workspace
async def create_workspace(user_id: str, agent_id: str, session_id: str) -> BubblewrapWorkspace
asyncdeprecateddeprecated
创建工作区。
Build a brand-new workspace and track it.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
user_id | str | 用户标识(类型 `str`)。The user id. |
agent_id | str | 智能体标识(类型 `str`)。The agent id. |
session_id | str | 会话标识(类型 `str`)。The session id. |
BubblewrapWorkspace
返回BubblewrapWorkspace。Returns bubblewrap workspace.
源码Source
agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:178–194close
async def close(workspace_id: str) -> None
async
关闭连接并释放相关资源。
Close and evict a single workspace.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspace_id | str | 工作区标识(类型 `str`)。The workspace id. |
None
无返回值。No value is returned.
源码Source
agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:196–203close_all
async def close_all() -> None
async
关闭所有。
Close every cached workspace in parallel.
None
无返回值。No value is returned.
源码Source
agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:205–215__aenter__
async def __aenter__() -> Self
async
进入异步上下文并返回自身。
Start the TTL sweeper task.
Self
返回自身。Returns self.
源码Source
agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:217–221__aexit__
async def __aexit__(*exc: object) -> None
async
退出异步上下文并清理资源。
Stop the sweeper, then close cached workspaces.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
exc | object | exc(类型 `object`)。The exc. |
None
无返回值。No value is returned.
源码Source
agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:223–232