Eva Kadlecová activity https://gitlab.com/evakadlecova 2026-03-19T21:05:50Z tag:gitlab.com,2026-03-19:5222648011 Eva Kadlecová pushed to project branch 112-update-create-commit-approval-message at GitLab.org / Duo UI 2026-03-19T15:03:38Z evakadlecova Eva Kadlecová

Eva Kadlecová (ceac2c88) at 19 Mar 15:03

fix: improve create_commit tool approval message

... and 2 more commits

tag:gitlab.com,2026-03-19:5222088354 Eva Kadlecová pushed to project branch 112-update-create-commit-approval-message at GitLab.org / Duo UI 2026-03-19T13:07:22Z evakadlecova Eva Kadlecová

Eva Kadlecová (a8c15ffc) at 19 Mar 13:07

fix: improve create_commit tool approval message

... and 9 more commits

tag:gitlab.com,2026-03-19:5221615388 Eva Kadlecová pushed to project branch 592447-retry-invalid-tool at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-19T11:10:10Z evakadlecova Eva Kadlecová

Eva Kadlecová (2812b2a9) at 19 Mar 11:10

fix: retry invalid tool call

... and 20 more commits

tag:gitlab.com,2026-03-18:5218124965 Eva Kadlecová pushed to project branch 592447-retry-invalid-tool at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-18T15:07:09Z evakadlecova Eva Kadlecová

Eva Kadlecová (9132d3ef) at 18 Mar 15:07

fix: retry invalid tool call

tag:gitlab.com,2026-03-18:5217080836 Eva Kadlecová pushed to project branch 592447-retry-invalid-tool at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-18T11:35:03Z evakadlecova Eva Kadlecová

Eva Kadlecová (a3034a90) at 18 Mar 11:35

fix: retry invalid tool call

tag:gitlab.com,2026-03-18:5216915537 Eva Kadlecová opened merge request !4927: fix: retry invalid tool call at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI ... 2026-03-18T10:56:44Z evakadlecova Eva Kadlecová

What does this merge request do and why?

Fixes an issue where LLMs occasionally produce malformed tool call arguments (e.g. passing a string instead of a list), which causes tool execution to fail silently and results in blank or broken responses for the user.

This MR adds pre-approval validation of tool call arguments against their Pydantic schemas in ChatAgent. When a malformed tool call is detected, the agent automatically retries the LLM request (up to 3 times), appending the validation error to the conversation history so the model can self-correct. If all retries are exhausted, a user-friendly error message is returned.

Closes gitlab-org/gitlab#592447

How to set up and validate locally

  1. I was able to reproduce quite reliably with question "Add joke to readme" and the use_generic_gitlab_api_tools feature flag enabled.
  2. Other option is to apply this change to create a mock (which allows to change then number of malformed tool calls)
diff --git a/duo_workflow_service/agents/chat_agent.py b/duo_workflow_service/agents/chat_agent.py
index 702dccd5b..5aeb78444 100644
--- a/duo_workflow_service/agents/chat_agent.py
+++ b/duo_workflow_service/agents/chat_agent.py
@@ -173,10 +173,37 @@ class ChatAgent:
         return messages

     async def _get_agent_response(self, state: ChatWorkflowState) -> BaseMessage:
-        return await self.prompt_adapter.get_response(
+        # --- DEV ONLY: mock corrupt tool calls to test retry exhaustion ---
+        import json as _json  # noqa: F811,E402  # DEV ONLY
+
+        _MOCK_REMAINING = 4
+        if not hasattr(self, "_mock_corrupt_ctr"):
+            self._mock_corrupt_ctr = _MOCK_REMAINING
+
+        response = await self.prompt_adapter.get_response(
             state, system_template_override=self.system_template_override
         )

+        if (
+            self._mock_corrupt_ctr > 0
+            and isinstance(response, AIMessage)
+            and response.tool_calls
+        ):
+            for call in response.tool_calls:
+                if call["name"] == "create_commit" and isinstance(
+                    call["args"].get("actions"), list
+                ):
+                    log.warning(
+                        "DEV MOCK: Corrupting create_commit tool call args",
+                        remaining=self._mock_corrupt_ctr,
+                    )
+                    call["args"]["actions"] = _json.dumps(call["args"]["actions"])
+                    self._mock_corrupt_ctr -= 1
+                    break
+
+        return response
+        # --- END DEV ONLY ---
+
     def _build_response(
         self, agent_response: BaseMessage, state: ChatWorkflowState
     ) -> Dict[str, Any]:
@@ -317,3 +344,4 @@ class ChatAgent:
         except Exception as error:
             log_exception(error, extra={"context": "Error processing chat agent"})
             return self._create_error_response(error)
  1. You should see that Chat fixes the tool call without asking user to approve invalid call.
  2. If more than three times the tool fails, it ends with a message about the failure.
Before After - with one failure After - with continuous failure
image.png image.png image.png

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
  • If this change requires executor implementation: verified that issues/MRs exist for both Go executor and Node executor or confirmed that changes are backward-compatible and don't break existing executor functionality.
tag:gitlab.com,2026-03-18:5216895555 Eva Kadlecová pushed to project branch 592447-retry-invalid-tool at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-18T10:52:24Z evakadlecova Eva Kadlecová

Eva Kadlecová (6d5818c4) at 18 Mar 10:52

fix: retry invalid tool call

... and 4 more commits

tag:gitlab.com,2026-03-18:5216827990 Eva Kadlecová pushed to project branch 592447-retry-invalid-tool at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-18T10:38:36Z evakadlecova Eva Kadlecová

Eva Kadlecová (3ade930a) at 18 Mar 10:38

fix: retry invalid tool call

tag:gitlab.com,2026-03-18:5216775858 Eva Kadlecová pushed to project branch 592447-retry-invalid-tool at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-18T10:27:16Z evakadlecova Eva Kadlecová

Eva Kadlecová (be9cfc67) at 18 Mar 10:27

fix: retry invalid tool call

tag:gitlab.com,2026-03-18:5216609882 Eva Kadlecová commented on merge request !226254 at GitLab.org / GitLab 2026-03-18T09:55:08Z evakadlecova Eva Kadlecová

@s_murray Sure, I didn't notice, I'll reassign the review!

@pskorupa Can you please take over the review, please?

tag:gitlab.com,2026-03-18:5216410401 Eva Kadlecová pushed to project branch 592447-retry-invalid-tool at GitLab.org / ModelOps / AI Assisted (formerly Applied ML) / Code Suggestions / AI Gateway 2026-03-18T09:11:58Z evakadlecova Eva Kadlecová

Eva Kadlecová (c60fbe01) at 18 Mar 09:11

fix: retry invalid tool call

... and 102 more commits

tag:gitlab.com,2026-03-18:5215985042 Eva Kadlecová commented on merge request !226254 at GitLab.org / GitLab 2026-03-18T07:16:20Z evakadlecova Eva Kadlecová

Thanks for the fix, the code looks good, I just left one minor comment

@s_murray Can you please do the maintainer review?