Skip to content

feat(runtime): generic task tool + semaphore + nesting guard (#454) - #459

Merged
smallnest merged 1 commit into
masterfrom
feat/node-454-task-tool
Jul 31, 2026
Merged

feat(runtime): generic task tool + semaphore + nesting guard (#454)#459
smallnest merged 1 commit into
masterfrom
feat/node-454-task-tool

Conversation

@smallnest

Copy link
Copy Markdown
Owner

Summary

Implements node #454 of the subagent-orchestration graph: a generic task tool that lets the model dispatch general-purpose sub-agents with a runtime prompt, enabling single-message fan-out.

  • New internal/runtime/task.go: NewTaskTool(factory, sem) builds a generic SubAgentTool spec (generic system prompt, {description?, prompt} schema, parallel exec mode). MaxSubagents()/NewSubagentSemaphore() resolve the concurrency cap (default 4, PIGO_MAX_SUBAGENTS override, invalid/absent -> 4, floor 1).
  • Generalize SubAgentTool (subagent.go): optional Schema override + shared Sem semaphore acquired/released in executeGoroutine (blocks/queues when full, ctx-cancel aware, released via defer). Existing prompt-only specs and all existing subagent tests are unaffected.
  • Wire the task tool into run.SetupEnv (internal/cli/run/run.go) with a child RunConfig factory reusing the resolved provider stream/model and an env-resolved credential store. BuiltinToolsExcept(cwd, disabled, "task") builds the child registry without task (nesting guard: depth capped at 1).

Progress reporting is intentionally NOT included here — SubAgentProgressEvent does not yet exist on master (parallel node #453) and is added on top in #455.

Test plan

  • go build ./..., go vet ./..., go test ./... all pass
  • task returns child final text; child failure -> tool error
  • semaphore: N > cap dispatched, peak concurrent children never exceeds cap (blocking fake tool + counter)
  • child tool set excludes task (BuiltinToolsExcept)
  • existing orchestration_test.go / subagent_process_test.go still green (no regression)

Closes #454

…454)

Add a general-purpose `task` sub-agent tool the model can dispatch with a
runtime prompt to fan out work in one message. Generalize SubAgentTool with
an optional argument-schema override and a shared concurrency semaphore
(acquired/released in executeGoroutine), then wire the tool into run.SetupEnv
with a child RunConfig factory reusing the resolved provider stream/model.

- task schema: {description?, prompt} with prompt required; parallel exec mode
- semaphore: default 4, PIGO_MAX_SUBAGENTS override (invalid/absent -> 4, floor 1)
- nesting guard: BuiltinToolsExcept builds the child registry without "task"
- child failure surfaces as a tool error; existing subagent tests unchanged

No progress events are emitted here; SubAgentProgressEvent lands in #455.

Refs #454
@smallnest
smallnest merged commit b4ce694 into master Jul 31, 2026
1 check 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.

通用 task 工具 + 接线 + 信号量 + 嵌套护栏

1 participant