Class WorkspaceManager
- All Implemented Interfaces:
AutoCloseable
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
ConstructorsConstructorDescriptionWorkspaceManager(Path workspace) WorkspaceManager(Path workspace, AbstractFilesystem filesystem) WorkspaceManager(Path workspace, AbstractFilesystem filesystem, WorkspaceIndex index) WorkspaceManager(Path workspace, AbstractFilesystem filesystem, WorkspaceIndex index, NamespaceFactory namespaceFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidappendUtf8WorkspaceRelative(io.agentscope.core.agent.RuntimeContext rc, String relativePath, String content) Appends UTF-8 text to a workspace-relative file, creating parent directories when needed.voidclose()Releases the SQLite-backedWorkspaceIndexwhen this manager owns it.getIndex()Returns the best-effort workspace index; may benullwhen unavailable.getMemoryDir(io.agentscope.core.agent.RuntimeContext rc) getSessionDir(io.agentscope.core.agent.RuntimeContext rc, String agentId) listAllTaskRecords(io.agentscope.core.agent.RuntimeContext rc, String agentId, Duration recentWindow) Returns allTaskRecords for the given agent across all sessions that have been active withinrecentWindow, in no particular order.listKnowledgeFiles(io.agentscope.core.agent.RuntimeContext rc) Lists all files under the knowledge directory tree (union of filesystem + local disk).listMemoryFilePaths(io.agentscope.core.agent.RuntimeContext rc) Returns workspace-relative paths of all memory files (MEMORY.mdandmemory/*.md).listSessionLogFiles(io.agentscope.core.agent.RuntimeContext rc) Lists workspace-relative paths of all session log files (*.log.jsonl).listTaskRecords(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId) Returns allTaskRecords for the given agent and session, in insertion order.booleanMove a directory inside the workspace (used by promotion:skills/_drafts/<x>→skills/<x>).readAgentsMd(io.agentscope.core.agent.RuntimeContext rc) Reads AGENTS.md content, returns empty string if not found.readKnowledgeMd(io.agentscope.core.agent.RuntimeContext rc) Reads KNOWLEDGE.md content from the knowledge directory.readManagedWorkspaceFileUtf8(io.agentscope.core.agent.RuntimeContext rc, String relativePath) Reads a UTF-8 file under the workspace, using the two-layer pattern: filesystem first, then local disk fallback.readMemoryMd(io.agentscope.core.agent.RuntimeContext rc) Reads MEMORY.md content (two-layer: filesystem override, local fallback).readTaskRecord(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId, String taskId) Reads a singleTaskRecordby task ID, orOptional.empty()if not found.resolveRuntimeDataPath(io.agentscope.core.agent.RuntimeContext rc, String relativePath) Resolves a workspace-relative path for runtime user data, applying namespace prefix.resolveSessionContextFile(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId) Returns the JSONL session context file path (LLM-facing, compacted).resolveSessionFile(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId) Deprecated.resolveSessionLogFile(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId) Returns the JSONL session log file path (full history, append-only).toWorkspaceRelativeString(Path absoluteUnderWorkspace) Workspace-relative path for indexing.voidupdateSessionIndex(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId, String summary) Upserts metadata for a session inagents/<agentId>/sessions/sessions.json(small mutable JSON, keyed bysessionId).voidvalidate()Validates the workspace exists and key files are present.voidwriteDraftSkillFile(io.agentscope.core.agent.RuntimeContext rc, String relativePath, String content) Write a single file underskills/_drafts/(or whatever drafts dir the caller passes).voidwriteTaskRecord(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId, TaskRecord record) Upserts aTaskRecordinagents/<agentId>/tasks/<sessionId>.json.voidwriteUtf8WorkspaceRelative(io.agentscope.core.agent.RuntimeContext rc, String relativePath, String content) Overwrites a workspace-relative UTF-8 file.
-
Constructor Details
-
WorkspaceManager
-
WorkspaceManager
-
WorkspaceManager
-
WorkspaceManager
public WorkspaceManager(Path workspace, AbstractFilesystem filesystem, WorkspaceIndex index, NamespaceFactory namespaceFactory)
-
-
Method Details
-
close
public void close()Releases the SQLite-backedWorkspaceIndexwhen this manager owns it.Required for tests that use
@TempDiron Windows: the JDBC driver keeps a file handle on.index/workspace.db, and Windows refuses to delete the temp directory while the handle is open.- Specified by:
closein interfaceAutoCloseable
-
getNamespaceFactory
-
getIndex
Returns the best-effort workspace index; may benullwhen unavailable. -
getFilesystem
-
validate
public void validate()Validates the workspace exists and key files are present. Logs warnings for anything missing. Called once at HarnessAgent build time. -
getWorkspace
-
resolveRuntimeDataPath
Resolves a workspace-relative path for runtime user data, applying namespace prefix. Use for paths that contain per-user data (sessions, tasks, memory).The runtime context is forwarded to the
NamespaceFactoryso per-call identity (user/session) drives the namespace, not a shared mutable reference. -
readAgentsMd
Reads AGENTS.md content, returns empty string if not found. -
readKnowledgeMd
Reads KNOWLEDGE.md content from the knowledge directory. -
readMemoryMd
Reads MEMORY.md content (two-layer: filesystem override, local fallback). -
readManagedWorkspaceFileUtf8
public String readManagedWorkspaceFileUtf8(io.agentscope.core.agent.RuntimeContext rc, String relativePath) Reads a UTF-8 file under the workspace, using the two-layer pattern: filesystem first, then local disk fallback. -
getMemoryDir
-
getSkillsDir
-
getKnowledgeDir
-
listKnowledgeFiles
Lists all files under the knowledge directory tree (union of filesystem + local disk). -
getSessionDir
-
resolveSessionFile
@Deprecated public Path resolveSessionFile(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId) Deprecated.UseresolveSessionContextFile(RuntimeContext, String, String)for the JSONL format.Returns the legacy session file path (.json) without creating directories. -
resolveSessionContextFile
public Path resolveSessionContextFile(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId) Returns the JSONL session context file path (LLM-facing, compacted). -
resolveSessionLogFile
public Path resolveSessionLogFile(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId) Returns the JSONL session log file path (full history, append-only). -
appendUtf8WorkspaceRelative
public void appendUtf8WorkspaceRelative(io.agentscope.core.agent.RuntimeContext rc, String relativePath, String content) Appends UTF-8 text to a workspace-relative file, creating parent directories when needed. All writes go through theAbstractFilesystem.A per-path
ReentrantLockserialises concurrent callers so that the read→merge→write cycle is atomic within this process. Across replicas the append is last-writer-wins; this method does not perform CAS. -
updateSessionIndex
public void updateSessionIndex(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId, String summary) Upserts metadata for a session inagents/<agentId>/sessions/sessions.json(small mutable JSON, keyed bysessionId).A per-path
ReentrantLockserialises concurrent callers so that the read→merge→write cycle is atomic within this process. -
writeTaskRecord
public void writeTaskRecord(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId, TaskRecord record) Upserts aTaskRecordinagents/<agentId>/tasks/<sessionId>.json.Reads the existing map, merges or inserts the record keyed by
taskId, then writes the updated map back. Acquires a per-fileReentrantLockto prevent concurrent read-modify-write races when multiple tasks share the same session file. -
readTaskRecord
public Optional<TaskRecord> readTaskRecord(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId, String taskId) Reads a singleTaskRecordby task ID, orOptional.empty()if not found. -
listTaskRecords
public Collection<TaskRecord> listTaskRecords(io.agentscope.core.agent.RuntimeContext rc, String agentId, String sessionId) Returns allTaskRecords for the given agent and session, in insertion order. -
listAllTaskRecords
public Collection<TaskRecord> listAllTaskRecords(io.agentscope.core.agent.RuntimeContext rc, String agentId, Duration recentWindow) Returns allTaskRecords for the given agent across all sessions that have been active withinrecentWindow, in no particular order.Unions task JSON files from the local disk and the filesystem layer. Files whose last modification time (from disk mtime or
FileInfo.modifiedAt()) is known and older thanrecentWindoware skipped: once all tasks in a session reach a terminal state the file is never modified again, so stale files cannot contain orphaned tasks.Used by the orphan-task sweeper in
WorkspaceTaskRepositoryto bound the number of files read per sweep cycle without missing any genuinely running tasks.- Parameters:
agentId- the parent agent identifierrecentWindow- only consider files modified within this duration; files known to be older are assumed to contain only terminal tasks and are skipped
-
writeUtf8WorkspaceRelative
public void writeUtf8WorkspaceRelative(io.agentscope.core.agent.RuntimeContext rc, String relativePath, String content) Overwrites a workspace-relative UTF-8 file. All writes go through the filesystem. -
writeDraftSkillFile
public void writeDraftSkillFile(io.agentscope.core.agent.RuntimeContext rc, String relativePath, String content) Write a single file underskills/_drafts/(or whatever drafts dir the caller passes). When the underlying filesystem is anOverlayFilesystembacked by aRemoteFilesystemlower layer, the draft is written directly to that lower layer so it is visible to other replicas / external approval systems. Otherwise it goes through the standard upper-layer write path.- Parameters:
rc- the runtime context (passed straight through to the filesystem)relativePath- workspace-relative path (must include the drafts prefix)content- UTF-8 content
-
moveSkill
public boolean moveSkill(io.agentscope.core.agent.RuntimeContext rc, String fromRelative, String toRelative) Move a directory inside the workspace (used by promotion:skills/_drafts/<x>→skills/<x>). Best-effort — falls back to the underlying filesystem's nativemovewhen available; returnstrueon success. -
listMemoryFilePaths
Returns workspace-relative paths of all memory files (MEMORY.mdandmemory/*.md). Unions results from theAbstractFilesystemlayer and the local disk, deduplicating by relative path. -
listSessionLogFiles
Lists workspace-relative paths of all session log files (*.log.jsonl). Unions results from theAbstractFilesystemlayer and the local disk. -
toWorkspaceRelativeString
Workspace-relative path for indexing.
-
resolveSessionContextFile(RuntimeContext, String, String)for the JSONL format.