mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 16:48:30 +00:00
This PR implements task decomposition as requested in Issue #2717. It allows complex tasks to be automatically split into sub-tasks without manual intervention. - Added parent_task and sub_tasks fields to Task class - Implemented decompose() method to create sub-tasks - Added combine_sub_task_results() method to aggregate results - Updated execute_sync() to handle sub-task execution - Added execute_sub_tasks_async() for asynchronous execution - Created tests for the task decomposition functionality - Added example script demonstrating usage Co-Authored-By: Joe Moura <joao@crewai.com>
49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
"""
|
|
Example of using task decomposition in CrewAI.
|
|
|
|
This example demonstrates how to use the task decomposition feature
|
|
to break down complex tasks into simpler sub-tasks.
|
|
"""
|
|
|
|
from crewai import Agent, Task, Crew
|
|
|
|
researcher = Agent(
|
|
role="Researcher",
|
|
goal="Research effectively",
|
|
backstory="You're an expert researcher with skills in breaking down complex topics.",
|
|
)
|
|
|
|
research_task = Task(
|
|
description="Research the impact of AI on various industries",
|
|
expected_output="A comprehensive report covering multiple industries",
|
|
agent=researcher,
|
|
)
|
|
|
|
sub_tasks = research_task.decompose(
|
|
descriptions=[
|
|
"Research AI impact on healthcare industry",
|
|
"Research AI impact on finance industry",
|
|
"Research AI impact on education industry",
|
|
],
|
|
expected_outputs=[
|
|
"A report on AI in healthcare",
|
|
"A report on AI in finance",
|
|
"A report on AI in education",
|
|
],
|
|
names=["Healthcare", "Finance", "Education"],
|
|
)
|
|
|
|
crew = Crew(
|
|
agents=[researcher],
|
|
tasks=[research_task],
|
|
)
|
|
|
|
result = crew.kickoff()
|
|
print(result)
|
|
|
|
|
|
#
|
|
#
|
|
#
|
|
#
|