From c3dc839b1232553724501167caa6fb17ace2639b Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 21 May 2025 04:03:52 +0000 Subject: [PATCH] docs: Update documentation for inject_date feature Co-Authored-By: Joe Moura --- docs/concepts/agents.mdx | 20 ++++++++++++++++++++ docs/usage_examples/inject_date_example.py | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/concepts/agents.mdx b/docs/concepts/agents.mdx index 4234e6428..9b5186cb0 100644 --- a/docs/concepts/agents.mdx +++ b/docs/concepts/agents.mdx @@ -58,6 +58,8 @@ The Visual Agent Builder enables: | **Embedder** _(optional)_ | `embedder` | `Optional[Dict[str, Any]]` | Configuration for the embedder used by the agent. | | **Knowledge Sources** _(optional)_ | `knowledge_sources` | `Optional[List[BaseKnowledgeSource]]` | Knowledge sources available to the agent. | | **Use System Prompt** _(optional)_ | `use_system_prompt` | `Optional[bool]` | Whether to use system prompt (for o1 model support). Default is True. | +| **Inject Date** _(optional)_ | `inject_date` | `bool` | Whether to automatically inject the current date into tasks. Default is False. | +| **Date Format** _(optional)_ | `date_format` | `str` | Format string for date when inject_date is enabled. Default is "%Y-%m-%d" (ISO format). | ## Creating Agents @@ -226,6 +228,18 @@ custom_agent = Agent( ) ``` +#### Date-Aware Agent +```python Code +date_aware_agent = Agent( + role="Market Analyst", + goal="Track market movements with precise date references", + backstory="Expert in time-sensitive financial analysis and reporting", + inject_date=True, # Automatically inject current date into tasks + date_format="%B %d, %Y", # Format as "May 21, 2025" + verbose=True +) +``` + ### Parameter Details #### Critical Parameters @@ -332,6 +346,12 @@ When `memory` is enabled, the agent will maintain context across multiple intera - Main `llm` for complex reasoning - `function_calling_llm` for efficient tool usage +### Date Awareness +- Use `inject_date: true` to provide agents with current date awareness +- Customize the date format with `date_format` using standard Python datetime format codes +- Valid format codes include: %Y (year), %m (month), %d (day), %B (full month name), etc. +- Invalid date formats will be logged as warnings and will not modify the task description + ### Model Compatibility - Set `use_system_prompt: false` for older models that don't support system messages - Ensure your chosen `llm` supports the features you need (like function calling) diff --git a/docs/usage_examples/inject_date_example.py b/docs/usage_examples/inject_date_example.py index 16ec6f963..32a97122f 100644 --- a/docs/usage_examples/inject_date_example.py +++ b/docs/usage_examples/inject_date_example.py @@ -1,4 +1,5 @@ from crewai import Agent, Task, Crew +from datetime import datetime agent = Agent( role="research_analyst", @@ -12,7 +13,7 @@ agent_custom_format = Agent( goal="Provide financial insights with proper date context", backstory="You are a financial analyst who needs precise date formatting.", inject_date=True, - date_format="%B %d, %Y", # Format as "May 21, 2025" + date_format="%B %d, %Y", # Format as "May 21, 2025" (Month Day, Year) ) task = Task( @@ -20,12 +21,14 @@ task = Task( expected_output="A comprehensive report on current market trends", agent=agent, ) +# task_custom = Task( description="Analyze financial data and provide insights", expected_output="A detailed financial analysis report", agent=agent_custom_format, ) +# crew = Crew( agents=[agent, agent_custom_format],