fixing tests

This commit is contained in:
João Moura
2025-06-08 20:34:29 -07:00
parent 49f8983b76
commit 67e5c00d07
2 changed files with 47 additions and 19 deletions

View File

@@ -401,7 +401,7 @@ def show_agent_logs(
) )
if task_description: if task_description:
# Filter out reasoning plan from display (but keep it in actual task for LLM) # Filter out reasoning plan from display (but keep it in actual task for LLM)
display_description = _filter_reasoning_plan_from_display(task_description) display_description = _filter_auxiliary_from_display(task_description)
printer.print( printer.print(
content=f"\033[95m## Task:\033[00m \033[92m{display_description}\033[00m" content=f"\033[95m## Task:\033[00m \033[92m{display_description}\033[00m"
) )
@@ -437,22 +437,42 @@ def show_agent_logs(
) )
def _filter_reasoning_plan_from_display(task_description: str) -> str: def _filter_auxiliary_from_display(task_description: str) -> str:
"""Filter out reasoning plan from task description for display purposes only. """Remove standard auxiliary sections (e.g., date injection, reasoning plan) from task description for display.
This keeps the reasoning plan in the actual task description for the LLM to use, This function standardizes the removal of auxiliary information such as the injected current date
but removes it from the display logs to avoid duplication with reasoning panels. and the reasoning plan from the task description, ensuring that only the core task is shown in display logs.
The actual task description (with all sections) is still used for LLM input.
Args: Args:
task_description: The full task description that may contain a reasoning plan task_description (str): The full task description, possibly containing auxiliary sections.
Returns: Returns:
Task description with reasoning plan removed for display purposes str: The task description with auxiliary sections removed for display purposes.
Example:
>>> desc = "Do X\\n\\nCurrent Date: 2024-06-01\\n\\nReasoning Plan:\\nStep 1..."
>>> _filter_auxiliary_from_display(desc)
'Do X'
""" """
# Look for the reasoning plan section and remove it for display # Define patterns for auxiliary sections to remove, in order.
if "\n\nReasoning Plan:\n" in task_description: auxiliary_patterns = [
return task_description.split("\n\nReasoning Plan:\n")[0] (r"\n\nCurrent Date: [^\n]*", "date injection"),
return task_description (r"\n\nReasoning Plan:\n.*", "reasoning plan"),
]
cleaned_description = task_description
for pattern, _ in auxiliary_patterns:
# For the reasoning plan, remove everything from the marker to the end.
if "Reasoning Plan" in pattern:
match = re.search(r"\n\nReasoning Plan:\n", cleaned_description)
if match:
cleaned_description = cleaned_description[: match.start()]
else:
cleaned_description = re.sub(pattern, "", cleaned_description)
return cleaned_description.strip()
def load_agent_from_repository(from_repository: str) -> Dict[str, Any]: def load_agent_from_repository(from_repository: str) -> Dict[str, Any]:

View File

@@ -29,7 +29,8 @@ def test_agent_with_reasoning(mock_llm_responses):
backstory="I am a test agent created to verify the reasoning feature works correctly.", backstory="I am a test agent created to verify the reasoning feature works correctly.",
llm=llm, llm=llm,
reasoning=True, reasoning=True,
verbose=True verbose=True,
inject_date=False
) )
task = Task( task = Task(
@@ -61,7 +62,8 @@ def test_agent_with_reasoning_not_ready_initially(mock_llm_responses):
llm=llm, llm=llm,
reasoning=True, reasoning=True,
max_reasoning_attempts=2, max_reasoning_attempts=2,
verbose=True verbose=True,
inject_date=False
) )
task = Task( task = Task(
@@ -102,7 +104,8 @@ def test_agent_with_reasoning_max_attempts_reached():
llm=llm, llm=llm,
reasoning=True, reasoning=True,
max_reasoning_attempts=2, max_reasoning_attempts=2,
verbose=True verbose=True,
inject_date=False
) )
task = Task( task = Task(
@@ -138,7 +141,8 @@ def test_agent_reasoning_input_validation():
goal="To test the reasoning feature", goal="To test the reasoning feature",
backstory="I am a test agent created to verify the reasoning feature works correctly.", backstory="I am a test agent created to verify the reasoning feature works correctly.",
llm=llm, llm=llm,
reasoning=True reasoning=True,
inject_date=False
) )
with pytest.raises(ValueError, match="Both task and agent must be provided"): with pytest.raises(ValueError, match="Both task and agent must be provided"):
@@ -161,7 +165,8 @@ def test_agent_reasoning_error_handling():
goal="To test the reasoning feature", goal="To test the reasoning feature",
backstory="I am a test agent created to verify the reasoning feature works correctly.", backstory="I am a test agent created to verify the reasoning feature works correctly.",
llm=llm, llm=llm,
reasoning=True reasoning=True,
inject_date=False
) )
task = Task( task = Task(
@@ -196,7 +201,8 @@ def test_agent_with_function_calling():
backstory="I am a test agent created to verify the reasoning feature works correctly.", backstory="I am a test agent created to verify the reasoning feature works correctly.",
llm=llm, llm=llm,
reasoning=True, reasoning=True,
verbose=True verbose=True,
inject_date=False
) )
task = Task( task = Task(
@@ -234,7 +240,8 @@ def test_agent_with_function_calling_fallback():
backstory="I am a test agent created to verify the reasoning feature works correctly.", backstory="I am a test agent created to verify the reasoning feature works correctly.",
llm=llm, llm=llm,
reasoning=True, reasoning=True,
verbose=True verbose=True,
inject_date=False
) )
task = Task( task = Task(
@@ -270,7 +277,8 @@ def test_agent_with_reasoning_non_verbose_mode(mock_llm_responses):
backstory="I am a test agent created to verify the reasoning feature works correctly.", backstory="I am a test agent created to verify the reasoning feature works correctly.",
llm=llm, llm=llm,
reasoning=True, reasoning=True,
verbose=False # Non-verbose mode verbose=False, # Non-verbose mode
inject_date=False
) )
task = Task( task = Task(