Skip to content

language_models: Add tool use support for Mistral models #29994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
May 19, 2025

Conversation

imumesh18
Copy link
Contributor

@imumesh18 imumesh18 commented May 6, 2025

Closes #29855

Implement tool use handling in Mistral provider, including mapping tool call events and updating request construction. Add support for tool_choice and parallel_tool_calls in Mistral API requests.

This works fine with all the existing models. Didn't touched anything else but for future. Fetching models using their models api, deducting tool call support, parallel tool calls etc should be done from model data from api response.

Screenshot 2025-05-06 at 4 52 37 PM

Tasks:

  • Add tool call support
  • Auto Fetch models using mistral api
  • Add tests for mistral crates.
  • Fix mistral configurations for llm providers.

Release Notes:

  • agent: Add tool call support for existing mistral models

Implement tool use handling in Mistral provider, including mapping
tool call events and updating request construction. Add support for
tool_choice and parallel_tool_calls in Mistral API requests.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label May 6, 2025
@imumesh18 imumesh18 changed the title mistral: Add tool use support for Mistral models agent: Add tool use support for Mistral models May 6, 2025
@notpeter
Copy link
Member

notpeter commented May 6, 2025

I was able to test this, it worked some, but I was able to trigger the following error:

Failed to connect to Mistral API: 400 Bad Request {"object":"error","message":"Unexpected role 'user' after role 'tool'","type":"invalid_request_error","param":null,"code":null}

Screenshot 2025-05-06 at 14 00 53

mistral-tool.md

@imumesh18
Copy link
Contributor Author

Hey @notpeter thanks for testing, can you help me with the which model did you try this with. I am currently unable to reproduce this at the mode. Will see if I am able to do it with the specific model.

@notpeter
Copy link
Member

notpeter commented May 6, 2025

It was with codestral-latest. I haven't been able to come up with a consistent repro. :(

@imumesh18 imumesh18 marked this pull request as ready for review May 12, 2025 19:05
@imumesh18 imumesh18 changed the title agent: Add tool use support for Mistral models language_models: Add tool use support for Mistral models May 13, 2025
@vlebert
Copy link

vlebert commented May 14, 2025

@notpeter I think the last mistral-medium should be a lot more reliable. I have very good results with other agentic tools such as Cline or Aider.dev

@bennetbo
Copy link
Contributor

bennetbo commented May 15, 2025

One thing that i do not love is that /models seems to return a very long list for available models (150 for me). It does not seem like most people are interested in using most of them, so i think it just adds a lot of unnecessary noise.
Is there any way that we can de-dup these? Or go back to the original approach and not fetch them at all?

I tried the de-duping (filter out duplicate ids, non chat models and de-dup by name) but still end up with a lot of unnecessary models that i'm not interested in using:

Screen.Recording.2025-05-15.at.10.51.22.mov

@bennetbo bennetbo closed this May 15, 2025
@bennetbo bennetbo reopened this May 15, 2025
@imumesh18
Copy link
Contributor Author

imumesh18 commented May 15, 2025

Hey @bennetbo got it. I guess in my case it was less so I didn't see this issue. In that case i can revert model fetch and have a hardcoded models in this pr. Probably we can discuss a better approach for exposing all models as a part of seperate pr wdyt?

@bennetbo
Copy link
Contributor

Sounds good 👍🏻

@vlebert
Copy link

vlebert commented May 15, 2025

Maybe only -latest models ?

@imumesh18
Copy link
Contributor Author

imumesh18 commented May 15, 2025

Hey @bennetbo , I have removed the code changes for fetching the model dynamically. Also I have added the language_models.mistral.available_models[n].supports_tools in settings so that users can define their own models and use it with tools. I have attached the demo for custom model usage. It's ready for review now and let me know if there is anyother changes you want me to do.

demo-mistral.mov

@KhazAkar
Copy link

KhazAkar commented May 17, 2025

Tested it today myself, but it needs 'reminding' to use tools, be it mistral-small-latest or codestral-latest.
Outside of that - works quite well.

EDIT: After hitting rate limit, it broke a little at least. After it, it needs few seconds and works fine.
pr-tool-call-issues

@vlebert
Copy link

vlebert commented May 17, 2025

Current best mistral agentic model is mistral medium latest actually

Copy link
Contributor

@bennetbo bennetbo left a comment

Choose a reason for hiding this comment

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

Thanks!

@bennetbo bennetbo merged commit 926f377 into zed-industries:main May 19, 2025
18 checks passed
@imumesh18 imumesh18 deleted the mistral-tool-calls branch May 22, 2025 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed The user has signed the Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Agent Panel: Support for Mistral Provider tool calling
5 participants