Remove deprecated test files and examples for LiteAgent; add comprehensive tests for LiteAgent functionality, including tool usage and structured output handling.

This commit is contained in:
Lorenze Jay
2025-03-31 12:13:25 -07:00
parent a00eaa4732
commit 7107224fa9
10 changed files with 1092 additions and 332 deletions

View File

@@ -241,12 +241,21 @@ class LiteAgent(BaseModel):
formatted_result: Optional[BaseModel] = None
if self.response_format:
try:
# Cast to BaseModel to ensure type safety
result = self.response_format.model_validate_json(
agent_finish.output
final_answer_match = re.search(
r"Final Answer:\s*(.*?)(?:\n\n|$)",
agent_finish.output,
re.DOTALL,
)
if isinstance(result, BaseModel):
formatted_result = result
if final_answer_match:
json_content = final_answer_match.group(1).strip()
result = self.response_format.model_validate_json(json_content)
if isinstance(result, BaseModel):
formatted_result = result
else:
self._printer.print(
content="Could not find Final Answer section in the output",
color="yellow",
)
except Exception as e:
self._printer.print(
content=f"Failed to parse output into response format: {str(e)}",

View File

@@ -26,7 +26,6 @@ from crewai.utilities.events.tool_usage_events import (
ToolSelectionErrorEvent,
ToolUsageErrorEvent,
ToolUsageFinishedEvent,
ToolUsageStartedEvent,
ToolValidateInputErrorEvent,
)
@@ -169,6 +168,7 @@ class ToolUsage:
started_at = time.time()
from_cache = False
result = None
if self.tools_handler and self.tools_handler.cache:
result = self.tools_handler.cache.read(