[PR #35] [MERGED] fix: remove duplicate assistant message when content+tool_calls present (fixes Gemini #8) #34

Closed
opened 2026-02-27 13:59:58 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/GH05TCREW/pentestagent/pull/35
Author: @selectqoma
Created: 2/25/2026
Status: Merged
Merged: 2/25/2026
Merged by: @GH05TCREW

Base: mainHead: fix/gemini-duplicate-assistant-message


📝 Commits (1)

  • a6cf684 fix: remove duplicate assistant message when content and tool_calls both present

📊 Changes

2 files changed (+2 additions, -5 deletions)

View changed files

📝 pentestagent/agents/crew/orchestrator.py (+0 -3)
📝 pentestagent/llm/llm.py (+2 -2)

📄 Description

Summary

  • Root cause of issue #8: In CrewOrchestrator.run(), when the LLM response contains both content and tool_calls, the code appended two back-to-back assistant messages to self._messages:

    1. {"role": "assistant", "content": response.content} — bare content message
    2. {"role": "assistant", "content": ..., "tool_calls": [...]} — the correct combined message

    Gemini (and technically any spec-compliant LLM API) rejects conversations with consecutive same-role messages. On the very next turn, Gemini would error or cancel the request, which explains why worker agents end up in cancelled state.

  • Fix: Remove the redundant self._messages.append({"role": "assistant", "content": response.content}) — the content is already included in the combined message that follows it.

  • Bonus fix: get_available_models() listed gemini-2.5-pro / gemini-2.5-flash without the required gemini/ prefix. Updated to match the documented correct format.

Test plan

  • Set PENTESTAGENT_MODEL=gemini/gemini-2.5-flash with a valid GEMINI_API_KEY
  • Run a crew task and verify worker agents complete (not cancelled/error)
  • Verify single-agent (non-crew) mode still works as expected

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/GH05TCREW/pentestagent/pull/35 **Author:** [@selectqoma](https://github.com/selectqoma) **Created:** 2/25/2026 **Status:** ✅ Merged **Merged:** 2/25/2026 **Merged by:** [@GH05TCREW](https://github.com/GH05TCREW) **Base:** `main` ← **Head:** `fix/gemini-duplicate-assistant-message` --- ### 📝 Commits (1) - [`a6cf684`](https://github.com/GH05TCREW/pentestagent/commit/a6cf68430f2019d62b9346d81c1a24cd6c22cbef) fix: remove duplicate assistant message when content and tool_calls both present ### 📊 Changes **2 files changed** (+2 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `pentestagent/agents/crew/orchestrator.py` (+0 -3) 📝 `pentestagent/llm/llm.py` (+2 -2) </details> ### 📄 Description ## Summary - **Root cause of issue #8**: In `CrewOrchestrator.run()`, when the LLM response contains both `content` and `tool_calls`, the code appended two back-to-back assistant messages to `self._messages`: 1. `{"role": "assistant", "content": response.content}` — bare content message 2. `{"role": "assistant", "content": ..., "tool_calls": [...]}` — the correct combined message Gemini (and technically any spec-compliant LLM API) rejects conversations with consecutive same-role messages. On the very next turn, Gemini would error or cancel the request, which explains why worker agents end up in `cancelled` state. - **Fix**: Remove the redundant `self._messages.append({"role": "assistant", "content": response.content})` — the content is already included in the combined message that follows it. - **Bonus fix**: `get_available_models()` listed `gemini-2.5-pro` / `gemini-2.5-flash` without the required `gemini/` prefix. Updated to match the documented correct format. ## Test plan - [ ] Set `PENTESTAGENT_MODEL=gemini/gemini-2.5-flash` with a valid `GEMINI_API_KEY` - [ ] Run a crew task and verify worker agents complete (not cancelled/error) - [ ] Verify single-agent (non-crew) mode still works as expected 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-27 13:59:58 -05:00
yindo closed this issue 2026-02-27 13:59:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: yindo/pentestagent#34