Skip to content

Commit

Permalink
fix: bad crew creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisotee committed Nov 13, 2024
1 parent a541b0d commit b97bf7b
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 108 deletions.
2 changes: 1 addition & 1 deletion apps/ai_api/eda_ai_api/api/routes/supervisor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import APIRouter
from eda_ai_api.models.supervisor import SupervisorRequest, SupervisorResponse
from supervisor.crew import SupervisorCrew
from opportunity_finder.crew import OpportunityFinderCrew
from plugins.supervisor.crew import SupervisorCrew

router = APIRouter()

Expand Down
6 changes: 0 additions & 6 deletions plugins/supervisor/.env.example

This file was deleted.

18 changes: 9 additions & 9 deletions plugins/supervisor/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpportunityFinder Crew
# Supervisor Crew

Welcome to the OpportunityFinder Crew project, powered by [crewAI](https://crewai.com). This template is designed to help you set up a multi-agent AI system with ease, leveraging the powerful and flexible framework provided by crewAI. Our goal is to enable your agents to collaborate effectively on complex tasks, maximizing their collective intelligence and capabilities.
Welcome to the Supervisor Crew project, powered by [crewAI](https://crewai.com). This template is designed to help you set up a multi-agent AI system with ease, leveraging the powerful and flexible framework provided by crewAI. Our goal is to enable your agents to collaborate effectively on complex tasks, maximizing their collective intelligence and capabilities.

## Installation

Expand All @@ -22,10 +22,10 @@ crewai install

**Add your `OPENAI_API_KEY` into the `.env` file**

- Modify `src/opportunity_finder/config/agents.yaml` to define your agents
- Modify `src/opportunity_finder/config/tasks.yaml` to define your tasks
- Modify `src/opportunity_finder/crew.py` to add your own logic, tools and specific args
- Modify `src/opportunity_finder/main.py` to add custom inputs for your agents and tasks
- Modify `src/supervisor/config/agents.yaml` to define your agents
- Modify `src/supervisor/config/tasks.yaml` to define your tasks
- Modify `src/supervisor/crew.py` to add your own logic, tools and specific args
- Modify `src/supervisor/main.py` to add custom inputs for your agents and tasks

## Running the Project

Expand All @@ -35,17 +35,17 @@ To kickstart your crew of AI agents and begin task execution, run this from the
$ crewai run
```

This command initializes the opportunity-finder Crew, assembling the agents and assigning them tasks as defined in your configuration.
This command initializes the supervisor Crew, assembling the agents and assigning them tasks as defined in your configuration.

This example, unmodified, will run the create a `report.md` file with the output of a research on LLMs in the root folder.

## Understanding Your Crew

The opportunity-finder Crew is composed of multiple AI agents, each with unique roles, goals, and tools. These agents collaborate on a series of tasks, defined in `config/tasks.yaml`, leveraging their collective skills to achieve complex objectives. The `config/agents.yaml` file outlines the capabilities and configurations of each agent in your crew.
The supervisor Crew is composed of multiple AI agents, each with unique roles, goals, and tools. These agents collaborate on a series of tasks, defined in `config/tasks.yaml`, leveraging their collective skills to achieve complex objectives. The `config/agents.yaml` file outlines the capabilities and configurations of each agent in your crew.

## Support

For support, questions, or feedback regarding the OpportunityFinder Crew or crewAI.
For support, questions, or feedback regarding the Supervisor Crew or crewAI.
- Visit our [documentation](https://docs.crewai.com)
- Reach out to us through our [GitHub repository](https://github.com/joaomdmoura/crewai)
- [Join our Discord](https://discord.com/invite/X4JWnZnxPb)
Expand Down
12 changes: 6 additions & 6 deletions plugins/supervisor/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[project]
name = "supervisor"
version = "0.1.0"
description = "Supervisor crew using crewAI"
description = "supervisor using crewAI"
authors = [{ name = "Your Name", email = "[email protected]" }]
requires-python = ">=3.10,<=3.13"
dependencies = [
"crewai[agentops,tools]>=0.76.2,<1.0.0",
"crewai[tools]>=0.79.4,<1.0.0"
]

[project.scripts]
supervisor = "supervisor.main:run"
run_crew = "supervisor.main:run"

[tool.hatch.build.targets.wheel]
packages = ["src/supervisor"]
train = "supervisor.main:train"
replay = "supervisor.main:replay"
test = "supervisor.main:test"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
build-backend = "hatchling.build"
20 changes: 10 additions & 10 deletions plugins/supervisor/src/supervisor/crew.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import datetime
import os
from crewai import Agent, Crew, Process, Task, LLM
from crewai.project import CrewBase, agent, crew, task

Expand All @@ -10,10 +10,11 @@
temperature=0.5,
)


@CrewBase
class SupervisorCrew:
"""Supervisor crew"""
agents_config = "config/agents.yaml"
tasks_config = "config/tasks.yaml"

@agent
def decision_maker(self) -> Agent:
Expand All @@ -24,20 +25,19 @@ def decision_maker(self) -> Agent:
llm=cerebras_llm,
)

@task
def route_decision_task(self, message: str) -> Task:
return Task(
config=self.tasks_config["route_decision_task"],
context={"message": message},
)
@task
def route_decision_task(self) -> Task:
return Task(config=self.tasks_config["route_decision_task"])

@crew
def crew(self) -> Crew:
"""Creates the Supervisor crew"""
return Crew(
agents=[self.decision_maker],
tasks=[self.route_decision_task],
tasks=[self.route_decision_task],
process=Process.sequential,
verbose=True,
output_log_file=f'SupervisorCrew_{datetime.datetime.now().strftime("%Y%m%d_%H%M%S")}.log',
output_log_file=f'SupervisorCrew_{datetime.datetime.now().strftime("%Y%m%d_%H%M%S")}.log'
)

__all__ = ["SupervisorCrew"]
29 changes: 22 additions & 7 deletions plugins/supervisor/src/supervisor/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
from supervisor.crew import SupervisorCrew
#!/usr/bin/env python
import sys
from supervisor.crew import Supervisor


def run():
"""Run the supervisor crew"""
crew = SupervisorCrew()
result = crew.crew().kickoff(
inputs={"message": "Find grant opportunities for AI projects"}
)
print(f"Decision: {result}")
"""
Run the crew for routing decision.
"""
inputs = {"message": "I need to find grant opportunities for my research"}
result = Supervisor().crew().kickoff(inputs=inputs)
return result


def test():
"""
Test the crew execution and returns the results.
"""
inputs = {"message": "I need to find grant opportunities for my research"}
try:
Supervisor().crew().test(
n_iterations=int(sys.argv[1]), openai_model_name=sys.argv[2], inputs=inputs
)
except Exception as e:
raise Exception(f"An error occurred while testing the crew: {e}")


if __name__ == "__main__":
Expand Down
9 changes: 8 additions & 1 deletion plugins/supervisor/src/supervisor/tools/custom_tool.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from crewai_tools import BaseTool
from crewai.tools import BaseTool
from typing import Type
from pydantic import BaseModel, Field


class MyCustomToolInput(BaseModel):
"""Input schema for MyCustomTool."""
argument: str = Field(..., description="Description of the argument.")

class MyCustomTool(BaseTool):
name: str = "Name of my tool"
description: str = (
"Clear description for what this tool is useful for, you agent will need this information to use it."
)
args_schema: Type[BaseModel] = MyCustomToolInput

def _run(self, argument: str) -> str:
# Implementation goes here
Expand Down
Loading

0 comments on commit b97bf7b

Please sign in to comment.