Skip to content

fix(gemini): exclude thought parts from the model answer - #78

Closed
HamzaKhanBUIC wants to merge 1 commit into
getdownandcode:mainfrom
HamzaKhanBUIC:fix/gemini-thought-part-leak
Closed

HamzaKhanBUIC wants to merge 1 commit into
getdownandcode:mainfrom
HamzaKhanBUIC:fix/gemini-thought-part-leak

Conversation

@HamzaKhanBUIC

Copy link
Copy Markdown

Summary

Fixes #63 (AUDIT-06: High/Medium — Gemini thought parts are appended to the answer).

Problem

In agentkit/llm/gemini.py, the candidate parts loop appended part.text to text_parts without checking the thought flag on types.Part. This caused internal chain-of-thought reasoning to be concatenated into LLMResponse.text, leaking into assistant turns, persisted history, and the API final_answer.

Changes

  1. Exclude Thought Parts from Response Text:
    • In agentkit/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).
    • Ensured that thought parts carrying a function_call still yield the tool call and preserve its thought_signature.
  2. Tests and Docs:
    • Added unit test verifying thought parts are stripped from response.text.
    • Added integration test verifying the API endpoint POST /runs emits an answer with zero thought text.
    • Added unit test verifying thought parts with function calls properly yield the tool call and thought signature.
    • Updated docs/PROGRESS.md.

Verification

  • pytest tests/unit/test_audit_regressions.py tests/unit/test_gemini_adapter.py: 41/41 passed.
  • ruff check: clean (0 errors).
  • ruff format check: clean (110 files formatted).
  • mypy agentkit: clean (no issues found in 42 source files).
  • Verification gate: Semgrep differential security check passed (0 warnings).

Copilot AI balanced review requested due to automatic review settings October 20, 2026 21:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

AUDIT-06 — High/Medium — Gemini thought parts are appended to the answer

2 participants