Supporting no-code Guardrail creation (#2636)

* feat: support to define a guardrail task no-code

* feat: add auto-discovery for Guardrail code execution mode

* feat: handle malformed or invalid response from CodeInterpreterTool

* feat: allow to set unsafe_mode from Guardrail task

* feat: renaming GuardrailTask to TaskGuardrail

* feat: ensure guardrail is callable while initializing Task

* feat: remove Docker availability check from TaskGuardrail

The CodeInterpreterTool already ensures compliance with this requirement.

* refactor: replace if/raise with assert

For this use case `assert` is more appropriate choice

* test: remove useless or duplicated test

* fix: attempt to fix type-checker

* feat: support to define a task guardrail using YAML config

* refactor: simplify TaskGuardrail to use LLM for validation, no code generation

* docs: update TaskGuardrail doc strings

* refactor: drop task paramenter from TaskGuardrail

This parameter was used to get the model from the `task.agent` which is a quite bit redudant since we could propagate the llm directly
This commit is contained in:
Lucas Gomide
2025-04-30 11:47:58 -03:00
committed by GitHub
parent 94b1a6cfb8
commit 015e1a41b2
18 changed files with 4935 additions and 1162 deletions

View File

@@ -1,4 +1,5 @@
from typing import List
from unittest.mock import patch
import pytest
@@ -142,6 +143,15 @@ def test_agent_function_calling_llm():
), "agent's function_calling_llm is incorrect"
def test_task_guardrail():
crew = InternalCrew()
research_task = crew.research_task()
assert research_task.guardrail == "ensure each bullet contains its source"
reporting_task = crew.reporting_task()
assert reporting_task.guardrail is None
@pytest.mark.vcr(filter_headers=["authorization"])
def test_before_kickoff_modification():
crew = InternalCrew()