From 75e5bd58987187f2ee16ffd59afe29f686f39cb9 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Sun, 29 Nov 2026 19:16:36 -0800 Subject: [PATCH 1/7] ADFA-7340 AI-Agent-Gemini: say why turns still need merging The comment on buildContents said the transcript stops alternating because AI Core's agent loop drops an ASSISTANT turn that carried only a native call. ADFA-7340 (addons #188) makes AI Core store a turn naming that call, so the reason is out of date. The merge is still needed: SYSTEM and TOOL turns go as user turns here, and chats saved by an older AI Core still have the user message and its tool results side by side. Comment only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn --- .../plugins/aiagentgemini/backend/GeminiBackend.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt index a858f48f8..7ba4217e5 100644 --- a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt +++ b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt @@ -476,9 +476,10 @@ class GeminiBackend( /** * Builds the `contents[]` array for a multi-turn request. * - * Consecutive same-role turns are merged into one content, because the transcript no longer - * always alternates: the agent loop drops an ASSISTANT turn that carried only a native call - * and no prose, leaving the user message and the tool results it produced adjacent. + * Consecutive same-role turns are merged into one content, because the transcript does not + * always alternate. SYSTEM and TOOL turns go as user turns here. And a chat saved by an AI Core + * that dropped the ASSISTANT turn of a native call made with no prose (fixed in ADFA-7340) has + * the user message and the tool results it produced side by side. * * The system prompt is NOT one of these turns: [buildRequestJson] sends it as the request's * `systemInstruction`, where the API privileges it over anything a later turn says. From 8d22cfddd204a0aa0bb33b5842b1c3e53057532c Mon Sep 17 00:00:00 2001 From: David Schachter Date: Sun, 29 Nov 2026 19:16:36 -0800 Subject: [PATCH 2/7] ADFA-7340 AI-Agent-Gemini: version 1.1.1 A PATCH bump for the comment change, as the repository's CLAUDE.md asks of any change to a plugin. versionCode 3. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn --- plugins/AI-Agent-Gemini/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/AI-Agent-Gemini/build.gradle.kts b/plugins/AI-Agent-Gemini/build.gradle.kts index 1c097631a..894d05de4 100644 --- a/plugins/AI-Agent-Gemini/build.gradle.kts +++ b/plugins/AI-Agent-Gemini/build.gradle.kts @@ -15,8 +15,8 @@ android { applicationId = "com.itsaky.androidide.plugins.aiagentgemini" minSdk = 33 targetSdk = 36 - versionCode = 2 - versionName = "1.1.0" + versionCode = 3 + versionName = "1.1.1" } buildTypes { From b91dc64599c29f6659c8e83de45847cbd5342896 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Sun, 29 Nov 2026 19:35:20 -0800 Subject: [PATCH 3/7] ADFA-7340 AI-Agent-Gemini: name the restore as the other reason turns repeat The first wording said a chat saved by an older AI Core keeps the user message and its tool results side by side. A restored chat is rebuilt from its messages and keeps no tool turns, so that was wrong. What the rebuild does leave out is an agent reply that held only a native call, or that never finished, which can put two user turns in a row, before and after ADFA-7340. Comment only; the version stays 1.1.1. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn --- .../plugins/aiagentgemini/backend/GeminiBackend.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt index 7ba4217e5..9aec19aa3 100644 --- a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt +++ b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt @@ -477,9 +477,9 @@ class GeminiBackend( * Builds the `contents[]` array for a multi-turn request. * * Consecutive same-role turns are merged into one content, because the transcript does not - * always alternate. SYSTEM and TOOL turns go as user turns here. And a chat saved by an AI Core - * that dropped the ASSISTANT turn of a native call made with no prose (fixed in ADFA-7340) has - * the user message and the tool results it produced side by side. + * always alternate. SYSTEM and TOOL turns go as user turns here. And a chat AI Core restores + * from its messages can hold user turns in a row: the rebuild leaves out an agent reply that + * held only a native call, or that never finished. * * The system prompt is NOT one of these turns: [buildRequestJson] sends it as the request's * `systemInstruction`, where the API privileges it over anything a later turn says. From a6c511a94c29affa7e5699c959d876adae2a4d42 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Sun, 29 Nov 2026 23:37:29 -0800 Subject: [PATCH 4/7] ADFA-7340 AI-Agent-Gemini, AI-Agent-Claude: the real reasons turns repeat An independent review of this PR found the Gemini comment true but incomplete, and AI Agent Claude's overstated: - AI Core's agent loop stores no assistant turn for a reply with no text, so the user turn it adds next (asking the model to go on, or for a required tool) follows the previous user turn. That holds with ADFA-7340 too, which adds a turn only for a reply that called tools. - A chat AI Core restores leaves out an agent reply that had no text or never finished, and starts with the compaction summary as a user turn. - AI Core sends no SYSTEM or TOOL turns; other callers may. Claude's comment said results as user text "leave runs" of same-role turns; with ADFA-7340 the results follow the stored call turn, so it now names the cases above. Comments only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn --- .../aiagentclaude/backend/ClaudeRequestBuilder.kt | 5 +++-- .../plugins/aiagentgemini/backend/GeminiBackend.kt | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt b/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt index 27ad8b86d..c2f2db924 100644 --- a/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt +++ b/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt @@ -64,8 +64,9 @@ internal object ClaudeRequestBuilder { * The caller hands tool results back as ordinary text — a USER turn wrapping each result, or * a TOOL turn — and never the assistant `tool_use` block they answer, so they are sent as user * text rather than as `tool_result` blocks, which the API rejects without a matching call. - * That leaves runs of same-role turns, which are merged into one; blank turns are dropped, - * since the API refuses an empty text block. SYSTEM turns join the top-level system prompt: + * Runs of same-role turns still occur (AI Core stores no assistant turn for a reply with no + * text, and a restored chat can start with two user turns) and are merged into one; blank + * turns are dropped, since the API refuses an empty text block. SYSTEM turns join the top-level system prompt: * the API has no system role inside `messages[]` that every model accepts. * * @param history the conversation so far, oldest first diff --git a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt index 9aec19aa3..1bd5e2f12 100644 --- a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt +++ b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt @@ -476,10 +476,12 @@ class GeminiBackend( /** * Builds the `contents[]` array for a multi-turn request. * - * Consecutive same-role turns are merged into one content, because the transcript does not - * always alternate. SYSTEM and TOOL turns go as user turns here. And a chat AI Core restores - * from its messages can hold user turns in a row: the rebuild leaves out an agent reply that - * held only a native call, or that never finished. + * Consecutive same-role turns are merged into one content, because the history a caller passes + * does not always alternate. AI Core's agent loop stores no assistant turn for a reply with no + * text, so a user turn it adds next (asking the model to go on, or for a required tool) follows + * the previous user turn. A chat AI Core restores from its messages leaves out an agent reply + * that had no text or never finished, and starts with the compaction summary as a user turn. + * SYSTEM and TOOL turns, which other callers may send, also go as user turns here. * * The system prompt is NOT one of these turns: [buildRequestJson] sends it as the request's * `systemInstruction`, where the API privileges it over anything a later turn says. From 803c6b8ab6f6e95481c4ef6217279a0b14a87aa8 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Sun, 29 Nov 2026 23:37:29 -0800 Subject: [PATCH 5/7] ADFA-7340 AI-Agent-Claude: version 1.0.1 A PATCH bump for the comment change, as the repository's CLAUDE.md asks of any change to a plugin. versionCode 2. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn --- plugins/AI-Agent-Claude/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/AI-Agent-Claude/build.gradle.kts b/plugins/AI-Agent-Claude/build.gradle.kts index bd5805663..bc046b328 100644 --- a/plugins/AI-Agent-Claude/build.gradle.kts +++ b/plugins/AI-Agent-Claude/build.gradle.kts @@ -15,8 +15,8 @@ android { applicationId = "com.itsaky.androidide.plugins.aiagentclaude" minSdk = 33 targetSdk = 36 - versionCode = 1 - versionName = "1.0.0" + versionCode = 2 + versionName = "1.0.1" } buildTypes { From 30e8606ca77a259fdbf276aa73f4ff48070ea36c Mon Sep 17 00:00:00 2001 From: David Schachter Date: Sun, 29 Nov 2026 23:40:41 -0800 Subject: [PATCH 6/7] ADFA-7340 AI-Agent-Gemini, AI-Agent-Claude: a reply with no text and no call The re-check of a6c511a9: with ADFA-7340, AI Core stores a turn for a reply that called tools even when it has no text, so the case that leaves two user turns in a row is a reply with no text and no call. Both comments say so, and the Claude one is rewrapped. Comments only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn --- .../plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt | 7 ++++--- .../plugins/aiagentgemini/backend/GeminiBackend.kt | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt b/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt index c2f2db924..11454063d 100644 --- a/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt +++ b/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt @@ -65,9 +65,10 @@ internal object ClaudeRequestBuilder { * a TOOL turn — and never the assistant `tool_use` block they answer, so they are sent as user * text rather than as `tool_result` blocks, which the API rejects without a matching call. * Runs of same-role turns still occur (AI Core stores no assistant turn for a reply with no - * text, and a restored chat can start with two user turns) and are merged into one; blank - * turns are dropped, since the API refuses an empty text block. SYSTEM turns join the top-level system prompt: - * the API has no system role inside `messages[]` that every model accepts. + * text and no call, and a restored chat can start with two user turns) and are merged into + * one; blank turns are dropped, since the API refuses an empty text block. SYSTEM turns join + * the top-level system prompt: the API has no system role inside `messages[]` that every model + * accepts. * * @param history the conversation so far, oldest first * @param prompt the current user turn, appended last diff --git a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt index 1bd5e2f12..2cea43351 100644 --- a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt +++ b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt @@ -478,10 +478,10 @@ class GeminiBackend( * * Consecutive same-role turns are merged into one content, because the history a caller passes * does not always alternate. AI Core's agent loop stores no assistant turn for a reply with no - * text, so a user turn it adds next (asking the model to go on, or for a required tool) follows - * the previous user turn. A chat AI Core restores from its messages leaves out an agent reply - * that had no text or never finished, and starts with the compaction summary as a user turn. - * SYSTEM and TOOL turns, which other callers may send, also go as user turns here. + * text and no call, so a user turn it adds next (asking the model to go on, or for a required + * tool) follows the previous user turn. A chat AI Core restores from its messages leaves out + * an agent reply that had no text or never finished, and starts with the compaction summary as + * a user turn. SYSTEM and TOOL turns, which other callers may send, also go as user turns here. * * The system prompt is NOT one of these turns: [buildRequestJson] sends it as the request's * `systemInstruction`, where the API privileges it over anything a later turn says. From e601ddf1092766a523c42436a8252166d453e861 Mon Sep 17 00:00:00 2001 From: David Schachter Date: Mon, 30 Nov 2026 10:43:38 -0800 Subject: [PATCH 7/7] ADFA-7340 Gemini and Claude KDoc: hold whether or not AI Core stores a bare native call The comments said AI Core stores no assistant turn "for a reply with no text and no call", which implies a reply that is only a native call is stored. On AI Core without ADFA-7340 (addons #188) it is not: the loop stores nothing for blank text and then adds the tool results as a user turn, which is the most common run of same-role turns. Both comments now say so, and that AI Core from ADFA-7340 on stores a turn naming the call. (Review on addons #191, ADFA-7131 comment 41750.) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn --- .../aiagentclaude/backend/ClaudeRequestBuilder.kt | 10 +++++----- .../plugins/aiagentgemini/backend/GeminiBackend.kt | 11 +++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt b/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt index 11454063d..2ea74bb93 100644 --- a/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt +++ b/plugins/AI-Agent-Claude/src/main/kotlin/com/itsaky/androidide/plugins/aiagentclaude/backend/ClaudeRequestBuilder.kt @@ -64,11 +64,11 @@ internal object ClaudeRequestBuilder { * The caller hands tool results back as ordinary text — a USER turn wrapping each result, or * a TOOL turn — and never the assistant `tool_use` block they answer, so they are sent as user * text rather than as `tool_result` blocks, which the API rejects without a matching call. - * Runs of same-role turns still occur (AI Core stores no assistant turn for a reply with no - * text and no call, and a restored chat can start with two user turns) and are merged into - * one; blank turns are dropped, since the API refuses an empty text block. SYSTEM turns join - * the top-level system prompt: the API has no system role inside `messages[]` that every model - * accepts. + * Runs of same-role turns still occur and are merged into one: AI Core stores no assistant turn + * for a reply with no text, which before ADFA-7340 includes a native call made with no prose, + * and a restored chat can start with two user turns. Blank turns are dropped, since the API + * refuses an empty text block. SYSTEM turns join the top-level system prompt: the API has no + * system role inside `messages[]` that every model accepts. * * @param history the conversation so far, oldest first * @param prompt the current user turn, appended last diff --git a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt index 2cea43351..990e0487e 100644 --- a/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt +++ b/plugins/AI-Agent-Gemini/src/main/kotlin/com/itsaky/androidide/plugins/aiagentgemini/backend/GeminiBackend.kt @@ -478,10 +478,13 @@ class GeminiBackend( * * Consecutive same-role turns are merged into one content, because the history a caller passes * does not always alternate. AI Core's agent loop stores no assistant turn for a reply with no - * text and no call, so a user turn it adds next (asking the model to go on, or for a required - * tool) follows the previous user turn. A chat AI Core restores from its messages leaves out - * an agent reply that had no text or never finished, and starts with the compaction summary as - * a user turn. SYSTEM and TOOL turns, which other callers may send, also go as user turns here. + * text, and sends tool results as a user turn. So the results of a native call made with no + * prose follow the previous user turn directly, unless AI Core stores a turn naming the call + * (it does from ADFA-7340 on; older versions don't). The same happens when it asks the model + * to go on, or for a required tool, after an empty reply. A chat AI Core restores from its + * messages leaves out an agent reply that had no text or never finished, and starts with the + * compaction summary as a user turn. SYSTEM and TOOL turns, which other callers may send, also + * go as user turns here. * * The system prompt is NOT one of these turns: [buildRequestJson] sends it as the request's * `systemInstruction`, where the API privileges it over anything a later turn says.