Replies: 1 comment
-
|
This constraint exists because crewAI needs to collect results before the crew completes. Here's how to work around it: Understanding the ConstraintThe final task(s) must be synchronous so the crew can:
Pattern: Parallel Async + Sync Aggregatorfrom crewai import Task, Crew, Agent
# These can run in parallel
logistics_task = Task(
description="Handle logistics...",
async_execution=True, # Runs async
agent=logistics_agent
)
marketing_task = Task(
description="Handle marketing...",
async_execution=True, # Runs async
agent=marketing_agent
)
# Final task MUST be sync to collect results
aggregation_task = Task(
description="Combine logistics and marketing results into final report",
async_execution=False, # Sync - collects async results
agent=coordinator_agent,
context=[logistics_task, marketing_task] # Waits for both
)
crew = Crew(
agents=[logistics_agent, marketing_agent, coordinator_agent],
tasks=[logistics_task, marketing_task, aggregation_task] # Ends with sync
)Why This Works
Alternative: External StateIf you truly need multiple async endpoints: state = {"results": {}}
# Each async task writes to state
def on_logistics_complete(output):
state["results"]["logistics"] = output
def on_marketing_complete(output):
state["results"]["marketing"] = outputThis decouples result collection from the crew execution. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm experiencing an issue with the crewAI library when trying to include multiple asynchronous tasks within a single Crew. According to the official documentation and examples, it seems possible to have multiple asynchronous tasks in one crew. However, I'm encountering an error that suggests otherwise.
Problem Details:
Steps I've Taken:
Documentation Review: Re-examined the "Automate Event Planning" lesson and official documentation. Confirmed that multiple asynchronous tasks are used in a single crew in the examples.
Questions:
Any help or guidance would be greatly appreciated!
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions