WorkspaceManager
public class WorkspaceManager implements AutoCloseable
io/agentscope/harness/agent/workspace/WorkspaceManager.java:99–1026工作区管理器,承载智能体的部署、调度与服务化运行。位于 io.agentscope.harness.agent.workspace 包,实现 AutoCloseable。核心成员包括 close、getNamespaceFactory、getIndex、getFilesystem、validate、getWorkspace。
Stateless accessor for workspace content using a two-layer read architecture.
Read path: For every read (AGENTS.md, MEMORY.md, knowledge, etc.),
the AbstractFilesystem is queried first. If it returns non-empty content, that
content is used (filesystem overrides). Otherwise, the local workspace disk is read as a
fallback. The filesystem layer applies user/session scoping transparently via
NamespaceFactory.
Write path: All writes (memory, sessions, etc.) go through the
AbstractFilesystem.
Listing: File listings (memory files, knowledge files, session logs) union results from both the filesystem layer and local disk, deduplicating by relative path.
Expected layout:
workspace/
├── AGENTS.md
├── MEMORY.md
├── memory/YYYY-MM-DD.md
├── skills/<skill-name>/SKILL.md
├── knowledge/KNOWLEDGE.md
├── knowledge/*
├── subagents/<id>.md (subagent declarations)
├── agents/<agentId>/workspace/ (isolated subagent runtime root, auto-created)
├── agents/<agentId>/sessions/sessions.json
└── agents/<agentId>/sessions/<sessionId>.log.jsonl
构造器摘要Constructor Summary
方法摘要Method Summary
构造器详情Constructor Detail
WorkspaceManager
public WorkspaceManager(Path workspace)
初始化 WorkspaceManager 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspace | Path | 工作区(类型 `Path`)。The workspace. |
io/agentscope/harness/agent/workspace/WorkspaceManager.java:138–140WorkspaceManager
public WorkspaceManager(Path workspace, AbstractFilesystem filesystem)
初始化 WorkspaceManager 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspace | Path | 工作区(类型 `Path`)。The workspace. |
filesystem | AbstractFilesystem | 文件系统(类型 `AbstractFilesystem`)。The filesystem. |
io/agentscope/harness/agent/workspace/WorkspaceManager.java:142–144WorkspaceManager
public WorkspaceManager(Path workspace, AbstractFilesystem filesystem, WorkspaceIndex index)
初始化 WorkspaceManager 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspace | Path | 工作区(类型 `Path`)。The workspace. |
filesystem | AbstractFilesystem | 文件系统(类型 `AbstractFilesystem`)。The filesystem. |
index | WorkspaceIndex | 索引(类型 `WorkspaceIndex`)。The index. |
io/agentscope/harness/agent/workspace/WorkspaceManager.java:146–148WorkspaceManager
public WorkspaceManager(Path workspace, AbstractFilesystem filesystem, WorkspaceIndex index, NamespaceFactory namespaceFactory)
初始化 WorkspaceManager 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
workspace | Path | 工作区(类型 `Path`)。The workspace. |
filesystem | AbstractFilesystem | 文件系统(类型 `AbstractFilesystem`)。The filesystem. |
index | WorkspaceIndex | 索引(类型 `WorkspaceIndex`)。The index. |
namespaceFactory | NamespaceFactory | 命名空间工厂(类型 `NamespaceFactory`)。The namespace factory. |
io/agentscope/harness/agent/workspace/WorkspaceManager.java:150–156方法详情Method Detail
close
public void close()
关闭连接并释放相关资源。
Releases the SQLite-backed WorkspaceIndex when this manager owns it.
io/agentscope/harness/agent/workspace/WorkspaceManager.java:178–183getNamespaceFactory
public NamespaceFactory getNamespaceFactory()
获取命名空间工厂。
Returns the namespace factory.
NamespaceFactoryio/agentscope/harness/agent/workspace/WorkspaceManager.java:185–187getIndex
public WorkspaceIndex getIndex()
获取索引。
Returns the best-effort workspace index; may be null when unavailable.
WorkspaceIndexio/agentscope/harness/agent/workspace/WorkspaceManager.java:190–192getFilesystem
public AbstractFilesystem getFilesystem()
获取文件系统。
Returns the filesystem.
AbstractFilesystemio/agentscope/harness/agent/workspace/WorkspaceManager.java:194–196validate
public void validate()
执行校验相关操作。
Validates the workspace exists and key files are present.
io/agentscope/harness/agent/workspace/WorkspaceManager.java:202–226getWorkspace
public Path getWorkspace()
获取工作区。
Returns the workspace.
Pathio/agentscope/harness/agent/workspace/WorkspaceManager.java:228–230resolveRuntimeDataPath
public Path resolveRuntimeDataPath(RuntimeContext rc, String relativePath)
解析运行时数据路径。
Resolves a workspace-relative path for runtime user data, applying namespace prefix.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
relativePath | String | relative 路径(类型 `String`)。The relative path. |
Pathio/agentscope/harness/agent/workspace/WorkspaceManager.java:239–248readAgentsMd
public String readAgentsMd(RuntimeContext rc)
设置读取智能体 Md。
Reads AGENTS.md content, returns empty string if not found.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
Stringio/agentscope/harness/agent/workspace/WorkspaceManager.java:251–253readKnowledgeMd
public String readKnowledgeMd(RuntimeContext rc)
设置读取知识库 Md。
Reads KNOWLEDGE.md content from the knowledge directory.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
Stringio/agentscope/harness/agent/workspace/WorkspaceManager.java:256–258readMemoryMd
public String readMemoryMd(RuntimeContext rc)
设置读取记忆 Md。
Reads MEMORY.md content (two-layer: filesystem override, local fallback).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
Stringio/agentscope/harness/agent/workspace/WorkspaceManager.java:261–263readManagedWorkspaceFileUtf8
public String readManagedWorkspaceFileUtf8(RuntimeContext rc, String relativePath)
执行 readManagedWorkspaceFileUtf8 方法。
Reads a UTF-8 file under the workspace, using the two-layer pattern: filesystem first, then local disk fallback.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
relativePath | String | relative 路径(类型 `String`)。The relative path. |
Stringio/agentscope/harness/agent/workspace/WorkspaceManager.java:269–282getMemoryDir
public Path getMemoryDir(RuntimeContext rc)
获取记忆目录。
Returns the memory dir.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
Pathio/agentscope/harness/agent/workspace/WorkspaceManager.java:284–286getSkillsDir
public Path getSkillsDir()
获取技能目录。
Returns the skills dir.
Pathio/agentscope/harness/agent/workspace/WorkspaceManager.java:288–290getKnowledgeDir
public Path getKnowledgeDir()
获取知识库目录。
Returns the knowledge dir.
Pathio/agentscope/harness/agent/workspace/WorkspaceManager.java:292–294listKnowledgeFiles
public List<Path> listKnowledgeFiles(RuntimeContext rc)
列出知识库文件。
Lists all files under the knowledge directory tree (union of filesystem + local disk).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
List<Path>io/agentscope/harness/agent/workspace/WorkspaceManager.java:297–334getSessionDir
public Path getSessionDir(RuntimeContext rc, String agentId)
获取会话目录。
Returns the session dir.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
agentId | String | 智能体标识(类型 `String`)。The agent id. |
Pathio/agentscope/harness/agent/workspace/WorkspaceManager.java:336–338resolveSessionFile
public Path resolveSessionFile(RuntimeContext rc, String agentId, String sessionId)
解析会话文件。
Returns the legacy session file path (.json) without creating directories.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
agentId | String | 智能体标识(类型 `String`)。The agent id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
Pathio/agentscope/harness/agent/workspace/WorkspaceManager.java:346–349resolveSessionContextFile
public Path resolveSessionContextFile(RuntimeContext rc, String agentId, String sessionId)
解析会话上下文文件。
Returns the JSONL session context file path (LLM-facing, compacted).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
agentId | String | 智能体标识(类型 `String`)。The agent id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
Pathio/agentscope/harness/agent/workspace/WorkspaceManager.java:352–355resolveSessionLogFile
public Path resolveSessionLogFile(RuntimeContext rc, String agentId, String sessionId)
解析会话日志文件。
Returns the JSONL session log file path (full history, append-only).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
agentId | String | 智能体标识(类型 `String`)。The agent id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
Pathio/agentscope/harness/agent/workspace/WorkspaceManager.java:358–360appendUtf8WorkspaceRelative
public void appendUtf8WorkspaceRelative(RuntimeContext rc, String relativePath, String content)
追加 appendUtf8WorkspaceRelative。
Appends UTF-8 text to a workspace-relative file, creating parent directories when needed.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
relativePath | String | relative 路径(类型 `String`)。The relative path. |
content | String | 内容(类型 `String`)。The content. |
io/agentscope/harness/agent/workspace/WorkspaceManager.java:370–397updateSessionIndex
public void updateSessionIndex(RuntimeContext rc, String agentId, String sessionId, String summary)
更新会话索引。
Upserts metadata for a session in agents/ /sessions/sessions.json (small mutable JSON, keyed by sessionId).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
agentId | String | 智能体标识(类型 `String`)。The agent id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
summary | String | 摘要(类型 `String`)。The summary. |
io/agentscope/harness/agent/workspace/WorkspaceManager.java:406–437writeTaskRecord
public void writeTaskRecord(RuntimeContext rc, String agentId, String sessionId, TaskRecord record)
执行写入任务记录相关操作。
Upserts a TaskRecord in agents/ /tasks/ .json.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
agentId | String | 智能体标识(类型 `String`)。The agent id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
record | TaskRecord | 记录(类型 `TaskRecord`)。The record. |
io/agentscope/harness/agent/workspace/WorkspaceManager.java:466–497readTaskRecord
public Optional<TaskRecord> readTaskRecord(RuntimeContext rc, String agentId, String sessionId, String taskId)
执行读取任务记录相关操作。
Reads a single TaskRecord by task ID, or Optional#empty() if not found.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
agentId | String | 智能体标识(类型 `String`)。The agent id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
taskId | String | 任务标识(类型 `String`)。The task id. |
Optional<TaskRecord>io/agentscope/harness/agent/workspace/WorkspaceManager.java:502–515listTaskRecords
public Collection<TaskRecord> listTaskRecords(RuntimeContext rc, String agentId, String sessionId)
列出 listTaskRecords。
Returns all TaskRecords for the given agent and session, in insertion order.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
agentId | String | 智能体标识(类型 `String`)。The agent id. |
sessionId | String | 会话标识(类型 `String`)。The session id. |
Collection<TaskRecord>io/agentscope/harness/agent/workspace/WorkspaceManager.java:520–527listAllTaskRecords
public Collection<TaskRecord> listAllTaskRecords(RuntimeContext rc, String agentId, Duration recentWindow)
列出 listAllTaskRecords。
Returns all TaskRecords for the given agent across all sessions that have been active within recentWindow, in no particular order.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
agentId | String | 智能体标识(类型 `String`)。the parent agent identifier |
recentWindow | Duration | recent Window(类型 `Duration`)。only consider files modified within this duration; files known to be older are assumed to contain only terminal tasks and are skipped |
Collection<TaskRecord>io/agentscope/harness/agent/workspace/WorkspaceManager.java:546–598writeUtf8WorkspaceRelative
public void writeUtf8WorkspaceRelative(RuntimeContext rc, String relativePath, String content)
执行 writeUtf8WorkspaceRelative 方法。
Overwrites a workspace-relative UTF-8 file.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
relativePath | String | relative 路径(类型 `String`)。The relative path. |
content | String | 内容(类型 `String`)。The content. |
io/agentscope/harness/agent/workspace/WorkspaceManager.java:711–729writeDraftSkillFile
public void writeDraftSkillFile(RuntimeContext rc, String relativePath, String content)
执行 writeDraftSkillFile 方法。
Write a single file under skills/_drafts/ (or whatever drafts dir the caller passes).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。the runtime context (passed straight through to the filesystem) |
relativePath | String | relative 路径(类型 `String`)。workspace-relative path (must include the drafts prefix) |
content | String | 内容(类型 `String`)。UTF-8 content |
io/agentscope/harness/agent/workspace/WorkspaceManager.java:764–784moveSkill
public boolean moveSkill(RuntimeContext rc, String fromRelative, String toRelative)
执行 moveSkill 方法。
Move a directory inside the workspace (used by promotion: skills/_drafts/ → skills/).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
fromRelative | String | 来自 Relative(类型 `String`)。The from relative. |
toRelative | String | 到 Relative(类型 `String`)。The to relative. |
booleanio/agentscope/harness/agent/workspace/WorkspaceManager.java:791–810listMemoryFilePaths
public List<String> listMemoryFilePaths(RuntimeContext rc)
列出 listMemoryFilePaths。
Returns workspace-relative paths of all memory files (MEMORY.md and memory/*.md).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
List<String>io/agentscope/harness/agent/workspace/WorkspaceManager.java:939–974listSessionLogFiles
public List<String> listSessionLogFiles(RuntimeContext rc)
列出会话日志文件。
Lists workspace-relative paths of all session log files (*.log.jsonl).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
rc | RuntimeContext | rc(类型 `RuntimeContext`)。The rc. |
List<String>io/agentscope/harness/agent/workspace/WorkspaceManager.java:980–1017toWorkspaceRelativeString
public String toWorkspaceRelativeString(Path absoluteUnderWorkspace)
设置该参数。
Workspace-relative path for indexing.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
absoluteUnderWorkspace | Path | absolute Under 工作区(类型 `Path`)。The absolute under workspace. |
Stringio/agentscope/harness/agent/workspace/WorkspaceManager.java:1020–1025