mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-01 23:32:39 +00:00
fix: Address CI failures and code review feedback for multi-round dialogue
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -1206,6 +1206,7 @@ def test_agent_max_retry_limit():
|
||||
"tool_names": "",
|
||||
"tools": "",
|
||||
"ask_for_human_input": True,
|
||||
"max_dialogue_rounds": 10,
|
||||
}
|
||||
),
|
||||
mock.call(
|
||||
@@ -1214,6 +1215,7 @@ def test_agent_max_retry_limit():
|
||||
"tool_names": "",
|
||||
"tools": "",
|
||||
"ask_for_human_input": True,
|
||||
"max_dialogue_rounds": 10,
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
from crewai.task import Task
|
||||
from langchain_core.agents import AgentFinish
|
||||
|
||||
|
||||
class TestMultiRoundDialogue(unittest.TestCase):
|
||||
@@ -31,6 +32,44 @@ class TestMultiRoundDialogue(unittest.TestCase):
|
||||
|
||||
# Verify the custom value
|
||||
self.assertEqual(task.max_dialogue_rounds, 5)
|
||||
|
||||
def test_task_max_dialogue_rounds_validation(self):
|
||||
"""Test that Task validates max_dialogue_rounds as a positive integer."""
|
||||
# Create a task with invalid max_dialogue_rounds
|
||||
with self.assertRaises(ValueError):
|
||||
task = Task(
|
||||
description="Test task",
|
||||
expected_output="Test output",
|
||||
human_input=True,
|
||||
max_dialogue_rounds=0
|
||||
)
|
||||
|
||||
def test_handle_regular_feedback_rounds(self):
|
||||
"""Test that _handle_regular_feedback correctly handles multiple rounds."""
|
||||
from crewai.agents.crew_agent_executor import CrewAgentExecutor
|
||||
|
||||
# Create a simple mock executor
|
||||
executor = MagicMock()
|
||||
executor.ask_for_human_input = True
|
||||
executor._ask_human_input = MagicMock(side_effect=["Feedback", ""])
|
||||
executor._process_feedback_iteration = MagicMock(return_value=MagicMock())
|
||||
|
||||
# Create a sample initial answer
|
||||
initial_answer = MagicMock()
|
||||
|
||||
# Call the method directly
|
||||
CrewAgentExecutor._handle_regular_feedback(
|
||||
executor,
|
||||
initial_answer,
|
||||
"Initial feedback",
|
||||
max_rounds=3
|
||||
)
|
||||
|
||||
# Verify the correct number of iterations occurred
|
||||
# First call for initial feedback, second call for empty feedback to end loop
|
||||
self.assertEqual(executor._ask_human_input.call_count, 2)
|
||||
# The _process_feedback_iteration is called for the initial feedback and the first round
|
||||
self.assertEqual(executor._process_feedback_iteration.call_count, 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user