Skip to content

ADFA-7340 AI-Core: show the model its own native call when it wrote nothing - #188

Draft
davidschachterADFA wants to merge 7 commits into
mainfrom
ai-core/ADFA-7340
Draft

davidschachterADFA wants to merge 7 commits into
mainfrom
ai-core/ADFA-7340

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

ADFA-7340

What: when a natively calling backend's model calls tools and writes nothing, AI Core now stores an assistant turn naming those calls, so the model sees on its next turn that it made them. Before, it often asked for the same call again, and AI Core ended the run without an answer. That was ADFA-7186's symptom, seen with the SQLite debugger's read_sql_template and list_databases on a Note 20 (ADFA-7302, ADFA-7300).

Why it happened:

  • AgentLoop skipped the ASSISTANT turn for a native call with no prose, because Gemini rejects an empty part, and then added the results as a USER turn.
  • AI Agent Claude sends results as user text, not tool_result blocks, and merges same-role turns.
  • So the next request held the user's question with the results appended, and nothing showing the model had made the call.

ClaudeRequestBuilderTest.givenToolResultsAsUserTurns_whenMapped_thenConsecutiveUserTurnsAreMerged shows that merged message.

The change (c3eed33):

  • The turn reads "Calling with key=value." for each call, from agent_loop.yml's new bare_call. In its CALLS value, each argument is on one line and cut to 60 characters, since a file's content can be long.
  • It's never empty, so Gemini accepts it. It's never a <tool_call> envelope, which would invite the model to write its next call as text.
  • The terminal tool alone adds no turn, since the run ends there. A repeat of a successful call also gets the turn, ahead of the "already succeeded" prompt. (A reply with prose kept only its prose here; 98944f3 adds the call text after it, below.)
  • The prompts load from the plugin's own assets, so the new required key can't be missing from a user's copy.
  • The README lists bare_call and CALLS.

The answer review's evidence (b745df4):

  • The device check with 3.7.2 confirmed the repeat is gone. It also showed the answer losing the tool's result: the model's draft held the rendered SQL, and AI Core's answer review removed it. ("The draft's SQL ... doesn't appear in anything the tool returned".)
  • The review checks a reply that holds code against runToolLog. AgentActivity.logEntry builds that log for the exported chat, and it keeps a successful tool's output only for web tools.
  • The review now gets runEvidence from the new AgentActivity.evidenceEntry: every call with its output, clipped as a web result is, within EVIDENCE_CHARS. That's what PromptVariables.EVIDENCE already documents. The exported chat is unchanged.

