AS AgentScopeAPI 手册 / API Reference
类class agentscope.app.workspace_manager

BubblewrapWorkspaceManager

class BubblewrapWorkspaceManager(WorkspaceManagerBase)
源码Source agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:32–272

Bubblewrap 工作区管理器,承载智能体的部署、调度与服务化运行。位于 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
basedirstrbasedir(类型 `str`)。Host root for per-user/per-workspace workdirs.
isolationkw默认default IsolationPolicy.PER_AGENTIsolationPolicy隔离(类型 `IsolationPolicy`)。Isolation grain for assigned workspace ids.
gateway_portkw默认default DEFAULT_GATEWAY_PORTint | None网关 port(类型 `int | None`)。In-sandbox MCP gateway port. `None` lets each workspace allocate an available loopback port during initialization.
share_netkw默认default Trueboolshare net(类型 `bool`)。Must be `True` for the current Bubblewrap workspace TCP gateway design.
envkw默认default Nonedict[str, str] | Noneenv(类型 `dict[str, str] | None`)。Extra environment variables for every workspace.
extra_pipkw默认default Nonelist[str] | Noneextra pip(类型 `list[str] | None`)。Extra gateway venv requirements.
default_mcpskw默认default Nonelist[MCPClient] | None默认 mcps(类型 `list[MCPClient] | None`)。MCPs seeded into new workspaces.
skill_pathskw默认default Nonelist[str] | None技能 paths(类型 `list[str] | None`)。Skill dirs seeded into new workspaces.
ttlkw默认default 3600.0float存活时间(类型 `float`)。Seconds before an idle workspace is evicted.
sweep_intervalkw默认default DEFAULT_SWEEP_INTERVALfloatsweep 间隔(类型 `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_idstr用户标识(类型 `str`)。The user id.
agent_idstr智能体标识(类型 `str`)。The agent id.
session_idstr会话标识(类型 `str`)。The session id.
workspace_id默认default Nonestr | None工作区标识(类型 `str | None`)。The workspace id.
返回Returns BubblewrapWorkspace
返回BubblewrapWorkspace。Returns bubblewrap workspace.
源码Source agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:143–171

create_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_idstr用户标识(类型 `str`)。The user id.
agent_idstr智能体标识(类型 `str`)。The agent id.
session_idstr会话标识(类型 `str`)。The session id.
返回Returns BubblewrapWorkspace
返回BubblewrapWorkspace。Returns bubblewrap workspace.
源码Source agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:178–194

close

async def close(workspace_id: str) -> None
async

关闭连接并释放相关资源。

Close and evict a single workspace.

参数Parameters
名称Name类型Type说明Description
workspace_idstr工作区标识(类型 `str`)。The workspace id.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:196–203

close_all

async def close_all() -> None
async

关闭所有。

Close every cached workspace in parallel.

返回Returns 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.

返回Returns 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
excobjectexc(类型 `object`)。The exc.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/workspace_manager/_bubblewrap_workspace_manager.py:223–232

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.