Skip to content

feat(subagents): definition registry, spawn_agent tool, and file-based agents#226

Merged
Aaronontheweb merged 6 commits into
devfrom
claude-wt-subagent-design
Mar 14, 2026
Merged

feat(subagents): definition registry, spawn_agent tool, and file-based agents#226
Aaronontheweb merged 6 commits into
devfrom
claude-wt-subagent-design

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Collaborator

Summary

  • Introduces SubAgentProfile + SubAgentDefinitionRegistry for first-class subagent identity management with Internal/UserFacing visibility separation
  • Adds SubAgentSpawner shared utility that spawns subagents as children of the owning session actor (not top-level) for proper supervision and lifecycle management
  • Adds spawn_agent tool so the frontline LLM can delegate tasks to named subagents
  • Adds SubAgentDiscoveryContextLayer to advertise available subagents in the system prompt
  • Adds FileSubAgentDefinitionLoader for operator-defined agents from ~/.netclaw/agents/*.json with companion .md prompt files
  • Seeds 3 built-in agents during netclaw init: research-assistant, code-analyst, summarizer

Key Design Decisions

  • Profiles store tool names (not resolved instances) — decouples definitions from runtime tool lifecycle
  • Subagents are children of the session actor via ToolExecutionContext.SpawnChildActor delegate
  • spawn_agent tool registered in ToolIndexUpdater.StartAsync() after MCP discovery completes
  • Built-in agents are file-based (JSON + MD) seeded during init — operators can customize prompts

Related

Test plan

  • SubAgentDefinitionRegistryTests — register, lookup, duplicate rejection, visibility filtering (9 tests)
  • FileSubAgentDefinitionLoaderTests — JSON parsing, prompt file resolution, validation, model conversion (9 tests)
  • All 1,008 existing tests pass
  • dotnet slopwatch analyze — zero violations
  • Manual: run netclaw init, verify agent files seeded, verify discovery context layer, invoke spawn_agent

…d definitions, and built-in agents

Introduce the complete subagent definition, invocation, and discovery stack:

- SubAgentProfile + SubAgentDefinitionRegistry: first-class definition model
  with Internal/UserFacing visibility separation. Profiles store tool names
  (resolved at spawn time) to decouple from runtime tool state.

- SubAgentSpawner: shared spawn utility that resolves tools, creates child
  actors under the owning session (not top-level), handles observability
  notifications and timeout cascading.

- SpawnAgentTool: user-facing "spawn_agent" tool so the frontline LLM can
  delegate tasks to named subagents. Registered after MCP discovery in
  ToolIndexUpdater.

- SubAgentDiscoveryContextLayer: advertises available subagents in the system
  prompt so the LLM knows what it can delegate to.

- FileSubAgentDefinitionLoader: loads operator-defined agents from
  ~/.netclaw/agents/*.json with optional companion .md prompt files.

- ToolExecutionContext.SpawnChildActor: delegate wired by LlmSessionActor
  to Context.ActorOf so subagents are supervised children of the session.

- Built-in agents seeded during `netclaw init`: research-assistant,
  code-analyst, summarizer — with customizable JSON + markdown prompts.

Closes #184. Partially addresses #183.
…tion

Explains how subagents work end-to-end: how the main agent discovers them
via the context layer on every turn, how spawn_agent is invoked, how to
define custom agents via JSON+MD files, and the built-in agents seeded
during init.
@Aaronontheweb Aaronontheweb marked this pull request as ready for review March 14, 2026 00:18
Keep subagents supervised on the session actor thread, cancel them with parent tool execution, and restrict file-defined agents to a safe user-facing capability set.
Verify spawn_agent emits subagent start events and uses the subagent model prompt without leaking the parent session prompt or user request into the child call.
Restore one completion event per subagent run even when no structured findings are produced, and document the zero-findings completion behavior for observers.
@Aaronontheweb Aaronontheweb merged commit 25ff92f into dev Mar 14, 2026
3 checks passed
@Aaronontheweb Aaronontheweb deleted the claude-wt-subagent-design branch March 14, 2026 04:01
Aaronontheweb added a commit that referenced this pull request Apr 14, 2026
PR #652 migrated sub-agent definitions from JSON+MD sidecar pairs to single
markdown files with YAML frontmatter, added an optional Context parameter to
spawn_agent, and enriched the [available-subagents] discovery context layer
to include per-agent description, tools, and an example call. None of that
was reflected in the runbook — anyone following the existing "Defining
subagents" section would write a .json file the loader rejects.

Rewrite docs/runbooks/subagents.md end to end:

- Discovery section shows the new enriched block (per-agent description +
  tools + timeout + a how-to-delegate block with the context field example)
  instead of the old one-line form.
- Invocation section documents all three spawn_agent arguments (agent, task,
  context) with one null-context and one context-populated example. Clarifies
  that Context is prefixed onto the subagent's first user message as a
  Context:/Task: block, and that the agent's system prompt stays verbatim
  from disk (not mutated by runtime context).
- Defining subagents section replaces the JSON schema + companion-file
  walkthrough with a single markdown-with-frontmatter template. Documents
  every frontmatter field with required/default columns: name, description,
  tools, modelRole, timeoutSeconds, visibility (hyphenated or PascalCase),
  emitStructuredFindings. Adds a loader-behavior-fail-loud subsection listing
  every rejection reason the scanner can log.
- Creating a custom agent walkthrough now writes a single .md file with
  frontmatter instead of a JSON+MD pair.
- Limitations section gains an entry noting that per-agent model selection
  is not yet supported and is blocked on the multi-model provider follow-on.

Also update IMPLEMENTATION_PLAN.md line 969 — the "Subagent Roadmap" entry
still listed the JSON file format. Updated minimally to reference the new
format and cite both #226 (original disk-based design) and #652 (migration
to frontmatter).

Historical references in RELEASE_NOTES.md are left alone — they accurately
describe what shipped at #226 and shouldn't be retconned.
@Aaronontheweb Aaronontheweb added the subagents spawn_agent, SubAgentActor, definition loader, discovery context layer, and related features label Apr 14, 2026
Aaronontheweb added a commit that referenced this pull request Apr 14, 2026
PR #652 migrated sub-agent definitions from JSON+MD sidecar pairs to single
markdown files with YAML frontmatter, added an optional Context parameter to
spawn_agent, and enriched the [available-subagents] discovery context layer
to include per-agent description, tools, and an example call. None of that
was reflected in the runbook — anyone following the existing "Defining
subagents" section would write a .json file the loader rejects.

Rewrite docs/runbooks/subagents.md end to end:

- Discovery section shows the new enriched block (per-agent description +
  tools + timeout + a how-to-delegate block with the context field example)
  instead of the old one-line form.
- Invocation section documents all three spawn_agent arguments (agent, task,
  context) with one null-context and one context-populated example. Clarifies
  that Context is prefixed onto the subagent's first user message as a
  Context:/Task: block, and that the agent's system prompt stays verbatim
  from disk (not mutated by runtime context).
- Defining subagents section replaces the JSON schema + companion-file
  walkthrough with a single markdown-with-frontmatter template. Documents
  every frontmatter field with required/default columns: name, description,
  tools, modelRole, timeoutSeconds, visibility (hyphenated or PascalCase),
  emitStructuredFindings. Adds a loader-behavior-fail-loud subsection listing
  every rejection reason the scanner can log.
- Creating a custom agent walkthrough now writes a single .md file with
  frontmatter instead of a JSON+MD pair.
- Limitations section gains an entry noting that per-agent model selection
  is not yet supported and is blocked on the multi-model provider follow-on.

Also update IMPLEMENTATION_PLAN.md line 969 — the "Subagent Roadmap" entry
still listed the JSON file format. Updated minimally to reference the new
format and cite both #226 (original disk-based design) and #652 (migration
to frontmatter).

Historical references in RELEASE_NOTES.md are left alone — they accurately
describe what shipped at #226 and shouldn't be retconned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

subagents spawn_agent, SubAgentActor, definition loader, discovery context layer, and related features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add internal agent definition support for platform-owned subagents

1 participant