fix: wrap sync instructor.to_json() in asyncio.to_thread for ato_json

Addresses Cursor Bugbot feedback: the function-calling path in ato_json
was still calling _create_instructor().to_json() synchronously, blocking
the event loop. Now wrapped in asyncio.to_thread() to offload the
blocking call to a separate thread.

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2026-04-02 12:54:20 +00:00
parent 85369cf23e
commit 415b894405

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
import asyncio
import json
import re
from typing import TYPE_CHECKING, Any, Final, TypedDict
@@ -225,7 +226,7 @@ class Converter(OutputConverter):
"""
try:
if self.llm.supports_function_calling():
return self._create_instructor().to_json()
return await asyncio.to_thread(self._create_instructor().to_json)
return json.dumps(
await self.llm.acall(
[