Problem/Motivation
Mistral provider does not support "thinking" models and it fails when trying to construct a new \Drupal\ai\OperationType\Chat\ChatMessage(), since that constructor expects a string parameter, but Mistral returns an array of "thinking" steps.
Steps to reproduce
- Visit /admin/config/ai/agents
- Click on the "Explore" operation for "Taxonomy Agent"
- Run the agent with "mistral-medium" model
- Agent will hung, submit button stays on "Running..."
Recent logs will show the following message:
TypeError: Drupal\ai\OperationType\Chat\ChatMessage::__construct(): Argument #2 ($text) must be of type string, array given, called in /var/www/html/web/modules/contrib/ai_provider_mistral/src/Plugin/AiProvider/MistralProvider.php on line 318 in Drupal\ai\OperationType\Chat\ChatMessage->__construct() (line 64 of /var/www/html/web/modules/contrib/ai/src/OperationType/Chat/ChatMessage.php).
Everything works correctly for non-thinking models, such as "mistral-tiny".
Proposed resolution
- Support Mistral "thinking" models
- Make sure that we display an error on the agent explorer, when things fail
Issue fork ai_provider_mistral-3567184
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:
- 3567184-reasoning
changes, plain diff MR !11
- 3567184-add-support-for
compare
Comments
Comment #2
ademarco commentedComment #3
yautja_cetanu commentedComment #4
marcus_johansson commentedComment #7
marcus_johansson commentedI can only replicate this if I use Magistral and according to documentation this is the only model that supports it at the moment, see: https://docs.mistral.ai/capabilities/reasoning
This might need an upstream fix, but I have added a solution that will work. What is happening is that they are giving back the thinking array, but we only need the text. But in this case there is no text because the order is:
1. Thinking
2. Give back tool response
And we are trying to fill in string where we have an array.
Comment #8
marcus_johansson commentedComment #9
ademarco commentedI've tested it with mistral-large 2 agents, one that adds taxonomy terms to a vocabulary and another that add fields to a content type, and it worked in both cases, repeatedly.
Comment #10
marcus_johansson commentedThank you for finding and reviewing, this is getting merged.
Comment #13
arianraeesi commentedComment #14
arianraeesi commented