Class SubagentDeclaration

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

public final class SubagentDeclaration extends Object
Declares a subagent: its identity, workspace resolution strategy, and optional capability allowlist.

A declaration binds to exactly one of two source modes:

  1. Definition workspace — getWorkspacePath() points to a workspace directory containing at least AGENTS.md. That file is used as the subagent's system-prompt body. Skills, knowledge, and MEMORY in the definition directory are available when the WorkspaceMode is WorkspaceMode.ISOLATED.
  2. Remote HTTP — getUrl() points to an AgentScope task HTTP server. No local definition workspace or inline body; the subagent runs out-of-process. Mutually exclusive with definition workspace and inline body.

The three source modes are mutually exclusive: at most one of SubagentDeclaration.Builder.workspace(Path), a non-blank SubagentDeclaration.Builder.inlineAgentsBody(String), or a non-blank SubagentDeclaration.Builder.url(String) may be set.

Workspace resolution follows the five-row decision table in WorkspaceMode.

The tools list, when non-empty, acts as an allowlist filter for inherited parent tools: only inherited tools whose names appear in the list are kept. Child-local tool registrations may still be added by the child builder.

Obtain instances via builder().

Example (programmatic):


 SubagentDeclaration decl = SubagentDeclaration.builder()
     .name("code-reviewer")
     .description("Reviews code for security, performance, and readability issues.")
     .workspace(Path.of("./defs/code-reviewer"))
     .workspaceMode(WorkspaceMode.ISOLATED)
     .model("qwen3-max")
     .tools(List.of("read_file", "grep_files", "edit_file"))
     .build();
 
  • Method Details

    • builder

      public static SubagentDeclaration.Builder builder()
      Factory method for a new builder.
    • getName

      public String getName()
      Unique name / agent-id used to reference this subagent.
    • getDescription

      public String getDescription()
      Human-readable description; the main agent uses this to decide when to delegate.
    • getWorkspaceMode

      public WorkspaceMode getWorkspaceMode()
      Workspace resolution strategy. Defaults to WorkspaceMode.ISOLATED when not specified.
    • getWorkspacePath

      public Path getWorkspacePath()
      Path to the definition workspace directory (contains at least AGENTS.md). When null this declaration is in inline mode and getInlineAgentsBody() provides the system prompt.
    • getInlineAgentsBody

      public String getInlineAgentsBody()
      Inline system-prompt body used when getWorkspacePath() is null. May be null or blank if neither a definition workspace nor an inline body is provided.
    • getModel

      public String getModel()
      Optional model override (e.g. "qwen3-max" or "openai:gpt-4o-mini"). When null or blank, the parent model is used.
    • getMaxIters

      @Deprecated public int getMaxIters()
      Deprecated.
      since Phase A — use getSteps(). Returns the same value; kept for source compatibility with callers built before the steps field existed.
      Maximum reasoning iterations. Defaults to 10.
    • getSteps

      public int getSteps()
      Maximum reasoning iterations (default 10). Replaces the historical maxIters field.
    • getTemperature

      public Double getTemperature()
      Optional sampling temperature override (e.g. 0.0 for deterministic compaction-like tasks, 0.7 for creative generation). When null, the parent's GenerateOptions.getTemperature() applies unchanged.
    • getTopP

      public Double getTopP()
      Optional nucleus-sampling override. When null, the parent's GenerateOptions.getTopP() applies unchanged.
    • getVariant

      public String getVariant()
      Optional model variant identifier (e.g. "thinking" for DashScope thinking-mode variants). When null or blank, no variant transform is applied; the parent's variant — if any — is inherited via builder copy.
    • getMode

      public SubagentDeclaration.Mode getMode()
      The SubagentDeclaration.Mode of this declaration. Defaults to SubagentDeclaration.Mode.ALL when not specified — both spawnable and primary-capable.
    • isHidden

      public boolean isHidden()
      Whether this declaration should be hidden from the LLM's view of available subagents. Used for internal subagents (e.g. compaction, summary, title) that the orchestrator should not directly delegate to.
    • isPersistSession

      public boolean isPersistSession()
      Whether the subagent's session state should persist across parent calls. When true, the spawn key is derived deterministically from (parentSessionId, agentId, label), enabling state recovery after process restarts. When false (default), a random UUID is used.
    • isInheritParentPermissions

      public boolean isInheritParentPermissions()
      Whether the subagent inherits parent DENY permission rules. When true (default), all DENY rules from the parent's permission context are propagated to the child's permission engine at spawn time, preventing the child from circumventing parent-level restrictions.
    • getExposeToUser

      public Boolean getExposeToUser()
      Per-type policy for exposing spawned instances of this subagent as user-addressable threads.

      Tri-state:

      • TRUE — always expose, regardless of what the LLM requests on agent_spawn
      • FALSE — never expose (hard opt-out), overriding an LLM expose_to_user=true
      • null (default) — no opinion; defer to the per-call RuntimeContext override and then the LLM's expose_to_user argument

      This is overridden at runtime by a RuntimeContext value keyed AgentSpawnTool#CTX_EXPOSE_TO_USER. See AgentSpawnTool for the full resolution precedence.

    • getEnablePendingToolRecovery

      public Boolean getEnablePendingToolRecovery()
      Recovery policy for orphaned tool calls in an automatically constructed local subagent. null (default) inherits the parent's setting; true or false explicitly overrides it. Remote subagents configure recovery on their own server.
    • getTools

      public List<String> getTools()
      Optional tool allowlist. When non-empty, only inherited parent tools whose names are listed remain on the subagent's inherited toolkit. Empty means inherit all parent tools.
    • getSkills

      public List<String> getSkills()
    • isRemote

      public boolean isRemote()
      Returns true when this declaration targets a remote task HTTP server.
    • getUrl

      public String getUrl()
      Base URL of the remote task server. Non-blank only in remote mode.
    • getHeaders

      public Map<String,String> getHeaders()
      Optional HTTP headers (e.g. auth) sent to the remote task server. Never empty when non-null.
    • isRemoteStreaming

      public boolean isRemoteStreaming()
      Whether remote subagent events (text deltas, tool calls, confirmations) should be streamed back into the parent's live event stream when one is present. Defaults to true when unset.
    • getRemoteStreamDetail

      public RemoteStreamDetail getRemoteStreamDetail()
      How much of the remote event stream to forward. Defaults to RemoteStreamDetail.FULL (lifecycle, tool calls, text and thinking deltas). Use RemoteStreamDetail.VERBOSE to mirror a local subagent's stream in full — block boundaries, tool output deltas, model calls with token usage and every other event — at the cost of more traffic. Only relevant when isRemoteStreaming() is true.
    • getRemoteAskPolicy

      public RemoteAskPolicy getRemoteAskPolicy()
      Policy for resolving remote HITL (tool-confirmation) requests. Defaults to RemoteAskPolicy.DENY, which auto-denies pending confirmations rather than leaving the remote task blocked indefinitely.
    • getRemoteContextAttributes

      public Map<String,Object> getRemoteContextAttributes()
      Static attributes sent as context.attributes with every remote submission, for the remote server to route on or expose to its agent. null when unset; never empty otherwise.
    • hasDefinitionWorkspace

      public boolean hasDefinitionWorkspace()
      Returns true when this declaration points at an external definition workspace.