Multiple tools with Mistral Large 2411

Please release an example of tools calling in a multiple tools environment.
Currently ‘tools’ section only allowed single tool implementation, vllm server will omit ‘“POST /v1/chat/completions HTTP/1.1” 400 Bad Request’ for multiple tools without any detailed explanation.
Sorry, I’m new here. I’m trying to figure out causes by searching in source code. :laughing:

Here is my ‘tools’ section:

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_current_time",
            "description": "Get the current system time",
            "parameters": {
                "type": "object",
                "properties": {},
                "required": [],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "bash_interaction",
            "description": "Execute a bash command and get the output",
            "parameters": {
                "type": "object",
                "properties": {
                    "command": {
                        "type": "string",
                        "description": "The bash command to execute.",
                    }
                },
                "required": ["command"],
            },
        },
    }
]

I believe there is something wrong in my ‘bash_interaction’.

I am rewriting entire thing with bash :laughing:
It somethings work.
Tool calling behavior of Mistral 2411 isn’t stable.
Here is something shouldn’t be(the vLLM side reply):

{
  "id": "chatcmpl-27b7180ea0d84d27a3b74de04998277d",
  "object": "chat.completion",
  "created": 1742967363,
  "model": "./Mistral-Large-Instruct-2411/",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "reasoning_content": null,
        "content": " [{\"name\": \"Bash_interaction\", \"arguments\": {\"command\": \"date\"}}]",
        "tool_calls": []
      },
      "logprobs": null,
      "finish_reason": "stop",
      "stop_reason": null
    }
  ],
  "usage": {
    "prompt_tokens": 94,
    "total_tokens": 118,
    "completion_tokens": 24,
    "prompt_tokens_details": null
  },
  "prompt_logprobs": null
}

Here is a success and triggered my bash script:

[
  {
    "role": "user",
    "content": "get current time"
  },
  {
    "role": "assistant",
    "reasoning_content": null,
    "content": null,
    "tool_calls": [
      {
        "id": "Q7VLh0RDH",
        "type": "function",
        "function": {
          "name": "Bash_interaction",
          "arguments": "{\"command\": \"date\"}"
        }
      }
    ]
  },
  {
    "role": "tool",
    "name": "Bash_interaction",
    "content": "Wed Mar 26 01:47:00 PM CST 2025\n",
    "tool_call_id": "Q7VLh0RDH"
  },
  null
]

However the vllm server omit ‘400 bad request’ when I send back :smiling_face_with_tear:

Here is log of vLLM:

ERROR 03-26 14:21:20 [serving_chat.py:201] Error in preprocessing prompt inputs
ERROR 03-26 14:21:20 [serving_chat.py:201] Traceback (most recent call last):
ERROR 03-26 14:21:20 [serving_chat.py:201]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/site-packages/vllm-0.8.1+cpu-py3.10-linux-x86_64.egg/vllm/entrypoints/openai/serving_chat.py", line 185, in create_chat_completion
ERROR 03-26 14:21:20 [serving_chat.py:201]     ) = await self._preprocess_chat(
ERROR 03-26 14:21:20 [serving_chat.py:201]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/site-packages/vllm-0.8.1+cpu-py3.10-linux-x86_64.egg/vllm/entrypoints/openai/serving_engine.py", line 405, in _preprocess_chat
ERROR 03-26 14:21:20 [serving_chat.py:201]     request_prompt = apply_mistral_chat_template(
ERROR 03-26 14:21:20 [serving_chat.py:201]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/site-packages/vllm-0.8.1+cpu-py3.10-linux-x86_64.egg/vllm/entrypoints/chat_utils.py", line 1118, in apply_mistral_chat_template
ERROR 03-26 14:21:20 [serving_chat.py:201]     return tokenizer.apply_chat_template(
ERROR 03-26 14:21:20 [serving_chat.py:201]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/site-packages/vllm-0.8.1+cpu-py3.10-linux-x86_64.egg/vllm/transformers_utils/tokenizers/mistral.py", line 369, in apply_chat_template
ERROR 03-26 14:21:20 [serving_chat.py:201]     request = make_mistral_chat_completion_request(messages, tools)
ERROR 03-26 14:21:20 [serving_chat.py:201]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/site-packages/vllm-0.8.1+cpu-py3.10-linux-x86_64.egg/vllm/transformers_utils/tokenizers/mistral.py", line 167, in make_mistral_chat_completion_request
ERROR 03-26 14:21:20 [serving_chat.py:201]     return ChatCompletionRequest(messages=messages,
ERROR 03-26 14:21:20 [serving_chat.py:201]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/site-packages/pydantic/main.py", line 214, in __init__
ERROR 03-26 14:21:20 [serving_chat.py:201]     validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
ERROR 03-26 14:21:20 [serving_chat.py:201] pydantic_core._pydantic_core.ValidationError: 1 validation error for ChatCompletionRequest
ERROR 03-26 14:21:20 [serving_chat.py:201] messages.1.assistant.reasoning_content
ERROR 03-26 14:21:20 [serving_chat.py:201]   Extra inputs are not permitted [type=extra_forbidden, input_value=None, input_type=NoneType]
ERROR 03-26 14:21:20 [serving_chat.py:201]     For further information visit https://errors.pydantic.dev/2.10/v/extra_forbidden

I DID IT :partying_face:
However, there is a problems on vLLM server side:
The JSON escape encode/decode strategy is NOT constant all over the place for tool calling. (It caused code leak on my server, Urgent)
Maybe forcing to jq for JSON processing?
Error messages for reference:

ERROR 03-26 22:08:54 [mistral_tool_parser.py:127] Error in extracting tool call from response.
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127] Traceback (most recent call last):
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/site-packages/vllm-0.8.1+cpu-py3.10-linux-x86_64.egg/vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py", line 98, in extract_tool_calls
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]     function_call_arr = json.loads(tool_content)
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/json/__init__.py", line 346, in loads
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]     return _default_decoder.decode(s)
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/json/decoder.py", line 337, in decode
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/json/decoder.py", line 353, in raw_decode
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]     obj, end = self.scan_once(s, idx)
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127] json.decoder.JSONDecodeError: Invalid control character at: line 1 column 678 (char 677)
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127] During handling of the above exception, another exception occurred:
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127] Traceback (most recent call last):
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]   File "/home/test/anaconda3/envs/vllm/lib/python3.10/site-packages/vllm-0.8.1+cpu-py3.10-linux-x86_64.egg/vllm/entrypoints/openai/tool_parsers/mistral_tool_parser.py", line 104, in extract_tool_calls
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127]     raw_tool_call = self.tool_call_regex.findall(tool_content)[0]
ERROR 03-26 22:08:54 [mistral_tool_parser.py:127] IndexError: list index out of range