mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 00:28:31 +00:00
Fix issue #2402: Handle missing templates gracefully
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
47
tests/test_templates.py
Normal file
47
tests/test_templates.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Test template handling in Agent creation."""
|
||||
|
||||
import pytest
|
||||
from crewai import Agent, Task, Crew
|
||||
|
||||
|
||||
def test_agent_with_only_system_template():
|
||||
"""Test that an agent with only system_template works without errors."""
|
||||
agent = Agent(
|
||||
role="Test Role",
|
||||
goal="Test Goal",
|
||||
backstory="Test Backstory",
|
||||
allow_delegation=False,
|
||||
system_template="You are a test agent...",
|
||||
# prompt_template is intentionally missing
|
||||
)
|
||||
|
||||
task = Task(description="Test task", agent=agent, expected_output="Test output")
|
||||
|
||||
# This should not raise an error
|
||||
try:
|
||||
agent.execute_task(task)
|
||||
assert True
|
||||
except AttributeError:
|
||||
pytest.fail("AttributeError was raised with only system_template")
|
||||
|
||||
|
||||
def test_agent_with_missing_response_template():
|
||||
"""Test that an agent with system_template and prompt_template but no response_template works without errors."""
|
||||
agent = Agent(
|
||||
role="Test Role",
|
||||
goal="Test Goal",
|
||||
backstory="Test Backstory",
|
||||
allow_delegation=False,
|
||||
system_template="You are a test agent...",
|
||||
prompt_template="This is a test prompt...",
|
||||
# response_template is intentionally missing
|
||||
)
|
||||
|
||||
task = Task(description="Test task", agent=agent, expected_output="Test output")
|
||||
|
||||
# This should not raise an error
|
||||
try:
|
||||
agent.execute_task(task)
|
||||
assert True
|
||||
except AttributeError:
|
||||
pytest.fail("AttributeError was raised with missing response_template")
|
||||
Reference in New Issue
Block a user