From 5ece26297642d99e183c050be153707e8f9828ca Mon Sep 17 00:00:00 2001 From: Sarthak Deshpande <60317842+cheesecake100201@users.noreply.github.com> Date: Wed, 19 Mar 2025 02:43:46 +0530 Subject: [PATCH] chore: Make code interpreter async (#1654) # What does this PR do? Made code interpreter tool call to be async such that its non blocking ## Test Plan pytest -s -v tests/integration/agents/test_agents.py --stack-config=together --text-model=meta-llama/Llama-3.3-70B-Instruct image [//]: # (## Documentation) Co-authored-by: sarthakdeshpande --- .../inline/tool_runtime/code_interpreter/code_interpreter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/llama_stack/providers/inline/tool_runtime/code_interpreter/code_interpreter.py b/llama_stack/providers/inline/tool_runtime/code_interpreter/code_interpreter.py index 4b97914c5..9610b9b46 100644 --- a/llama_stack/providers/inline/tool_runtime/code_interpreter/code_interpreter.py +++ b/llama_stack/providers/inline/tool_runtime/code_interpreter/code_interpreter.py @@ -5,6 +5,7 @@ # the root directory of this source tree. +import asyncio import logging import os import tempfile @@ -37,7 +38,7 @@ class CodeInterpreterToolRuntimeImpl(ToolsProtocolPrivate, ToolRuntime): async def initialize(self): pass - async def register_tool(self, tool: Tool): + async def register_tool(self, tool: Tool) -> None: pass async def unregister_tool(self, tool_id: str) -> None: @@ -65,7 +66,7 @@ class CodeInterpreterToolRuntimeImpl(ToolsProtocolPrivate, ToolRuntime): # Use environment variable to control bwrap usage force_disable_bwrap = os.environ.get("DISABLE_CODE_SANDBOX", "").lower() in ("1", "true", "yes") req = CodeExecutionRequest(scripts=[script], use_bwrap=not force_disable_bwrap) - res = self.code_executor.execute(req) + res = await asyncio.to_thread(self.code_executor.execute, req) pieces = [res["process_status"]] for out_type in ["stdout", "stderr"]: res_out = res[out_type]