Class AgentSpecLoader

java.lang.Object
io.agentscope.harness.agent.subagent.AgentSpecLoader

public final class AgentSpecLoader extends Object
Loads SubagentDeclaration instances from Markdown files with YAML front matter placed in the subagents/ directory of a workspace.

File naming: the filename (without the .md extension) becomes the subagent's name / agent-id. The front matter must not contain a name field.

Scan strategy: only direct children of the given directory are scanned (non-recursive) to prevent accidentally loading files that live inside a definition workspace that happens to be stored under the same parent.

File format:

 ---
 description: Reviews code for security and performance issues.
 workspace:
   mode: isolated          # isolated | shared  (default: isolated)
   path: ./defs/reviewer   # optional; relative to mainWorkspace, or absolute
 model: qwen3-max          # optional model override
 maxIters: 12              # optional (default 10)
 tools: [read_file, grep_files, edit_file]   # optional allowlist
 ---

 # Inline body (only when workspace.path is absent)
 You are a code reviewer...
 

Rules:

  • description is required.
  • When workspace.path is present, the Markdown body must be blank; the subagent's system prompt is read from <workspace.path>/AGENTS.md at runtime.
  • When workspace.path is absent, the Markdown body (if any) becomes the inline SubagentDeclaration.getInlineAgentsBody().
  • Method Details

    • loadFromDirectory

      public static List<SubagentDeclaration> loadFromDirectory(Path subagentsDir, Path mainWorkspace)
      Non-recursively scans subagentsDir for .md files and parses each into a SubagentDeclaration.
      Parameters:
      subagentsDir - the subagents/ directory to scan
      mainWorkspace - the parent workspace used to resolve relative workspace.path values; may be null (relative paths will remain relative)
      Returns:
      list of parsed declarations; never null
    • loadFromFilesystem

      public static List<SubagentDeclaration> loadFromFilesystem(AbstractFilesystem filesystem, Path mainWorkspace)
      Loads subagent declarations via the AbstractFilesystem using an empty runtime context. Scans subagents/ for *.md files using filesystem glob.

      Use loadFromFilesystem(AbstractFilesystem, RuntimeContext, Path) when declarations are scoped to a calling user's namespace.

      Parameters:
      filesystem - the filesystem layer (applies namespace transparently)
      mainWorkspace - the parent workspace for resolving relative workspace paths; may be null
      Returns:
      list of parsed declarations; never null
    • loadFromFilesystem

      public static List<SubagentDeclaration> loadFromFilesystem(AbstractFilesystem filesystem, io.agentscope.core.agent.RuntimeContext runtimeContext, Path mainWorkspace)
      Loads subagent declarations via the AbstractFilesystem, respecting the supplied runtime context's namespace isolation.
      Parameters:
      filesystem - the filesystem layer (applies namespace transparently)
      runtimeContext - the call context used to resolve namespace-scoped declarations
      mainWorkspace - the parent workspace for resolving relative workspace paths; may be null
      Returns:
      list of parsed declarations; never null
    • loadFromFile

      public static SubagentDeclaration loadFromFile(Path filePath, Path mainWorkspace) throws IOException
      Parses a single Markdown declaration file.
      Parameters:
      filePath - the .md file to parse
      mainWorkspace - workspace root used to resolve relative workspace.path values; may be null
      Returns:
      parsed declaration, or null if the file is malformed / missing required fields
      Throws:
      IOException
    • parse

      public static SubagentDeclaration parse(String markdown, String name, Path mainWorkspace)
      Parses markdown content with YAML front matter into a SubagentDeclaration.
      Parameters:
      markdown - the full file content
      name - the subagent name (derived from the filename, without .md)
      mainWorkspace - workspace root used to resolve relative workspace.path values; may be null
      Returns:
      parsed declaration, or null if the content is malformed