Skip to content

Commit

Permalink
adding manager_llm
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomdmoura committed Feb 6, 2024
1 parent 2f0bf3b commit 09bec0e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 102 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 0 additions & 95 deletions docs/getting-started.md

This file was deleted.

10 changes: 9 additions & 1 deletion docs/how-to/Creating-a-Crew-and-kick-it-off.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ description: A step-by-step guide to creating a cohesive CrewAI team for your pr
---

## Introduction
Assembling a crew in CrewAI is akin to casting for a play, where each agent plays a unique role. This guide walks you through creating a crew, assigning roles and tasks, and activating them to work in harmony.
Embarking on your CrewAI journey involves a few straightforward steps to set up your environment and initiate your AI crew. This guide ensures a seamless start.

## Step 0: Installation
Begin by installing CrewAI and any additional packages required for your project. For instance, the `duckduckgo-search` package is used in this example for enhanced search capabilities.

```shell
pip install crewai
pip install duckduckgo-search
```

## Step 1: Assemble Your Agents
Begin by defining your agents with distinct roles and backstories. These elements not only add depth but also guide their task execution and interaction within the crew.
Expand Down
5 changes: 5 additions & 0 deletions docs/how-to/Hierarchical.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ To utilize the hierarchical process, you must define a crew with a designated ma
!!! note "Tools on the hierarchical process"
For tools when using the hierarchical process, you want to make sure to assign them to the agents instead of the tasks, as the manager will be the one delegating the tasks and the agents will be the ones executing them.

!!! note "Manager LLM"
A manager will be automatically set for the crew, you don't need to define it. You do need to set the `manager_llm` parameter in the crew though.

```python
from langchain_openai import ChatOpenAI
from crewai import Crew, Process, Agent

# Define your agents, no need to define a manager
Expand All @@ -42,6 +46,7 @@ writer = Agent(
project_crew = Crew(
tasks=[...], # Tasks that that manager will figure out how to complete
agents=[researcher, writer],
manager_llm=ChatOpenAI(temperature=0, model="gpt-4"), # The manager's LLM that will be used internally
process=Process.hierarchical # Designating the hierarchical approach
)
```
Expand Down
25 changes: 20 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By
<div style="width:30%">
<h2>How-To Guides</h2>
<ul>
<li>
<a href="./how-to/Creating-a-Crew-and-kick-it-off">
Getting Started
</a>
</li>
<li>
<a href="./how-to/how-to/Sequential">
Using Sequential Process
</a>
</li>
<li>
<a href="./how-to/Hierarchical">
Using Hierarchical Process
</a>
</li>
<li>
<a href="./how-to/LLM-Connections">
Connecting to LLMs
Expand All @@ -43,11 +58,6 @@ Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By
Customizing Agents
</a>
</li>
<li>
<a href="./how-to/Creating-a-Crew-and-kick-it-off">
Creating a Crew and kick it off
</a>
</li>
<li>
<a href="./how-to/Human-Input-on-Execution">
Human Input on Execution
Expand All @@ -58,6 +68,11 @@ Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By
<div style="width:30%">
<h2>Examples</h2>
<ul>
<li>
<a target='_blank' href="https://github.com/joaomdmoura/crewAI-examples/tree/main/prep-for-a-meeting">
Prepare for meetings
</a>
</li>
<li>
<a target='_blank' href="https://github.com/joaomdmoura/crewAI-examples/tree/main/trip_planner">
Trip Planner Crew
Expand Down
3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ nav:
- Processes: 'core-concepts/Processes.md'
- Collaboration: 'core-concepts/Collaboration.md'
- How to Guides:
- Creating a Crew Automation: 'how-to/Creating-a-Crew-and-kick-it-off.md'
- Getting Started: 'how-to/Creating-a-Crew-and-kick-it-off.md'
- Using Sequential Process: 'how-to/Sequential.md'
- Using Hierarchical Process: 'how-to/Hierarchical.md'
- Connecting to any LLM: 'how-to/LLM-Connections.md'
Expand All @@ -139,6 +139,7 @@ nav:
- Game Generator: https://github.com/joaomdmoura/crewAI-examples/tree/main/game-builder-crew"
- Drafting emails with LangGraph: https://github.com/joaomdmoura/crewAI-examples/tree/main/CrewAI-LangGraph"
- Landing Page Generator: https://github.com/joaomdmoura/crewAI-examples/tree/main/landing_page_generator"
- Prepare for meetings: https://github.com/joaomdmoura/crewAI-examples/tree/main/prep-for-a-meeting"
extra_css:
- stylesheets/output.css
- stylesheets/extra.css
Expand Down
15 changes: 15 additions & 0 deletions src/crewai/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Crew(BaseModel):
Attributes:
tasks: List of tasks assigned to the crew.
agents: List of agents part of this crew.
manager_llm: The language model that will run manager agent.
process: The process flow that the crew will follow (e.g., sequential).
verbose: Indicates the verbosity level for logging during execution.
config: Configuration settings for the crew.
Expand All @@ -47,6 +48,9 @@ class Crew(BaseModel):
agents: List[Agent] = Field(default_factory=list)
process: Process = Field(default=Process.sequential)
verbose: Union[int, bool] = Field(default=0)
manager_llm: Optional[Any] = Field(
description="Language model that will run the agent.", default=None
)
config: Optional[Union[Json, Dict[str, Any]]] = Field(default=None)
id: UUID4 = Field(default_factory=uuid.uuid4, frozen=True)
max_rpm: Optional[int] = Field(
Expand Down Expand Up @@ -90,6 +94,17 @@ def set_private_attrs(self) -> "Crew":
self._rpm_controller = RPMController(max_rpm=self.max_rpm, logger=self._logger)
return self

@model_validator(mode="after")
def check_manager_llm(self):
"""Validates that the language model is set when using hierarchical process."""
if self.process == Process.hierarchical and not self.manager_llm:
raise PydanticCustomError(
"missing_manager_llm",
"Attribute `manager_llm` is required when using hierarchical process.",
{},
)
return self

@model_validator(mode="after")
def check_config(self):
"""Validates that the crew is properly configured with agents and tasks."""
Expand Down
17 changes: 17 additions & 0 deletions tests/crew_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json

import pydantic_core
import pytest

from crewai.agent import Agent
Expand Down Expand Up @@ -144,13 +145,16 @@ def test_crew_creation():

@pytest.mark.vcr(filter_headers=["authorization"])
def test_hierarchical_process():
from langchain_openai import ChatOpenAI

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,
manager_llm=ChatOpenAI(temperature=0, model="gpt-4"),
tasks=[task],
)

Expand All @@ -175,6 +179,19 @@ def test_hierarchical_process():
)


def test_manager_llm_requirement_for_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.",
)

with pytest.raises(pydantic_core._pydantic_core.ValidationError):
Crew(
agents=[researcher, writer],
process=Process.hierarchical,
tasks=[task],
)


@pytest.mark.vcr(filter_headers=["authorization"])
def test_crew_with_delegating_agents():
tasks = [
Expand Down

0 comments on commit 09bec0e

Please sign in to comment.