From 49539dc7c0943c881698aa6bdfaddda38dd14aab Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Wed, 29 Oct 2025 15:33:29 +0100 Subject: [PATCH 1/6] Modify create_function_result output to be a typedDict to avoid conflicts between ToolCall and FunctionToolCall --- src/mistralai/extra/run/tools.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/mistralai/extra/run/tools.py b/src/mistralai/extra/run/tools.py index 81fec665..ab7d847a 100644 --- a/src/mistralai/extra/run/tools.py +++ b/src/mistralai/extra/run/tools.py @@ -2,6 +2,7 @@ import logging from dataclasses import dataclass import inspect +from typing import Dict from pydantic import Field, create_model from pydantic.fields import FieldInfo @@ -140,8 +141,8 @@ def _get_function_parameters( return schema -def create_tool_call(func: Callable) -> FunctionTool: - """Parse a function docstring / type annotations to create a FunctionTool.""" +def create_tool_call(func: Callable) -> Dict: + """Parse a function docstring / type annotations to create a FunctionToolTypedDict or a ToolTypedDict.""" name = func.__name__ # Inspect and parse the docstring of the function @@ -165,19 +166,15 @@ def create_tool_call(func: Callable) -> FunctionTool: params_from_sig = list(sig.parameters.values()) type_hints = get_type_hints(func, include_extras=True, localns=None, globalns=None) - return FunctionTool( - type="function", - function=Function( - name=name, - description=_get_function_description(docstring_sections), - parameters=_get_function_parameters( - docstring_sections=docstring_sections, - params_from_sig=params_from_sig, - type_hints=type_hints, - ), - strict=True, - ), - ) + return { + "type": "function", + "function": { + "name": name, + "description": _get_function_description(docstring_sections), + "parameters": _get_function_parameters(docstring_sections, params_from_sig, type_hints), + "strict": True, + }, + } async def create_function_result( From 65d8a048002c28583be426f2e1f1177717d84959 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria <47357713+amenasria@users.noreply.github.com> Date: Wed, 29 Oct 2025 15:51:21 +0100 Subject: [PATCH 2/6] Update src/mistralai/extra/run/tools.py Co-authored-by: Jean-Malo Delignon <56539593+jean-malo@users.noreply.github.com> --- src/mistralai/extra/run/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mistralai/extra/run/tools.py b/src/mistralai/extra/run/tools.py index ab7d847a..0d37cce5 100644 --- a/src/mistralai/extra/run/tools.py +++ b/src/mistralai/extra/run/tools.py @@ -141,7 +141,7 @@ def _get_function_parameters( return schema -def create_tool_call(func: Callable) -> Dict: +def create_tool_call(func: Callable) -> FunctionToolTypedDict | ToolTypedDict: """Parse a function docstring / type annotations to create a FunctionToolTypedDict or a ToolTypedDict.""" name = func.__name__ From 7d580f48d6d7e911913d4c893dfc9f06fef38136 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Wed, 29 Oct 2025 15:53:04 +0100 Subject: [PATCH 3/6] Fix --- src/mistralai/extra/run/tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mistralai/extra/run/tools.py b/src/mistralai/extra/run/tools.py index 0d37cce5..78794121 100644 --- a/src/mistralai/extra/run/tools.py +++ b/src/mistralai/extra/run/tools.py @@ -23,7 +23,8 @@ from mistralai.models import ( FunctionResultEntry, FunctionTool, - Function, + FunctionToolTypedDict, + ToolTypedDict, FunctionCallEntry, ) From af4de4d40771180e2ea68deca7dac4c87b8294ce Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Wed, 29 Oct 2025 16:38:49 +0100 Subject: [PATCH 4/6] unused import --- src/mistralai/extra/run/tools.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mistralai/extra/run/tools.py b/src/mistralai/extra/run/tools.py index 78794121..0a86eab6 100644 --- a/src/mistralai/extra/run/tools.py +++ b/src/mistralai/extra/run/tools.py @@ -2,7 +2,6 @@ import logging from dataclasses import dataclass import inspect -from typing import Dict from pydantic import Field, create_model from pydantic.fields import FieldInfo From c450fac66ac2a4cb0ea656966335f02a3ef22ba9 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Thu, 30 Oct 2025 15:25:18 +0100 Subject: [PATCH 5/6] Fix typing --- src/mistralai/extra/run/tools.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mistralai/extra/run/tools.py b/src/mistralai/extra/run/tools.py index 0a86eab6..46affc11 100644 --- a/src/mistralai/extra/run/tools.py +++ b/src/mistralai/extra/run/tools.py @@ -35,20 +35,20 @@ class RunFunction: name: str callable: Callable - tool: FunctionTool + tool: Union[FunctionToolTypedDict, ToolTypedDict] @dataclass class RunCoroutine: name: str awaitable: Callable - tool: FunctionTool + tool: Union[FunctionToolTypedDict, ToolTypedDict] @dataclass class RunMCPTool: name: str - tool: FunctionTool + tool: FunctionToolTypedDict mcp_client: MCPClientProtocol @@ -141,7 +141,7 @@ def _get_function_parameters( return schema -def create_tool_call(func: Callable) -> FunctionToolTypedDict | ToolTypedDict: +def create_tool_call(func: Callable) -> Union[FunctionToolTypedDict, ToolTypedDict]: """Parse a function docstring / type annotations to create a FunctionToolTypedDict or a ToolTypedDict.""" name = func.__name__ From 14634db903bd2cff518d7e12b45702d5d5ba9d53 Mon Sep 17 00:00:00 2001 From: Alexandre Menasria Date: Thu, 30 Oct 2025 16:02:51 +0100 Subject: [PATCH 6/6] Fix linter --- src/mistralai/extra/run/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mistralai/extra/run/tools.py b/src/mistralai/extra/run/tools.py index 46affc11..dac6d948 100644 --- a/src/mistralai/extra/run/tools.py +++ b/src/mistralai/extra/run/tools.py @@ -48,7 +48,7 @@ class RunCoroutine: @dataclass class RunMCPTool: name: str - tool: FunctionToolTypedDict + tool: FunctionTool mcp_client: MCPClientProtocol