fix(sdd): ensure sub-agent responses are not lost when ending with tool calls#388
Open
ithril-ai wants to merge 1 commit intoGentleman-Programming:mainfrom
Open
fix(sdd): ensure sub-agent responses are not lost when ending with tool calls#388ithril-ai wants to merge 1 commit intoGentleman-Programming:mainfrom
ithril-ai wants to merge 1 commit intoGentleman-Programming:mainfrom
Conversation
…ol calls When a sub-agent's last action is a tool call (mem_save, mem_session_summary), the parent/orchestrator only receives the tool result — the actual analysis text is lost. Three-layer fix: - sdd-phase-common.md Section D: text-last rule for return envelope - persistence-contract.md: Sub-Agent Response Ordering section - sdd-orchestrator.md: Empty Sub-Agent Response Recovery (retry with task_id) Closes Gentleman-Programming#387
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #387
When a sub-agent's last action is a tool call (
mem_save,mem_session_summary), the parent/orchestrator agent only receives the tool result (e.g., "Observation saved") instead of the sub-agent's actual text response containing the analysis and return envelope.This has been running in production for several weeks with consistent success.
Changes
Three-layer defense-in-depth fix across 3 files (~20 lines total):
1. Prevention —
sdd-phase-common.md(Section D)Added a
CRITICAL — Response orderingcallout at the top of the Return Envelope section: final output MUST be text, not a tool call. Explains why (parent loses the response).2. Prevention —
persistence-contract.mdNew
Sub-Agent Response Orderingsection establishing the universal rule:do work → mem_save → return text as final action.3. Recovery —
sdd-orchestrator.mdNew
Empty Sub-Agent Response Recoverysection for the orchestrator: when a sub-agent returns empty/tool-result-only output, resume the same task_id asking for the text response instead of launching a new sub-agent (which wastes tokens and discards context).Why both prevention AND recovery?
LLMs don't always follow instructions perfectly. The prevention layer (files 1 & 2) handles ~95% of cases. The recovery layer (file 3) catches the remaining ~5% where the sub-agent still ends with a tool call despite explicit instructions.
Additional context
session.parentIDis only used for HTTP headers). So the prevention rules are written as unconditional ("always end with text") rather than conditional ("if you are a sub-agent...").session.parentIDis set, enabling more targeted instructions.