Skip to content

feat: implement delegation mechanism for agent orchestration#84

Open
NamelessNATM wants to merge 1 commit intoJackChen-me:mainfrom
NamelessNATM:main
Open

feat: implement delegation mechanism for agent orchestration#84
NamelessNATM wants to merge 1 commit intoJackChen-me:mainfrom
NamelessNATM:main

Conversation

@NamelessNATM
Copy link
Copy Markdown

What

Adds a built-in delegate_to_agent tool so agents in runTeam / runTasks can synchronously hand a sub-prompt to another roster agent and get that run’s final output as a normal tool result, with pool capacity checks to avoid nested pool.run deadlocks. Built-in registration is opt-in for pool workers (includeDelegateTool); TeamInfo and RunOptions.team carry delegation context, depth limits, and trace/abort forwarding.

Why

Teams already share context via shared memory and messaging, but there was no first-class way to “ask the specialist and get the answer back” inside one agent’s tool loop. This closes that gap using the existing tool protocol and pool semaphore, and prevents indefinite blocking when all concurrency slots are held by agents waiting on nested runs.
Fixes #63

Checklist

  • npm run lint passes
  • npm test passes (30 files, 528 tests)
  • Added/updated tests for changed behavior (tests/built-in-tools.test.ts, tests/agent-pool.test.ts, tests/semaphore.test.ts, etc.)
  • No new runtime dependencies (same stack: Anthropic/OpenAI SDKs, zod, etc.)

- Introduced `delegate_to_agent` tool for orchestrating agent tasks.
- Enhanced `AgentPool` to manage available run slots, preventing deadlocks during nested runs.
- Updated `TeamInfo` and `RunOptions` to support delegation context.
- Added tests for delegation functionality, including error handling for self-delegation and depth limits.
- Refactored built-in tools registration to conditionally include the new delegation tool.
@JackChen-me
Copy link
Copy Markdown
Owner

The deadlock guard from #63 is addressed, and the delegation tool + registration gating look good. Two things:

Blocking:

package-lock.json still has ~300 lines of cross-platform rollup diffs from your local env. Please revert this file so only your actual changes are in the PR.

Non-blocking (can be follow-up PRs):

  • Delegated run token usage isn't accumulated into the parent's AgentRunResult or checked against maxTokenBudget. Fine for now, but worth tracking.
  • No cycle detection for mutual delegation (A delegates to B, B delegates back to A). maxDelegationDepth caps it, but tokens get burned until then.

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.

2 participants