feat(subagents): definition registry, spawn_agent tool, and file-based agents#226
Merged
Conversation
…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.
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.
2 tasks
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SubAgentProfile+SubAgentDefinitionRegistryfor first-class subagent identity management with Internal/UserFacing visibility separationSubAgentSpawnershared utility that spawns subagents as children of the owning session actor (not top-level) for proper supervision and lifecycle managementspawn_agenttool so the frontline LLM can delegate tasks to named subagentsSubAgentDiscoveryContextLayerto advertise available subagents in the system promptFileSubAgentDefinitionLoaderfor operator-defined agents from~/.netclaw/agents/*.jsonwith companion.mdprompt filesnetclaw init: research-assistant, code-analyst, summarizerKey Design Decisions
ToolExecutionContext.SpawnChildActordelegatespawn_agenttool registered inToolIndexUpdater.StartAsync()after MCP discovery completesRelated
Test plan
SubAgentDefinitionRegistryTests— register, lookup, duplicate rejection, visibility filtering (9 tests)FileSubAgentDefinitionLoaderTests— JSON parsing, prompt file resolution, validation, model conversion (9 tests)dotnet slopwatch analyze— zero violationsnetclaw init, verify agent files seeded, verify discovery context layer, invokespawn_agent