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

LocalWorkspaceManager

class LocalWorkspaceManager(WorkspaceManagerBase)
源码Source agentscope/app/workspace_manager/_local_workspace_manager.py:15–208

本地工作区管理器,承载智能体的部署、调度与服务化运行。位于 agentscope.app.workspace_manager 包,继承自 WorkspaceManagerBase。核心成员包括 get_workspace、create_workspace、close、close_all。

Workspaces are keyed by workspace_id in the cache. On cache miss the manager reconstructs the workspace from basedir/agent_id — the workdir is deterministic for local workspaces so no storage lookup is needed.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(basedir: str, *, isolation: IsolationPolicy = IsolationPolicy.PER_AGENT, default_mcps: list | None = None,…
初始化 `LocalWorkspaceManager` 实例。
Initialize the local workspace manager.

方法摘要Method Summary

方法Method说明Description
async def get_workspace(user_id: str, agent_id: str, session_id: str, workspace_id: str | None = None) -> LocalWorkspaceasync
获取工作区。
Return an initialized workspace, reconstructing from disk on cache miss.
async def create_workspace(user_id: str, agent_id: str, session_id: str) -> LocalWorkspaceasyncdeprecateddeprecated
创建工作区。
Create a new workspace for the given agent and return it.
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.

构造器详情Constructor Detail

LocalWorkspaceManager

def __init__(basedir: str, *, isolation: IsolationPolicy = IsolationPolicy.PER_AGENT, default_mcps: list | None = None, skill_paths: list[str] | None = None, ttl: float = 3600.0) -> None

初始化 LocalWorkspaceManager 实例。

Initialize the local workspace manager.

参数Parameters
名称Name类型Type说明Description
basedirstrbasedir(类型 `str`)。Root directory under which per-agent workdir are created.
isolationkw默认default IsolationPolicy.PER_AGENTIsolationPolicy隔离(类型 `IsolationPolicy`)。Isolation grain for :meth:`assign_workspace_id`. See :class:`DockerWorkspaceManager` for semantics.
default_mcpskw默认default Nonelist | None默认 mcps(类型 `list | None`)。MCP clients seeded into brand-new workspaces.
skill_pathskw默认default Nonelist[str] | None技能 paths(类型 `list[str] | None`)。Skill directories seeded into brand-new workspaces.
ttlkw默认default 3600.0float存活时间(类型 `float`)。Seconds before an idle cached workspace is evicted.
源码Source agentscope/app/workspace_manager/_local_workspace_manager.py:24–56

方法详情Method Detail

get_workspace

async def get_workspace(user_id: str, agent_id: str, session_id: str, workspace_id: str | None = None) -> LocalWorkspace
async

获取工作区。

Mirrors the Docker / E2B managers' double-check pattern: a first lock acquisition handles the cache-hit fast path and collects expired entries; expired entries are then closed in parallel outside the lock; on a miss a second acquisition runs initialize() while holding the lo…

参数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 LocalWorkspace
返回LocalWorkspace。Returns local workspace.
源码Source agentscope/app/workspace_manager/_local_workspace_manager.py:70–138

create_workspace

async def create_workspace(user_id: str, agent_id: str, session_id: str) -> LocalWorkspace
asyncdeprecateddeprecated

创建工作区。

Create a new workspace for the given agent and return it.

说明Notes

  • 注意:该行为受运行时配置或底层实现影响,建议结合对应源码与版本说明确认。Deprecated: Use :meth:`get_workspace` with `workspace_id=None` — it falls back to :meth:`assign_workspace_id` under the manager's isolation policy and reuses the cache path.
已弃用。Deprecated. 已弃用,请改用受支持的替代 API。Use :meth:`get_workspace` with `workspace_id=None` — it falls back to :meth:`assign_workspace_id` under the manager's isolation policy and reuses the cache path.
参数Parameters
名称Name类型Type说明Description
user_idstr用户标识(类型 `str`)。The user id.
agent_idstr智能体标识(类型 `str`)。The agent id.
session_idstr会话标识(类型 `str`)。The session id.
返回Returns LocalWorkspace
返回LocalWorkspace。Returns local workspace.
源码Source agentscope/app/workspace_manager/_local_workspace_manager.py:145–170

close

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

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

Close and evict a single workspace from the cache.

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

close_all

async def close_all() -> None
async

关闭所有。

Stdio MCP shutdown can be slow per workspace; doing it sequentially on app shutdown produces a noticeable stall, so we fan the calls out with :func:asyncio.gather (mirrors the Docker / E2B managers).

返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/workspace_manager/_local_workspace_manager.py:181–197

继承成员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.