AS AgentScopeAPI 手册 / API Reference
类class agentscope.workspace

K8sWorkspace

class K8sWorkspace(SandboxedWorkspaceBase)
源码Source agentscope/workspace/_k8s/_k8s_workspace.py:55–620

K 8 s 工作区,在隔离环境中安全执行代码和工具。位于 agentscope.workspace 包,继承自 SandboxedWorkspaceBase。核心成员包括 get_instructions。

default_mcps and skill_paths are seed-time inputs and are not retained as instance state past :meth:initialize.

构造器摘要Constructor Summary

构造器Constructor说明Description
def __init__(*, workspace_id: str | None = None, kubeconfig: str | None = None, namespace: str = 'agentscope', image: s…
初始化 `K8sWorkspace` 实例。
Construct a :class:`K8sWorkspace`.

方法摘要Method Summary

方法Method说明Description
async def get_instructions() -> strasync
获取指令。
Return the system-prompt fragment for this workspace.

构造器详情Constructor Detail

K8sWorkspace

def __init__(*, workspace_id: str | None = None, kubeconfig: str | None = None, namespace: str = 'agentscope', image: str = DEFAULT_IMAGE, image_pull_policy: str = 'IfNotPresent', image_pull_secrets: list[str] | None = None, resources: dict[str, Any] | None = None, node_selector: dict[str, str] | None = None, tolerations: list[dict[str, Any]] | None = None, service_account: str | None = None, gateway_port: int = DEFAULT_GATEWAY_PORT, extra_pip: list[str] | None = None, storage_class: str | None = None, storage_size: str = '1Gi', delete_pvc_on_close: bool = False, env: dict[str, str] | None = None, instructions: str = DEFAULT_WORKSPACE_INSTRUCTIONS, default_mcps: list[MCPClient] | None = None, skill_paths: list[str] | None = None) -> None

初始化 K8sWorkspace 实例。

The Pod is not started here; call :meth:initialize (or use the workspace as an async context manager).

参数Parameters
名称Name类型Type说明Description
workspace_idkw默认default Nonestr | None工作区标识(类型 `str | None`)。Stable identifier. `None` generates a fresh UUID.
kubeconfigkw默认default Nonestr | Nonekubeconfig(类型 `str | None`)。Path to kubeconfig file. `None` uses in-cluster config.
namespacekw默认default 'agentscope'str命名空间(类型 `str`)。K8s namespace for the Pod and PVC.
imagekw默认default DEFAULT_IMAGEstr图像(类型 `str`)。Container image.
image_pull_policykw默认default 'IfNotPresent'str图像 pull 策略(类型 `str`)。K8s imagePullPolicy.
image_pull_secretskw默认default Nonelist[str] | None图像 pull secrets(类型 `list[str] | None`)。Names of K8s image pull secrets.
resourceskw默认default Nonedict[str, Any] | Noneresources(类型 `dict[str, Any] | None`)。K8s ResourceRequirements dict.
node_selectorkw默认default Nonedict[str, str] | None节点 selector(类型 `dict[str, str] | None`)。K8s nodeSelector.
tolerationskw默认default Nonelist[dict[str, Any]] | Nonetolerations(类型 `list[dict[str, Any]] | None`)。K8s tolerations list.
service_accountkw默认default Nonestr | None服务 account(类型 `str | None`)。K8s serviceAccountName.
gateway_portkw默认default DEFAULT_GATEWAY_PORTint网关 port(类型 `int`)。Port the gateway listens on inside the Pod.
extra_pipkw默认default Nonelist[str] | Noneextra pip(类型 `list[str] | None`)。Extra packages for the gateway venv.
storage_classkw默认default Nonestr | None存储类(类型 `str | None`)。K8s StorageClass name. `None` uses cluster default.
storage_sizekw默认default '1Gi'str存储大小(类型 `str`)。PVC size.
delete_pvc_on_closekw默认default Falsebool删除 pvc on 关闭(类型 `bool`)。When `True`, :meth:`close` also deletes the PVC.
envkw默认default Nonedict[str, str] | Noneenv(类型 `dict[str, str] | None`)。Environment variables for the container.
instructionskw默认default DEFAULT_WORKSPACE_INSTRUCTIONSstr指令(类型 `str`)。System-prompt fragment template.
default_mcpskw默认default Nonelist[MCPClient] | None默认 mcps(类型 `list[MCPClient] | None`)。MCPs seeded on first init.
skill_pathskw默认default Nonelist[str] | None技能 paths(类型 `list[str] | None`)。Skill directories seeded on first init.
源码Source agentscope/workspace/_k8s/_k8s_workspace.py:64–170

方法详情Method Detail

get_instructions

async def get_instructions() -> str
async

获取指令。

Return the system-prompt fragment for this workspace.

返回Returns str
返回字符串结果。Returns a string.
源码Source agentscope/workspace/_k8s/_k8s_workspace.py:242–244
基于官方固定版本源码静态生成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.