Add inject_date flag to Agent for automatic date injection (#2870)

* feat: Add inject_date flag to Agent for automatic date injection

Co-Authored-By: Joe Moura <joao@crewai.com>

* feat: Add date_format parameter and error handling to inject_date feature

Co-Authored-By: Joe Moura <joao@crewai.com>

* fix: Update test implementation for inject_date feature

Co-Authored-By: Joe Moura <joao@crewai.com>

* fix: Add date format validation to prevent invalid formats

Co-Authored-By: Joe Moura <joao@crewai.com>

* docs: Update documentation for inject_date feature

Co-Authored-By: Joe Moura <joao@crewai.com>

* unnecesary

* new tests

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Joe Moura <joao@crewai.com>
Co-authored-by: João Moura <joaomdmoura@gmail.com>
This commit is contained in:
devin-ai-integration[bot]
2025-05-21 12:58:57 -07:00
committed by GitHub
parent 9945da7dbe
commit c1672613bc
11 changed files with 1277 additions and 0 deletions

View File

@@ -398,6 +398,79 @@ def test_output_json_hierarchical():
assert result.json == '{"score": 4}'
assert result.to_dict() == {"score": 4}
@pytest.mark.vcr(filter_headers=["authorization"])
def test_inject_date():
reporter = Agent(
role="Reporter",
goal="Report the date",
backstory="You're an expert reporter, specialized in reporting the date.",
allow_delegation=False,
inject_date=True,
)
task = Task(
description="What is the date today?",
expected_output="The date today as you were told, same format as the date you were told.",
agent=reporter,
)
crew = Crew(
agents=[reporter],
tasks=[task],
process=Process.sequential,
)
result = crew.kickoff()
assert "2025-05-21" in result.raw
@pytest.mark.vcr(filter_headers=["authorization"])
def test_inject_date_custom_format():
reporter = Agent(
role="Reporter",
goal="Report the date",
backstory="You're an expert reporter, specialized in reporting the date.",
allow_delegation=False,
inject_date=True,
date_format="%B %d, %Y",
)
task = Task(
description="What is the date today?",
expected_output="The date today.",
agent=reporter,
)
crew = Crew(
agents=[reporter],
tasks=[task],
process=Process.sequential,
)
result = crew.kickoff()
assert "May 21, 2025" in result.raw
@pytest.mark.vcr(filter_headers=["authorization"])
def test_no_inject_date():
reporter = Agent(
role="Reporter",
goal="Report the date",
backstory="You're an expert reporter, specialized in reporting the date.",
allow_delegation=False,
inject_date=False,
)
task = Task(
description="What is the date today?",
expected_output="The date today.",
agent=reporter,
)
crew = Crew(
agents=[reporter],
tasks=[task],
process=Process.sequential,
)
result = crew.kickoff()
assert "2025-05-21" not in result.raw
@pytest.mark.vcr(filter_headers=["authorization"])
def test_json_property_without_output_json():