Review fixes (98944f3, 92c7858): from an independent review of this PR, each re-checked.

  • A native reply with prose and calls now stores the prose, a blank line, then the call text (David's choice), so the model sees those calls too. A text-mode reply keeps its own text, which already holds its calls; the loop tells them apart because only a native reply's text differs from its historyText.
  • The call turn is stored only when the batch runs. A run that ends on a cycle, a repeat or a second repeat no longer saves a call with no result. The repeat-after-success order is kept.
  • The turn names at most 10 calls and 10 arguments per call ("and N more"), and cuts values by code point.
  • The evidence keeps the newest output: whole oldest entries are dropped until the rest fits EVIDENCE_CHARS, in order, with a first line saying how many were left out, and whether the newest was cut to fit. Before, the cut kept the oldest, so a long run lost the output the draft quoted.
  • When the review corrects an answer whose turn also holds call text, the correction is written back with the call text kept.
  • A restored chat is still rebuilt without tool turns, so it has no call text; that's unchanged and its comment says so. AI Agent Gemini's comment about why it merges turns is corrected in addons ADFA-7340 AI Agent Gemini 1.1.1, AI Agent Claude 1.0.1: say why turns still need merging #191.

From the cloud session's review (ee9201b; ADFA-7131 comment 41723, IMPORTANT): with every tool's output kept as evidence, the 60,000-character cut dropped the oldest first, so a web search made before about a dozen read_file pages was pushed out and the review marked versions unverified. Now web and failed outputs are always kept (one rule, AgentActivity.keepsFullOutput, shared with logEntry), and the oldest project outputs are dropped first; the first line says how many were left out. 9d4e81b (41724): the newest output is never dropped, whatever its kind, so five large web results can't push out the rendered SQL the answer quotes; it's cut only if it alone passes the cap.

Version (dab848d): 3.7.2, versionCode 13. addons #183 also takes 3.7.2, so whichever of the two merges second takes the next version.

Tests:

  • AgentLoopBareCallTest (4): a bare call is stored as the model's turn before its results; prose stays the turn; a bare answer adds none; a bare repeat is shown before the prompt that asks for the answer.
  • Two in ToolResultsPromptTest: the wording, and a long argument cut to one short line.
  • Three in AgentActivityTest: a contributed tool's output is kept as evidence, a long output is clipped, and a failure keeps its details. With evidenceEntry made to return logEntry, the output test fails with "... completed" and no output. ChatViewModel's wiring of runEvidence has no view-model test.
  • Local, at b745df4: 1,404 AI Core tests, assemblePlugin and addons check pass, apart from the flaky ChatViewModelCompactionTest.givenARunThatOverflowed_whenRetried_thenTheHistoryIsSummarizedFirstWhateverItsSize. It failed in 3 of 8 runs here and in 1 of 8 on dab848d, it runs no tool, and addons ADFA-7249 | AI-Core: fix the races in three ChatViewModel test classes #176 (ADFA-7249) fixes this class's waits. At dab848d: 1,401 tests pass.
  • Revert proof: with the new block in AgentLoop removed, the bare-call and repeat tests fail with the history [USER, USER, ASSISTANT].
  • For the review fixes: AgentLoopBareCallTest adds prose with one and with several calls, a text-mode reply, several bare calls, a terminal tool beside real calls, and the cycle, repeat and second-repeat endings. AnswerReviewTest adds the order, the cap, the markers and the correction that keeps the call text. ToolResultsPromptTest adds the call and argument limits and a surrogate pair at the cut. The new ChatViewModelBareCallTest runs the shipped wording through the real wiring, with and without prose, and checks the evidence is cleared at a run's start and end. With the fixes reverted, 14 of the 54 targeted tests fail, and each later fix has its own failing test.
  • Local, at 92c7858: 1,430 AI Core tests, assemblePlugin and addons check pass.
  • Local, at 9d4e81b: 1,433 AI Core tests, assemblePlugin and addons check pass; the new test (five large web outputs, then a small rendered SQL) fails with the newest entry back in the drop order. One test (givenWebOutputsAloneOverTheLimit_...) moved its small project entry from newest to oldest, so it no longer shows the project-first rule alone; givenAWebSearchThenManyLargeFileReads_... still does (left as is).
  • Local, at ee9201b: 1,432 AI Core tests, assemblePlugin and addons check pass. The two new evidence tests (a web search then 12 large reads; web outputs alone over the cap) fail with the old drop order.

Device (Note 20, AI Core 3.7.2 at dab848d, ADFA-7302's read_sql_template questions; ADFA-7340 comment 41694):

  • The model answered after one successful call in every check, with no repeat.
  • The answers lacked the SQL; b745df4 addresses that.

Device at b745df4 (ADFA-7340 comment 41697): verified.

  • In C1, C2 and C4 the model answered after one successful call, with no repeat.
  • Each answer holds the rendered SQL: -- notes.db: Room schema matches, the row counts and the orders line with :id in C1, Room schema differs or is not exported with the schema hash changed in C4, and schema_matches=true in C2.
  • The review rewrote C1's and C2's answers and kept the SQL.
  • In C3 the model followed its successful call with a second one passing the app's package as database, which failed. AI Core then showed its stock "the last action failed" message. That's outside this PR (ADFA-7318).

Not yet on a device: the review fixes, 98944f3, 92c7858, ee9201b and 9d4e81b. The Note 20 run is next.

Considered and not done: sending real tool_use/tool_result pairs to native backends. That's more correct, but it changes AI Core and every native backend (Claude, OpenAI, Gemini); David chose this smaller fix.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn

davidschachterADFA and others added 3 commits November 27, 2026 14:08
…othing

When a natively calling backend's model called tools and wrote no prose,
AgentLoop stored no assistant turn (Gemini rejects an empty part) and then
added the results as a user turn. The Claude backend sends results as user
text, not tool_result blocks, and merges same-role turns, so the next
request held the user's question with the results appended, and nothing
showing the model had made the call. It asked for the same call again, and
AI Core ended the run without an answer (ADFA-7186's symptom; seen with
read_sql_template and list_databases on the Note 20, ADFA-7302 and
ADFA-7300).

Such a reply now gets an assistant turn naming its calls in plain words,
"Calling <tool> with key=value.", from agent_loop.yml's new bare_call
(CALLS: each value on one line, cut to 60 characters). It is never empty,
and never a <tool_call> envelope, which would invite text-mode calls. The
terminal tool alone adds none, as the run ends there; a reply with prose
keeps its prose as before.

New tests: AgentLoopBareCallTest (4) and two in ToolResultsPromptTest.
With the new block in AgentLoop removed, the bare-call and the repeat test
fail with the history [USER, USER, ASSISTANT] instead of the model's turn
before its results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
A backwards-compatible fix: PATCH. addons #183 also takes 3.7.2; whichever
of the two merges second takes the next version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…ence

The answer review (ChatViewModel.reviewAnswer), the second request for a
reply that holds code, removes from the draft whatever its evidence does
not hold. Its evidence was runToolLog, built by AgentActivity.logEntry for
the exported chat, which keeps a successful tool's output only for web
tools so that an export does not copy the project. So for every MCP,
contributed or project tool the review saw only "<tool> completed". On the
Note 20 with AI Core 3.7.2 (ADFA-7340 comment 41694), the model's answer
held the rendered SQL from read_sql_template, and the review removed it:
"The draft's SQL ... doesn't appear in anything the tool returned".

The review now gets its own evidence, runEvidence, from the new
AgentActivity.evidenceEntry: every call with its output, clipped as a web
result is, the review still capping the total at EVIDENCE_CHARS. This is
what PromptVariables.EVIDENCE already documents ("What the run's tools
returned, verbatim"). The exported chat keeps logEntry unchanged.

New tests in AgentActivityTest (3). With evidenceEntry made to return
logEntry, the output test fails with "... completed" and no output.
ChatViewModel's wiring has no view-model test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
davidschachterADFA and others added 2 commits November 29, 2026 19:27
…ence

The answer review cut its evidence at 60,000 characters from the end, so after
a few large outputs the newest calls, which the draft quotes, were dropped and
the review stripped the quoted text. It now drops the oldest whole entries and
puts a first line saying how many were left out.

A native reply with prose and calls stored only its prose, so the model could
still repeat the call. It now stores the prose, a blank line and the call text;
text-mode replies, whose text already holds the call, are unchanged. The call
turn is stored only when the batch runs (or a repeat's answer prompt is sent),
so a run ended by the progress guard no longer saves a call with no results.

The rendered call text lists at most 10 calls and 10 arguments per call, builds
its whitespace Regex once and cuts values by code point. Adds tests for these,
for the real bareCall wiring in ChatViewModel, and for the evidence lifetime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
…all text

An evidence entry over the cap alone was cut under a "[0 earlier tool outputs
were left out]" line. Evidence that fits now has no marker, and a cut says so,
with the count of omitted outputs when both happen.

The review located the draft's history turn by its prose alone, which no longer
matches a native reply stored as prose, a blank line and the call text. The
match now accepts that form and keeps the call text when it writes the
correction back.

Adds tests for both, for the start-of-run evidence clear, and for prose plus a
native call reaching the next turn with the shipped wording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
@davidschachterADFA

Copy link
Copy Markdown
Contributor Author

@hal-eisen-adfa Two new commits since you were asked to review (David, 2026-11-28), answering an independent review of this PR: 98944f3 and 92c7858. The description's "Review fixes" section lists them. In short:

  • A native reply with prose and calls now keeps the call text after its prose (David's choice).
  • The call turn is stored only when the batch runs.
  • The answer review's evidence keeps the newest output, not the oldest.
  • A review correction keeps the turn's call text.

1,430 AI Core tests, assemblePlugin and addons check pass locally. This PR is still a draft, and the fixes haven't been on a device yet.

@davidschachterADFA davidschachterADFA left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of #188 at 92c7858278. Draft, base main; checked at this head.

IMPORTANT

  • plugins/AI-Core/src/main/kotlin/com/itsaky/androidide/plugins/aicore/viewmodel/AnswerReview.kt:69 - Newest-first evidence eviction drops the required web_search result once project tool outputs (now kept whole) pass 60k, so the review strips or unverifies sourced versions

Verdict: COMMENT. This PR is authored by the account posting the review, and GitHub refuses APPROVE and REQUEST_CHANGES on your own PR. Severity rules: CodeOnTheGo REVIEW.md and CLAUDE.md (a ticket moves to QA with no outstanding critical, high or medium findings); addons has no written rule, so the default applied.


Generated by Claude Code

ENTRY_SEPARATOR.length * (texts.size - from - 1)
if (size(0) <= EVIDENCE_CHARS) return texts.joinToString(ENTRY_SEPARATOR)
var first = 0
while (first < texts.size - 1 && markerFor(first, false).length + ENTRY_SEPARATOR.length + size(first) > EVIDENCE_CHARS) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMPORTANT: evidenceText now drops the oldest entries first, and that is usually the web search, so the review can lose the only source for the draft's versions.

A run that must search first (VerificationPolicy: code in the message, "latest version", review of attached files) puts web_search first in runEvidence (about 12,000 chars). evidenceEntry now keeps every project tool's output, each read_file page about 4,000 chars. About 12 later reads push the total past EVIDENCE_CHARS, and the search is dropped. answer_review.yml then has the review mark every version not found in the evidence as unverified, or remove its credit to a search. Before this PR, project entries were one line and joined.take(60000) kept the search. Reproduced: one web entry plus five 12k entries gives "[2 earlier tool outputs were left out to fit.]" and no search text.

Always keep the WebAccess.TOOL_NAMES entries, and drop the oldest project outputs first.


Generated by Claude Code

…ce is cut

Cutting the review's evidence by age dropped a web search once a run had read
about a dozen files after it, and the review then marked versions it could no
longer find as unverified. Each entry now carries whether AgentActivity keeps its
output in full (a web tool's or a failure's, the rule logEntry already used),
and the oldest project outputs are left out first. Only when those alone exceed
the cap do the oldest web or failed outputs go. Order and the first-line marker
stay; the marker no longer says "earlier", since a newer file read can be the
one dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
@davidschachterADFA

Copy link
Copy Markdown
Contributor Author

@hal-eisen-adfa One more commit since my last note: ee9201b, from a review by David's cloud session (ADFA-7131 comment 41723). With every tool's output kept as evidence, the 60,000-character cut dropped the oldest first, so a web search made before many read_file pages was pushed out. Now web and failed outputs are always kept, and the oldest project outputs go first. 1,432 AI Core tests, assemblePlugin and addons check pass locally.

About five web results fill the evidence budget alone, and the project output
read after them was then the first thing dropped, which could strip a rendered
SQL template from the answer again. The newest entry is now outside the drop
order whatever its kind; of the older entries the oldest project outputs still go
first, then the oldest web or failed ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
@davidschachterADFA

Copy link
Copy Markdown
Contributor Author

@hal-eisen-adfa One more commit: 9d4e81b, from the cloud session's re-check (ADFA-7131 comment 41724). The answer review's evidence never drops the newest output now, so about five large web results can't push out the rendered SQL the answer quotes. 1,433 AI Core tests, assemblePlugin and addons check pass locally.

davidschachterADFA added a commit that referenced this pull request Nov 30, 2026
…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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Vh2DAYT7GPoC2cDzo8LErn
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.

1 participant