From 5249084c090d02bebf239b180b02204d8637f83e Mon Sep 17 00:00:00 2001 From: Sam Schillace Date: Tue, 17 Feb 2026 08:44:10 -0800 Subject: [PATCH] fix: preserve append_to_last_tool_result when merging inject_context HookResults MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _merge_inject_context_results now checks whether ANY result requested append_to_last_tool_result and forwards the flag to the merged HookResult. Previously the field was dropped (defaulting to False), which caused the orchestrator to skip the tool-result merge path and create consecutive same-role messages instead of merging them. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> --- amplifier_core/hooks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/amplifier_core/hooks.py b/amplifier_core/hooks.py index a8abbf0..b9d721e 100644 --- a/amplifier_core/hooks.py +++ b/amplifier_core/hooks.py @@ -236,8 +236,12 @@ def _merge_inject_context_results(self, results: list[HookResult]) -> HookResult result.context_injection for result in results if result.context_injection ) - # Use settings from first result (role, ephemeral, suppress_output) + # Use settings from first result (role, ephemeral, suppress_output). + # Preserve append_to_last_tool_result if ANY result requested it - + # dropping this flag causes the orchestrator to skip the tool-result + # merge path and create consecutive same-role messages instead. first = results[0] + any_append = any(r.append_to_last_tool_result for r in results) return HookResult( action="inject_context", @@ -245,6 +249,7 @@ def _merge_inject_context_results(self, results: list[HookResult]) -> HookResult context_injection_role=first.context_injection_role, ephemeral=first.ephemeral, suppress_output=first.suppress_output, + append_to_last_tool_result=any_append, ) async def emit_and_collect(