-
Notifications
You must be signed in to change notification settings - Fork 311
perf(agent): orchestrator harness efficiency improvements #1314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
senamakel
merged 10 commits into
tinyhumansai:main
from
M3gA-Mind:feat/1141-orchestrator-efficiency
May 9, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a1ac5b3
perf(agent): orchestrator harness efficiency improvements (#1141)
M3gA-Mind b47a984
fix(test): update orchestrator test to match #1141 tool surface changes
M3gA-Mind 9a688b7
fix(subagent_runner): use char-safe truncation for max_result_chars cap
M3gA-Mind 956c383
fix(orchestrator): align delegation-guide tool names with synthesised…
M3gA-Mind e1481e8
fix(prompts): pass dispatcher_instructions through for Native tool fo…
M3gA-Mind 594463e
fix(dispatch): add 3s timeout to fetch_connected_integrations in rout…
M3gA-Mind 97e5c91
test(subagent_runner,orchestrator_tools): add char-safe and unconnect…
M3gA-Mind da54bb7
fix(test): update orchestrator_lists_memory_tree_tools for consolidat…
M3gA-Mind f9943f7
fix(review): address CodeRabbit feedback on PR #1314
M3gA-Mind c2ffba9
Merge branch 'main' into pr/1314
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Delegation Policy | ||
|
|
||
| ## When to delegate vs. act directly | ||
|
|
||
| The orchestrator follows a direct-first policy. This document codifies the four-tier decision tree the orchestrator applies to every user message. | ||
|
|
||
| ## Tier 1 — Reply directly (no tools) | ||
| Apply when: small talk, simple factual Q&A, acknowledgements, clarification requests, context already in the system prompt. | ||
| Cost: 0 tokens (output only). | ||
| Rule: if you can answer without calling any tool, do so. | ||
|
|
||
| ## Tier 2 — Use a direct tool | ||
| Apply when: the task needs a tool but not specialised execution (time lookup, memory read/write, cron scheduling, workspace state, listing connections). | ||
| Cost: 1 tool call + parse overhead (~200-400 tokens). | ||
| Rule: prefer `current_time`, `cron_*`, `memory_*`, `memory_tree`, `read_workspace_state`, `composio_list_connections`, `ask_user_clarification`. | ||
|
|
||
| ## Tier 3 — Spawn a sub-agent (inline) | ||
| Apply when: the task requires specialised execution (writing code, crawling docs, running shell, calling an external integration) that the orchestrator cannot do directly. | ||
| Cost: full sub-agent turn (~1-5k tokens depending on archetype). | ||
| Rule: spawn the narrowest archetype that can complete the task. Prefer inline spawn (`spawn_worker_thread` with no dedicated thread) for tasks that complete in <5 turns. | ||
|
|
||
| ## Tier 4 — Spawn a dedicated worker thread | ||
| Apply when: the task is long (>5 turns estimated), produces a large transcript, or the user explicitly wants it tracked as a separate thread. | ||
| Cost: same as Tier 3 but the parent thread is not flooded. | ||
| Rule: use `spawn_worker_thread` and surface a brief summary back to the parent. Do not chain workers (workers cannot spawn workers). | ||
|
|
||
| ## Anti-patterns to avoid | ||
| - Spawning a sub-agent to answer a question the orchestrator already has context for. | ||
| - Delegating a tool call to a sub-agent when `current_tier <= 2` applies. | ||
| - Using `spawn_subagent` when `delegate_{archetype}` covers the task — `delegate_*` tools carry the full archetype definition and have correct tool filtering pre-configured. | ||
| - Passing the entire parent conversation as context to a sub-agent — pass only the task-relevant slice. |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drift risk: archetype names in this prose can diverge from the synthesised
delegate_*tools.Step 3 here lists
delegate_run_code,delegate_researcher,delegate_plan,delegate_critic,delegate_archivistas hardcoded markdown. The summary line below repeats them. Meanwhile the source of truth for whichdelegate_*tools actually exist isagents/orchestrator/agent.toml'ssubagents = [...]field, expanded into tool schemas bycollect_orchestrator_tools.If anyone later removes (say)
archivistfromsubagents, the synthesiseddelegate_archivisttool disappears from the API tool schema, but this prompt still tells the LLM to "usedelegate_archivistfor memory writes." The model attempts to call a tool that doesn't exist.This PR did the right thing for integrations —
render_delegation_guidederives the## Connected Integrationsblock from runtime data, so prompt and schema cannot drift. But archetypes still go through hardcoded prose.Two options:
render_delegation_guidealso iteratedefinition.subagentsarchetype entries and emit one line per archetype using each target'swhen_to_use. Then archetypes and integrations share one drift-free source — same guarantee this PR already gives integrations.delegate_<archetype>literal mentioned inprompt.mdappears in the synthesised orchestrator tool set. Catches drift in CI without restructuring the prompt.Either is acceptable; option 1 is the principled fix.