Skip to content

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
ithril-ai:fix/subagent-response-ordering
Open

fix(sdd): ensure sub-agent responses are not lost when ending with tool calls#388
ithril-ai wants to merge 1 commit intoGentleman-Programming:mainfrom
ithril-ai:fix/subagent-response-ordering

Conversation

@ithril-ai
Copy link
Copy Markdown

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 ordering callout 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.md

New Sub-Agent Response Ordering section establishing the universal rule: do work → mem_save → return text as final action.

3. Recovery — sdd-orchestrator.md

New Empty Sub-Agent Response Recovery section 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

  • Sub-agents in the current architecture don't know they ARE sub-agents (system prompt construction is identical — session.parentID is 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...").
  • A future improvement could inject a sub-agent indicator into the system prompt when session.parentID is set, enabling more targeted instructions.

…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
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.

fix(sdd): sub-agent responses lost when last action is a tool call (mem_save)

2 participants