Skip to content

feat: add SubagentTool for task delegation#43

Merged
priyanshujain merged 14 commits intomasterfrom
feat-subagent-tool
Mar 10, 2026
Merged

feat: add SubagentTool for task delegation#43
priyanshujain merged 14 commits intomasterfrom
feat-subagent-tool

Conversation

@priyanshujain
Copy link
Copy Markdown
Collaborator

Summary

  • Adds a subagent tool that lets the parent agent delegate self-contained sub-tasks to a child agent
  • Child runs synchronously with fresh context, reduced maxIter (10), and its own tool registry that excludes subagent (preventing recursion)
  • Wired into both Telegram session and CLI chat

Design

  • Synchronous execution: child blocks parent, same as any other tool
  • Recursion prevention: child's tool registry is built via a factory that omits the subagent tool — max depth is exactly 1
  • No interface changes: Agent, ToolExecutor, Tool, Registry, Provider all unchanged

Files changed

File Change
agent/tools/subagent.go New SubagentTool implementation
agent/tools/subagent_test.go 7 tests covering all behaviors
channel/telegram/session.go Register subagent tool + update prompt
internal/cli/chat.go Register subagent tool + update prompt

Test plan

  • go build ./... compiles without errors
  • go test ./agent/tools/... — all 7 subagent tests pass
  • go test ./... — no new failures (existing Gemini API key failures only)
  • Manual: obk chat → ask to "use a subagent to list files and summarize them"

Implements a subagent tool that spawns a child agent with its own
context, fresh history, and reduced maxIter. The child registry is
built via a factory function that excludes the subagent tool itself,
preventing recursion.
Covers simple task, child tool use, max iterations, no-recursion
guard, context cancellation, empty task, and name verification.
Registers the subagent tool with a factory that provides child agents
with all standard tools except subagent itself.
Registers the subagent tool with a factory that provides child agents
with all standard tools except subagent itself.
Parent and child tool lists were duplicated in telegram session, CLI
chat, and the subagent tool factory. Now all use NewStandardRegistry().
Adds a ## Sub-agents section explaining when to use vs not use the
subagent tool, inspired by patterns from openclaw and zeroclaw.
Avoids real shell execution in unit tests. The stubTool returns a
fixed output, making tests faster and more deterministic.
The judge couldn't distinguish which facts came from memory vs email
because the criteria only marked one memory fact explicitly. Now both
memory facts (Raj Patel role, June 15 deadline) and both email facts
(Sprint 7 Retro, Launch Prep) are enumerated with their source, so
the judge can properly attribute and verify each.
Has checks if a tool is registered by name. ToolNames returns all
registered tool names sorted alphabetically. These will be used to
auto-generate the tool list in system prompts.
…egistry

The tool list is derived from Registry.ToolNames() so it can never
drift out of sync. Sub-agents section is conditionally included based
on whether the subagent tool is registered. Skills section loads the
index dynamically.
Removes the duplicated buildSystemPrompt() function. The tool list
is now auto-generated from the registry.
Removes the duplicated buildSystemPrompt() function and replaces it
with the shared builder. User memory injection extracted into its own
method for clarity.
Removes the third copy of buildSystemPrompt(). The spectest fixture
now uses the same shared builder, with the tool list auto-generated
from its 4-tool registry.
…ompt

"Be concise and direct" was only in the Telegram prompt originally,
not in CLI or spectest. Adding it to the shared prompt caused the
spectest LLMs to skip skill discovery steps. Now it's back in
Telegram's own prompt composition.
@priyanshujain priyanshujain merged commit ccd2152 into master Mar 10, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant