Thread root agent's system_prompt into sub-agent decomposition prompts - #151
Thread root agent's system_prompt into sub-agent decomposition prompts#151acdonaire wants to merge 2 commits into
Conversation
The parallel/sequential/hybrid decomposition prompt templates in DecompositionEngine were hardcoded English text with no awareness of the root agent's configured language or persona. In AgentMode.AUTO/ SUB_AGENTS, this meant generated subtask descriptions (and their internal reasoning) could be in English even when system_prompt asked for another language — verified empirically: a Spanish task with system_prompt="Responde siempre en español" produced a subtask literally titled "synthesis_specialist" with instruction "Synthesize the findings...". Fix: agent_orchestration.py now threads the agent's system_prompt into the context dict passed to SubAgentRouter.route(), and DecompositionEngine._llm_decompose() uses it to add an explicit language instruction to the LLM decomposition prompt. No-op when system_prompt is unset or when DecompositionEngine/SubAgentRouter are used standalone without a parent Agent — behavior is unchanged in both cases. Tests: 137/137 passing across test_agent_decomposition.py, test_agent_module_layout.py, and test_orchestration.py. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JGxRqBhgH19YxWzGyrXqJr
Two related gaps, both stemming from the same root cause (system_prompt not propagating past the root agent): - sub_agent_manager.py: each specialization's default system_prompt (research/coding/analysis/synthesis/general) is a fixed English persona. The parent's model is reused (`model="inherit"`) but its system_prompt never was — spawned children kept an English persona regardless of the parent's configured language. Now appends a note derived from the parent's system_prompt, when set. - orchestrator.py (defensive, lower severity): the hierarchical team's decomposition/synthesis prompts are fixed English text. This path already applies the manager's own system_prompt via a normal Agent.run() call, unlike DecompositionEngine's raw generate() bypass (see ctrl-gaurav#151), so it was less exposed — added an explicit language note anyway to remove ambiguity in the delegation-format instruction. Found while auditing the codebase for the same class of bug fixed in ctrl-gaurav#151. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JGxRqBhgH19YxWzGyrXqJr
Two related gaps, both stemming from the same root cause (system_prompt not propagating past the root agent): - sub_agent_manager.py: each specialization's default system_prompt (research/coding/analysis/synthesis/general) is a fixed English persona. The parent's model is reused (`model="inherit"`) but its system_prompt never was — spawned children kept an English persona regardless of the parent's configured language. Now appends a note derived from the parent's system_prompt, when set. - orchestrator.py (defensive, lower severity): the hierarchical team's decomposition/synthesis prompts are fixed English text. This path already applies the manager's own system_prompt via a normal Agent.run() call, unlike DecompositionEngine's raw generate() bypass (see #151), so it was less exposed — added an explicit language note anyway to remove ambiguity in the delegation-format instruction. Found while auditing the codebase for the same class of bug fixed in #151.
|
Merged into Your commits landed with your authorship intact:
Why this shows as closed rather than merged: the commits were replayed onto The code went in unchanged. Two things I checked specifically, because both would have been quiet failures:
Your "no-op when unset" claim held up: I asserted the decomposition prompt is byte-identical with no One thing needed fixing before it could land ( I also added One small comment tidy in |
Problem
DecompositionEngine's parallel/sequential/hybrid prompt templates are
hardcoded in English and don't inherit the root agent's system_prompt.
In AgentMode.AUTO/SUB_AGENTS, this can leak English-language reasoning
into generated subtasks regardless of the agent's configured language —
found while testing PR #150's Spanish keyword support with a real
multi-agent run.
Solution
Thread system_prompt through context (root agent -> SubAgentRouter.route
-> DecompositionEngine.decompose) and use it to add an explicit language
instruction to the LLM decomposition prompt. No-op when system_prompt
is unset.
Validation
the language instruction when system_prompt is set, and is byte-identical
to before when it isn't
🤖 Generated with Claude Code
https://claude.ai/code/session_01JGxRqBhgH19YxWzGyrXqJr