rmeove duplciate reasonign logs

This commit is contained in:
João Moura
2025-06-07 23:57:24 -07:00
parent 814afb86cf
commit ad725f44b3
2 changed files with 85 additions and 51 deletions

View File

@@ -254,7 +254,10 @@ class Agent(BaseAgent):
reasoning_handler.handle_agent_reasoning()
)
# Add the reasoning plan to the task description
# Only add reasoning plan to task description if verbose mode is disabled
# In verbose mode, the reasoning plan is already displayed in a panel
is_verbose = self.verbose or (hasattr(self, "crew") and getattr(self.crew, "verbose", False))
if not is_verbose:
task.description += f"\n\nReasoning Plan:\n{reasoning_output.plan.plan}"
except Exception as e:
if hasattr(self, "_logger"):

View File

@@ -47,7 +47,7 @@ def test_agent_with_reasoning(mock_llm_responses):
result = agent.execute_task(task)
assert result == mock_llm_responses["execution"]
assert "Reasoning Plan:" in task.description
assert "Reasoning Plan:" not in task.description
def test_agent_with_reasoning_not_ready_initially(mock_llm_responses):
@@ -88,7 +88,7 @@ def test_agent_with_reasoning_not_ready_initially(mock_llm_responses):
assert result == "2x"
assert call_count[0] == 2 # Should have made 2 reasoning calls
assert "Reasoning Plan:" in task.description
assert "Reasoning Plan:" not in task.description
def test_agent_with_reasoning_max_attempts_reached():
@@ -126,7 +126,7 @@ def test_agent_with_reasoning_max_attempts_reached():
assert result == "This is an unsolved problem in mathematics."
assert call_count[0] == 2 # Should have made exactly 2 reasoning calls (max_attempts)
assert "Reasoning Plan:" in task.description
assert "Reasoning Plan:" not in task.description
def test_agent_reasoning_input_validation():
@@ -221,8 +221,7 @@ def test_agent_with_function_calling():
result = agent.execute_task(task)
assert result == "4"
assert "Reasoning Plan:" in task.description
assert "I'll solve this simple math problem: 2+2=4." in task.description
assert "Reasoning Plan:" not in task.description
def test_agent_with_function_calling_fallback():
@@ -257,5 +256,37 @@ def test_agent_with_function_calling_fallback():
result = agent.execute_task(task)
assert result == "4"
# In verbose mode, reasoning plan should NOT be added to task description
assert "Reasoning Plan:" not in task.description
def test_agent_with_reasoning_non_verbose_mode(mock_llm_responses):
"""Test agent with reasoning in non-verbose mode where reasoning plan should be added to task description."""
llm = LLM("gpt-3.5-turbo")
agent = Agent(
role="Test Agent",
goal="To test the reasoning feature",
backstory="I am a test agent created to verify the reasoning feature works correctly.",
llm=llm,
reasoning=True,
verbose=False # Non-verbose mode
)
task = Task(
description="Simple math task: What's 2+2?",
expected_output="The answer should be a number.",
agent=agent
)
agent.llm.call = lambda messages, *args, **kwargs: (
mock_llm_responses["ready"]
if any("create a detailed plan" in msg.get("content", "") for msg in messages)
else mock_llm_responses["execution"]
)
result = agent.execute_task(task)
assert result == mock_llm_responses["execution"]
assert "Reasoning Plan:" in task.description
assert "Invalid JSON that will trigger fallback" in task.description
assert "I'll solve this simple math problem" in task.description