agentscope.app.workspace_managerLocalWorkspaceManager
class LocalWorkspaceManager(WorkspaceManagerBase)
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
basedir | str | basedir(类型 `str`)。Root directory under which per-agent workdir are created. |
isolationkw默认default IsolationPolicy.PER_AGENT | IsolationPolicy | 隔离(类型 `IsolationPolicy`)。Isolation grain for :meth:`assign_workspace_id`. See :class:`DockerWorkspaceManager` for semantics. |
default_mcpskw默认default None | list | None | 默认 mcps(类型 `list | 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. |
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
获取工作区。
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…
| 名称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. |
agentscope/app/workspace_manager/_local_workspace_manager.py:70–138create_workspace
async def create_workspace(user_id: str, agent_id: str, session_id: str) -> LocalWorkspace
创建工作区。
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
user_id | str | 用户标识(类型 `str`)。The user id. |
agent_id | str | 智能体标识(类型 `str`)。The agent id. |
session_id | str | 会话标识(类型 `str`)。The session id. |
agentscope/app/workspace_manager/_local_workspace_manager.py:145–170close
async def close(workspace_id: str) -> None
关闭连接并释放相关资源。
Close and evict a single workspace from the cache.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspace_id | str | 工作区标识(类型 `str`)。The workspace id. |
agentscope/app/workspace_manager/_local_workspace_manager.py:172–179close_all
async def close_all() -> None
关闭所有。
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).
agentscope/app/workspace_manager/_local_workspace_manager.py:181–197