mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
feat: remove Docker availability check from TaskGuardrail
The CodeInterpreterTool already ensures compliance with this requirement.
This commit is contained in:
@@ -11,8 +11,9 @@ class TaskGuardrail:
|
|||||||
|
|
||||||
This class generates and executes Python code to validate task outputs based on
|
This class generates and executes Python code to validate task outputs based on
|
||||||
specified criteria. It uses an LLM to generate the validation code and provides
|
specified criteria. It uses an LLM to generate the validation code and provides
|
||||||
safety guardrails for code execution. The code is executed in a Docker container
|
safety guardrails for code execution.
|
||||||
if available, otherwise it is executed in the current environment.
|
The code is executed in a Docker container if available, otherwise it is executed in a sandboxed environment.
|
||||||
|
If unsafe mode is enabled, the code is executed in the current environment.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
description (str): The description of the validation criteria.
|
description (str): The description of the validation criteria.
|
||||||
@@ -32,7 +33,7 @@ class TaskGuardrail:
|
|||||||
task: Task | None = None,
|
task: Task | None = None,
|
||||||
llm: LLM | None = None,
|
llm: LLM | None = None,
|
||||||
additional_instructions: str = "",
|
additional_instructions: str = "",
|
||||||
unsafe_mode: bool | None = None,
|
unsafe_mode: bool = False,
|
||||||
):
|
):
|
||||||
self.description = description
|
self.description = description
|
||||||
|
|
||||||
@@ -139,13 +140,8 @@ class TaskGuardrail:
|
|||||||
|
|
||||||
self.generated_code = self.generate_code(task_output)
|
self.generated_code = self.generate_code(task_output)
|
||||||
|
|
||||||
unsafe_mode = (
|
|
||||||
self.unsafe_mode
|
|
||||||
if self.unsafe_mode is not None
|
|
||||||
else not self.check_docker_available()
|
|
||||||
)
|
|
||||||
result = CodeInterpreterTool(
|
result = CodeInterpreterTool(
|
||||||
code=self.generated_code, unsafe_mode=unsafe_mode
|
code=self.generated_code, unsafe_mode=self.unsafe_mode
|
||||||
).run()
|
).run()
|
||||||
|
|
||||||
error_messages = [
|
error_messages = [
|
||||||
@@ -163,12 +159,3 @@ class TaskGuardrail:
|
|||||||
return False, f"Error parsing result: {str(e)}"
|
return False, f"Error parsing result: {str(e)}"
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def check_docker_available(self) -> bool:
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
try:
|
|
||||||
subprocess.run(["docker", "--version"], check=True)
|
|
||||||
return True
|
|
||||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
||||||
return False
|
|
||||||
|
|||||||
Reference in New Issue
Block a user