You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AUDIT-06 — High/Medium — Gemini thought parts are appended to the answer #63
Severity: High/Medium Area: Gemini adapter Affected files:agentkit/llm/gemini.py:159-169 Suggested branch:fix/gemini-thought-part-leak Suggested PR title:fix(gemini): exclude thought parts from the model answer
This is finding AUDIT-06 of 18 from a consolidated audit of agentkit/. It is deliberately self-contained so it can be fixed on its own branch with its own PR.
Related findings: Related: AUDIT-05.
AUDIT-06 — High/Medium — Gemini thought parts are appended to the answer
types.Part has a thought flag (google-genai 2.25 Part.thought). The loop never checks it, so internal reasoning text is concatenated into LLMResponse.text, which becomes the assistant turn content (agent.py:210-215), the persisted history, and the final_answer returned to the API client.
Reproduced
part = Part(text="SECRET CHAIN OF THOUGHT", thought=True)
adapter LLMResponse.text == "SECRET CHAIN OF THOUGHT"
Pass cases
A part with thought=True is never included in LLMResponse.text / final_answer / persisted assistant content.
A part with thought=False and text is still returned normally (no regression).
A part carrying both thought=True and a function_call still yields the tool call (and its thought_signature) — the call is not lost.
A regression test asserts the API's answer field contains no thought text for a Gemini response containing a thought part.
Definition of done (per AGENTS.md)
New/updated unit and integration tests covering the pass cases above, all passing (pytest).
ruff check ., ruff format --check . and mypy agentkit clean.
Each issue is self-contained: current code, reproduction, pass cases, suggested branch and PR title. Reference the relevant one with Fixes #NN in your PR.
In \�gentkit/llm/gemini.py, updated candidate content parsing to check \if getattr(part, 'text', None) and not getattr(part, 'thought', False): text_parts.append(part.text).
Preserved tool calls and \ hought_signature\ extraction on parts with both \ hought=True\ and a \unction_call.
Added unit and API endpoint regression tests in \ ests/unit/test_audit_regressions.py\ and \ ests/unit/test_gemini_adapter.py.
All tests passing,
uff\ check & format clean, \mypy\ clean.
Activity
getdownandcode commentedon Oct 20, 2026
Audit index (18 separate issues, fix one by one)
Each issue is self-contained: current code, reproduction, pass cases, suggested branch and PR title. Reference the relevant one with
Fixes #NNin your PR.HamzaKhanBUIC commentedon Oct 20, 2026
Opened PR with fix and regression tests: #78
Summary of Resolution
uff\ check & format clean, \mypy\ clean.