Documentation Index
Fetch the complete documentation index at: https://docs.agentscope.io/llms.txt
Use this file to discover all available pages before exploring further.
Overview
A workspace is the agent’s execution environment. It supplies the agent with three categories of resources — tools (built-in tools and MCPs), skills, and context offloading for compressed messages and oversized tool results — and owns the lifecycle of the resources living inside it (MCP server processes, dynamically added skills, offloaded files). AgentScope ships three workspace implementations — local filesystem, Docker container, and E2B cloud sandbox — plus a workspace manager that allocates and tracks workspaces in Agent Service so that multi-tenant deployments can map workspaces to users, agents, or sessions without rewriting the agent code. For Docker and E2B, MCP servers run inside the isolated environment; the host reaches them through an in-workspace gateway covered in MCP Gateway.Use a Workspace
Create a Workspace
AgentScope ships three workspace implementations, one per execution backend:| Class | Backend |
|---|---|
LocalWorkspace | Host filesystem (built-in tools run host-side) |
DockerWorkspace | Docker container via aiodocker |
E2BWorkspace | E2B cloud sandbox via AsyncSandbox |
- LocalWorkspace
- DockerWorkspace
- E2BWorkspace
LocalWorkspace persists state directly under workdir on the host filesystem — restarts simply re-open the same directory. The directory has the following layout:default_mcps and skill_paths are seed-time inputs — they populate a brand-new workspace on first initialize(). On restart the workspace restores its MCP list from the persisted .mcp file, so re-passing the seeds is a no-op.
All three implementations share the same WorkspaceBase interface, so the same agent code runs against any backend. The methods fall into four roles:
Provision the workspace, release its resources, and clear per-session state for pool reuse. Also drives the
async with protocol.Enumerate the built-in tools, active
MCPClient instances, available skills, and a workspace-specific system prompt fragment.Persist compressed context or oversized tool results into
sessions/<session_id>/ and return a reference path the agent stores in place of the original payload.add_mcp(mcp_client) / remove_mcp(name) / add_skill(skill_path) / remove_skill(name)
dynamic management (user)
Register or remove MCP servers and skills at runtime; changes are persisted to
.mcp and skills/ so they survive restarts.Integrate with Agent
A workspace plugs intoAgent along two axes — as a source of tools / MCPs / skills, and as the offloader for context compression:
| Axis | Wiring | What the agent gets |
|---|---|---|
| Resources | Toolkit(tools=..., mcps=..., skills_or_loaders=...) | Built-in tools, MCP-provided tools, and skills available in the workspace |
| Offloading | Agent(offloader=workspace) | When context compression triggers or a tool result exceeds the size limit, the agent calls workspace.offload_context() / offload_tool_result() and stores the returned reference path in place of the original payload |
Agent only depends on the Offloader protocol (offload_context / offload_tool_result), so any object satisfying that protocol can take the role — the workspace is the typical implementation.
Workspace Manager
A workspace manager is the allocator and lifecycle owner for workspaces in a multi-tenant service. It is used by Agent Service to map incoming requests to the right workspace instance and to release them on shutdown. A manager is responsible for:- Allocation —
create_workspace(user_id, agent_id, session_id)builds a fresh workspace and tracks it;get_workspace(..., workspace_id)returns a live one or rebuilds on cache miss. - Caching and TTL — workspaces are cached in memory keyed by
workspace_id; idle entries are evicted afterttlseconds and their underlying resources (containers, sandboxes, MCP processes) torn down. - Isolation policy — the manager decides whether two requests share a workspace; the built-in managers all isolate by
agent_id, butWorkspaceManagerBaseis a tiny abstract class that can be subclassed for per-user or per-session policies. - Cleanup —
close(workspace_id)evicts a single entry andclose_all()drains the cache on app shutdown.
| Class | Pairs with | Isolation key | Cache key |
|---|---|---|---|
LocalWorkspaceManager | LocalWorkspace | agent_id (workdir = <basedir>/<agent_id>) | workspace_id |
DockerWorkspaceManager | DockerWorkspace | (user_id, agent_id) (workdir = <basedir>/<user_id>/<agent_id>) | workspace_id |
E2BWorkspaceManager | E2BWorkspace | agent_id (workspace metadata, no host workdir) | workspace_id |
WorkspaceManagerBase and override get_workspace / create_workspace with your own keying — see Agent Service · Workspace implementation and isolation for how the service wires a manager into the request lifecycle.
MCP Gateway
DockerWorkspace and E2BWorkspace cannot register host-side MCP clients directly — the MCP servers live inside the container or sandbox, and stdio sessions cannot cross that boundary. AgentScope solves this with an MCP gateway: a lightweight FastAPI process that runs inside the workspace, owns the upstream MCP sessions, and exposes them over a single authenticated HTTP endpoint that the host talks to.
The gateway exposes a small REST surface — GET /health, GET/POST/DELETE /mcps, GET /mcps/{name}/tools, POST /mcps/{name}/tools/{tool} — protected by a per-workspace bearer token minted at each initialize(). On the host, two adapters preserve the standard interfaces:
GatewayMCPClient— anMCPClientsubclass whoseconnect/close/list_toolscalls become HTTP requests against the gateway, so the rest of the toolkit cannot tell it apart from a local MCP client.GatewayMCPTool— aToolBasesubclass whose__call__posts to/mcps/{name}/tools/{tool}and reconstructs the returnedToolChunk.
MCPClient instances from list_mcps() regardless of whether the upstream session lives on the host (LocalWorkspace) or inside an isolated environment (DockerWorkspace / E2BWorkspace).
Further Reading
Agent
Agent abstraction, the ReAct loop, and offloader integration
Tool
Built-in tools, MCP integration, and toolkit composition
Agent Service
Multi-tenant service that drives the workspace manager
Context
Context compression and the offloading triggers