From 79b0cfbc9b2b319ffca42fd65971ff47008e12ff Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 13 Mar 2025 05:21:40 +0000 Subject: [PATCH] Fix issue #2356: Missing parentheses in Flow documentation Co-Authored-By: Joe Moura --- docs/fix-issue-2356.md | 51 ++++++++++++++++++++++++++++++++ docs/guides/flows/first-flow.mdx | 4 +-- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 docs/fix-issue-2356.md diff --git a/docs/fix-issue-2356.md b/docs/fix-issue-2356.md new file mode 100644 index 000000000..14b279240 --- /dev/null +++ b/docs/fix-issue-2356.md @@ -0,0 +1,51 @@ +# Fix for Issue #2356: Missing Parentheses in Flow Documentation + +## Issue +In the "first-flow.mdx" documentation, there's an error in the code example where a task method reference is missing parentheses: + +```python +@task +def review_section_task(self) -> Task: + return Task( + config=self.tasks_config['review_section_task'], + context=[self.write_section_task] # Missing parentheses + ) +``` + +This causes an AttributeError when running `crewai flow kickoff` because the Flow system requires explicit method calls with parentheses. + +## Error Message +When users follow the documentation and use the code as shown, they encounter this error: +``` +AttributeError: 'function' object has no attribute 'get' +``` + +## Root Cause +The core issue is that the Flow system in CrewAI requires explicit method calls with parentheses when processing context tasks. This is implemented in the `_map_task_variables` method in `crew_base.py`: + +```python +if context_list := task_info.get("context"): + self.tasks_config[task_name]["context"] = [ + tasks[context_task_name]() for context_task_name in context_list + ] +``` + +When users follow the documentation and use `context=[self.write_section_task]` without parentheses, they get an AttributeError because a function object doesn't have a `get` attribute. + +## Fix +The correct code should be: + +```python +@task +def review_section_task(self) -> Task: + return Task( + config=self.tasks_config['review_section_task'], + context=[self.write_section_task()] # Added parentheses + ) +``` + +## Verification +I've created a minimal reproducible example that demonstrates both the error and the fix. The error occurs because in `crew_base.py`, the `_map_task_variables` method explicitly requires method calls with parentheses when processing context tasks. + +## Documentation Update Needed +The documentation at docs.crewai.com/guides/flows/first-flow needs to be updated to show the correct syntax with parentheses. diff --git a/docs/guides/flows/first-flow.mdx b/docs/guides/flows/first-flow.mdx index d3c346c76..ab03693b9 100644 --- a/docs/guides/flows/first-flow.mdx +++ b/docs/guides/flows/first-flow.mdx @@ -232,7 +232,7 @@ class ContentCrew(): def review_section_task(self) -> Task: return Task( config=self.tasks_config['review_section_task'], - context=[self.write_section_task] + context=[self.write_section_task()] ) @crew @@ -601,4 +601,4 @@ Now that you've built your first flow, you can: Congratulations! You've successfully built your first CrewAI Flow that combines regular code, direct LLM calls, and crew-based processing to create a comprehensive guide. These foundational skills enable you to create increasingly sophisticated AI applications that can tackle complex, multi-stage problems through a combination of procedural control and collaborative intelligence. - \ No newline at end of file +