Fix issue #2356: Missing parentheses in Flow documentation

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-03-13 05:21:40 +00:00
parent 41a670166a
commit 79b0cfbc9b
2 changed files with 53 additions and 2 deletions

51
docs/fix-issue-2356.md Normal file
View File

@@ -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.

View File

@@ -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:
<Check>
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.
</Check>
</Check>