Hierarchical process (#206)

* Hierarchical process +  Docs
Co-authored-by: João Moura <joaomdmoura@gmail.com>
This commit is contained in:
Gui Vieira
2024-02-02 13:56:35 -03:00
committed by GitHub
parent 8fc0f33dd5
commit c78237cb86
12 changed files with 1358 additions and 74 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -142,6 +142,39 @@ def test_crew_creation():
)
@pytest.mark.vcr(filter_headers=["authorization"])
def test_hierarchical_process():
task = Task(
description="Come up with a list of 5 interesting ideas to explore for an article, then write one amazing paragraph highlight for each idea that showcases how good an article about this topic could be. Return the list of ideas with their paragraph and your notes.",
)
crew = Crew(
agents=[researcher, writer],
process=Process.hierarchical,
tasks=[task],
)
assert (
crew.kickoff()
== """Here are the 5 interesting ideas with a highlight paragraph for each:
1. "The Future of AI in Healthcare: Predicting Diseases Before They Happen"
- "Imagine a future where AI empowers us to detect diseases before they arise, transforming healthcare from reactive to proactive. Machine learning algorithms, trained on vast amounts of patient data, could potentially predict heart diseases, strokes, or cancers before they manifest, allowing for early interventions and significantly improving patient outcomes. This article will delve into the rapid advancements in AI within the healthcare sector and how these technologies are ushering us into a new era of predictive medicine."
2. "How AI is Changing the Way We Cook: An Insight into Smart Kitchens"
- "From the humble home kitchen to grand culinary stages, AI is revolutionizing the way we cook. Smart appliances, equipped with advanced sensors and predictive algorithms, are turning kitchens into creative playgrounds, offering personalized recipes, precise cooking instructions, and even automated meal preparation. This article explores the fascinating intersection of AI and gastronomy, revealing how technology is transforming our culinary experiences."
3. "Redefining Fitness with AI: Personalized Workout Plans and Nutritional Advice"
- "Fitness reimagined that's the promise of AI in the wellness industry. Picture a personal trainer who knows your strengths, weaknesses, and nutritional needs intimately. An AI-powered fitness app can provide this personalized experience, adapting your workout plans and dietary recommendations in real-time based on your progress and feedback. Join us as we unpack how AI is revolutionizing the fitness landscape, offering personalized, data-driven approaches to health and well-being."
4. "AI and the Art World: How Technology is Shaping Creativity"
- "Art and AI may seem like unlikely partners, but their synergy is sparking a creative revolution. AI algorithms are now creating mesmerizing artworks, challenging our perceptions of creativity and originality. From AI-assisted painting to generative music composition, this article will take you on a journey through the fascinating world of AI in art, exploring how technology is reshaping the boundaries of human creativity."
5. "AI in Space Exploration: The Next Frontier"
- "The vast expanse of space, once the sole domain of astronauts and rovers, is the next frontier for AI. AI technology is playing an increasingly vital role in space exploration, from predicting space weather to assisting in interstellar navigation. This article will delve into the exciting intersection of AI and space exploration, exploring how these advanced technologies are helping us uncover the mysteries of the cosmos.\""""
)
@pytest.mark.vcr(filter_headers=["authorization"])
def test_crew_with_delegating_agents():
tasks = [

View File

@@ -1,5 +1,7 @@
"""Test Agent creation and execution basic functionality."""
from unittest.mock import MagicMock, patch
from crewai.agent import Agent
from crewai.task import Task
@@ -27,7 +29,7 @@ def test_task_tool_reflect_agent_tools():
assert task.tools == [fake_tool]
def test_task_tool_takes_precedence_ove_agent_tools():
def test_task_tool_takes_precedence_over_agent_tools():
from langchain.tools import tool
@tool
@@ -47,7 +49,7 @@ def test_task_tool_takes_precedence_ove_agent_tools():
)
task = Task(
description="Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
description="Give me a list of 5 interesting ideas to explore for an article, what makes them unique and interesting.",
agent=researcher,
tools=[fake_task_tool],
)
@@ -69,8 +71,6 @@ def test_task_prompt_includes_expected_output():
agent=researcher,
)
from unittest.mock import patch
with patch.object(Agent, "execute_task") as execute:
execute.return_value = "ok"
task.execute()
@@ -78,8 +78,6 @@ def test_task_prompt_includes_expected_output():
def test_task_callback():
from unittest.mock import MagicMock
researcher = Agent(
role="Researcher",
goal="Make the best research and analysis on content about AI and AI agents",
@@ -94,12 +92,27 @@ def test_task_callback():
expected_output="Bullet point list of 5 interesting ideas.",
agent=researcher,
callback=task_completed,
allow_delegation=False,
)
from unittest.mock import patch
with patch.object(Agent, "execute_task") as execute:
execute.return_value = "ok"
task.execute()
task_completed.assert_called_once_with(task.output)
def test_execute_with_agent():
researcher = Agent(
role="Researcher",
goal="Make the best research and analysis on content about AI and AI agents",
backstory="You're an expert researcher, specialized in technology, software engineering, AI and startups. You work as a freelancer and is now working on doing research and analysis for a new customer.",
allow_delegation=False,
)
task = Task(
description="Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
expected_output="Bullet point list of 5 interesting ideas.",
)
with patch.object(Agent, "execute_task", return_value="ok") as execute:
task.execute(agent=researcher)
execute.assert_called_once_with(task=task._prompt(), context=None, tools=[])