Problem/Motivation

When using the Mistral provider with Canvas AI, requests fail with "422 Unprocessable Entity" while the same request works correctly with the OpenAI provider.

The error originates from the php-mistral client. The failure appears to be caused by a tool definition that does not include parameters, which Mistral seems to reject, while other providers accept it. In my case such tool was "ai_agent_verify_task_completion".

Steps to reproduce

1. Enable canvas_ai.
2. Enable all Canvas AI components so they are available to the agent.
4. In the Canvas editor/agent UI, run a prompt that triggers a tool call, e.g.: "calling the page builder tool first, add a card component with title hello world to the content area"

The response we get is the following, which suggests the problem outlined in this ticket.

{
  "detail" : [ {
    "type" : "missing",
    "loc" : [ "body", "tools", "list[Tool]", 4, "function", "parameters" ],
    "msg" : "Field required",
    "input" : {
      "name" : "ai_agent_verify_task_completion",
      "description" : "This tool MUST be called ONLY after invoking canvas_page_builder_agent or canvas_template_builder_agent to verify that title and metadata were properly generated if they were empty. DO NOT call this tool for any other operations including canvas_component_agent, general questions, or non-page-building tasks."
    }
  }, {
    "type" : "string_type",
    "loc" : [ "body", "tools", "list[str]", 0 ],
    "msg" : "Input should be a valid string",
    "input" : {
      "type" : "function",
      "function" : {
        "name" : "canvas_component_agent",
        "description" : "This agent can manipulate things in Drupal Canvas. Since it outputs a very specific JSON format, please do not use this in other contexts.",
        "parameters" : {
          "type" : "object",
          "properties" : {
            "prompt" : {
              "name" : "prompt",
              "type" : "string",
              "description" : "Prompt The prompt in natural language on how to invoke this agent."
            },
            "files" : {
              "name" : "files",
              "type" : "array",
              "description" : "Files The files using file id.",
              "items" : {
                "type" : "string"
              }
            }
          },
          "required" : [ "prompt" ]
        }
      }
    }
  }, {
    "type" : "string_type",
    "loc" : [ "body", "tools", "list[str]", 1 ],
    "msg" : "Input should be a valid string",
    "input" : {
      "type" : "function",
      "function" : {
        "name" : "canvas_metadata_generation_agent",
        "description" : "This agent focuses on generating metadata(meta description) for Drupal Canvas content, as well as for any user-provided content",
        "parameters" : {
          "type" : "object",
          "properties" : {
            "prompt" : {
              "name" : "prompt",
              "type" : "string",
              "description" : "Prompt The prompt in natural language on how to invoke this agent."
            },
            "files" : {
              "name" : "files",
              "type" : "array",
              "description" : "Files The files using file id.",
              "items" : {
                "type" : "string"
              }
            }
          },
          "required" : [ "prompt" ]
        }
      }
    }
  }, {
    "type" : "string_type",
    "loc" : [ "body", "tools", "list[str]", 2 ],
    "msg" : "Input should be a valid string",
    "input" : {
      "type" : "function",
      "function" : {
        "name" : "canvas_page_builder_agent",
        "description" : "This agent can insert one or many existing components or sections into a specific location on a page. Use this to place a previously created component or section on a layout or page.",
        "parameters" : {
          "type" : "object",
          "properties" : {
            "prompt" : {
              "name" : "prompt",
              "type" : "string",
              "description" : "Prompt The prompt in natural language on how to invoke this agent."
            },
            "files" : {
              "name" : "files",
              "type" : "array",
              "description" : "Files The files using file id.",
              "items" : {
                "type" : "string"
              }
            }
          },
          "required" : [ "prompt" ]
        }
      }
    }
  }, {
    "type" : "string_type",
    "loc" : [ "body", "tools", "list[str]", 3 ],
    "msg" : "Input should be a valid string",
    "input" : {
      "type" : "function",
      "function" : {
        "name" : "canvas_title_generation_agent",
        "description" : "This agent focuses solely on generating new title and editing existing title for Drupal Canvas. It ensures that the created or edited title matches user-provided guidelines and specifications.",
        "parameters" : {
          "type" : "object",
          "properties" : {
            "prompt" : {
              "name" : "prompt",
              "type" : "string",
              "description" : "Prompt The prompt in natural language on how to invoke this agent."
            },
            "files" : {
              "name" : "files",
              "type" : "array",
              "description" : "Files The files using file id.",
              "items" : {
                "type" : "string"
              }
            }
          },
          "required" : [ "prompt" ]
        }
      }
    }
  }, {
    "type" : "string_type",
    "loc" : [ "body", "tools", "list[str]", 4 ],
    "msg" : "Input should be a valid string",
    "input" : {
      "type" : "function",
      "function" : {
        "name" : "ai_agent_verify_task_completion",
        "description" : "This tool MUST be called ONLY after invoking canvas_page_builder_agent or canvas_template_builder_agent to verify that title and metadata were properly generated if they were empty. DO NOT call this tool for any other operations including canvas_component_agent, general questions, or non-page-building tasks."
      }
    }
  } ]
}
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ademarco created an issue. See original summary.

marcus_johansson’s picture

StatusFileSize
new72.56 KB

Testing this in their playground it is possible, so lets see where the changes occur in the API request.

yautja_cetanu’s picture

Issue tags: +priority
marcus_johansson’s picture

Assigned: Unassigned » marcus_johansson

marcus_johansson’s picture

Status: Active » Needs review
Issue tags: +AI Initiative Sprint

I have a fix for the AI module here #3567784: Tools Function Input should give back an empty json schema skeleton. But I don't know what affects it will have, so it comes in 2.0.x.

I have added a fix for this specifically for Mistral.

marcus_johansson’s picture

Assigned: marcus_johansson » Unassigned
ademarco’s picture

This works correctly now, I was able to get a hero placed on the page without having to fiddle with the default agent configuration.

ademarco’s picture

Status: Needs review » Reviewed & tested by the community
marcus_johansson’s picture

Status: Reviewed & tested by the community » Fixed

Lets do it.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

arianraeesi’s picture

Issue tags: +AI Product Development
arianraeesi’s picture

Issue tags: -AI Product Development

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.