Skip to content

Commit

Permalink
v1 of self evaluation loop with flows working
Browse files Browse the repository at this point in the history
  • Loading branch information
bhancockio committed Oct 28, 2024
1 parent 156b290 commit 71f0f20
Show file tree
Hide file tree
Showing 22 changed files with 4,815 additions and 88 deletions.
37 changes: 20 additions & 17 deletions email_auto_responder_flow/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
[tool.poetry]
[project]
name = "email_auto_responder_flow"
version = "0.1.0"
description = "email_auto_responder_flow using crewAI"
authors = ["Your Name <you@example.com>"]
authors = [
{ name = "Your Name", email = "you@example.com" },
]
requires-python = ">=3.10,<=3.13"
dependencies = [
"crewai[tools]>=0.76.2,<1.0.0",
"asyncio*",
"langchain-tools>=0.1.34",
"crewai-tools>=0.12.0",
"google-auth-oauthlib>=1.2.1",
"google-api-python-client>=2.145.0",
]

[tool.poetry.dependencies]
python = ">=3.10,<=3.13"
crewai = { extras = ["tools"], version = ">=0.67.1,<1.0.0" }
asyncio = "*"
langchain-tools = "^0.1.34"
crewai-tools = "^0.12.0"
google-auth-oauthlib = "^1.2.1"
google-api-python-client = "^2.145.0"

[tool.poetry.scripts]
email_auto_responder_flow = "email_auto_responder_flow.main:main"
run_flow = "email_auto_responder_flow.main:main"
plot_flow = "email_auto_responder_flow.main:plot"
[project.scripts]
kickoff = "email_auto_responder_flow.main:kickoff"
plot = "email_auto_responder_flow.main:plot"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = [
"hatchling",
]
build-backend = "hatchling.build"
15 changes: 3 additions & 12 deletions email_auto_responder_flow/src/email_auto_responder_flow/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
import asyncio
import time
from typing import List

Expand Down Expand Up @@ -45,29 +44,21 @@ def generate_draft_responses(self):
time.sleep(180)


async def run_flow():
def kickoff():
"""
Run the flow.
"""
email_auto_response_flow = EmailAutoResponderFlow()
email_auto_response_flow.kickoff()


async def plot_flow():
def plot_flow():
"""
Plot the flow.
"""
email_auto_response_flow = EmailAutoResponderFlow()
email_auto_response_flow.plot()


def main():
asyncio.run(run_flow())


def plot():
asyncio.run(plot_flow())


if __name__ == "__main__":
main()
kickoff()
31 changes: 17 additions & 14 deletions meeting_assistant_flow/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
[tool.poetry]
[project]
name = "meeting_assistant_flow"
version = "0.1.0"
description = "meeting_assistant_flow using crewAI"
authors = ["Your Name <you@example.com>"]
authors = [
{ name = "Your Name", email = "you@example.com" },
]
requires-python = ">=3.10,<=3.13"
dependencies = [
"crewai[tools]>=0.76.2,<1.0.0",
"asyncio*",
"slack-sdk>=3.33.1",
]

[tool.poetry.dependencies]
python = ">=3.10,<=3.13"
crewai = { extras = ["tools"], version = ">=0.67.1,<1.0.0" }
asyncio = "*"
slack-sdk = "^3.33.1"

[tool.poetry.scripts]
meeting_assistant_flow = "meeting_assistant_flow.main:main"
run_flow = "meeting_assistant_flow.main:main"
plot_flow = "meeting_assistant_flow.main:plot"
[project.scripts]
kickoff = "meeting_assistant_flow.main:kickoff"
plot = "meeting_assistant_flow.main:plot"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = [
"hatchling",
]
build-backend = "hatchling.build"
15 changes: 3 additions & 12 deletions meeting_assistant_flow/src/meeting_assistant_flow/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
import asyncio
import csv
import os
from typing import List
Expand Down Expand Up @@ -67,29 +66,21 @@ def send_slack_notification(self):
send_message_to_channel(message)


async def run_flow():
def kickoff():
"""
Run the flow.
"""
meeting_flow = MeetingFlow()
meeting_flow.kickoff()


async def plot_flow():
def plot():
"""
Plot the flow.
"""
meeting_flow = MeetingFlow()
meeting_flow.plot()


def main():
asyncio.run(run_flow())


def plot():
asyncio.run(plot_flow())


if __name__ == "__main__":
main()
kickoff()
3 changes: 3 additions & 0 deletions self_evalulation_loop_flow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
__pycache__/
lib/
56 changes: 56 additions & 0 deletions self_evalulation_loop_flow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# {{crew_name}} Crew

Welcome to the {{crew_name}} 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

Ensure you have Python >=3.10 <=3.13 installed on your system. This project uses [UV](https://docs.astral.sh/uv/) for dependency management and package handling, offering a seamless setup and execution experience.

First, if you haven't already, install uv:

```bash
pip install uv
```

Next, navigate to your project directory and install the dependencies:

(Optional) Lock the dependencies and install them by using the CLI command:
```bash
crewai install
```

### Customizing

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

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

## Running the Project

To kickstart your crew of AI agents and begin task execution, run this from the root folder of your project:

```bash
crewai run
```

This command initializes the flow-self-evalulation-loop 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 flow-self-evalulation-loop 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 {{crew_name}} 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)
- [Chat with our docs](https://chatg.pt/DWjSBZn)

Let's create wonders together with the power and simplicity of crewAI.
202 changes: 202 additions & 0 deletions self_evalulation_loop_flow/crewai_flow.html

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions self_evalulation_loop_flow/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[project]
name = "self_evaluation_loop_flow"
version = "0.1.0"
description = "self-evalulation-loop-flow using crewAI"
authors = [{ name = "Your Name", email = "you@example.com" }]
requires-python = ">=3.10,<=3.13"
dependencies = [
"crewai[tools]>=0.76.2,<1.0.0",
]

[project.scripts]
kickoff = "self_evaluation_loop_flow.main:kickoff"
plot = "self_evaluation_loop_flow.main:plot"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
shakespearean_bard:
role: >
Shakespearean Bard
goal: >
Craft sarcastic and playful hot takes in the style of Shakespeare.
Ensure that all responses fit within 280 characters and contain no emojis.
backstory: >
Thou art a witty bard, renowned for turning the mundane into the
magnificent with thy playful jests and biting sarcasm. Armed with wit and
wisdom, thou dost revel in the creation of humorous quips most pleasing to the ear.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
write_x_post:
description: >
Given the topic '{topic}', compose a humorous hot take in the style of Shakespeare.
The tone should be sarcastic and playful. The final short form social media post
must be over 200 characters and not exceed 280 characters, and emojis are strictly forbidden.
Please incorporate the following feedback if present:
{feedback}
expected_output: >
A witty, Shakespearean hot take between 200 and 280 characters [Inclusive].
agent: shakespearean_bard

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
from self_evaluation_loop_flow.tools.CharacterCounterTool import CharacterCounterTool


@CrewBase
class ShakespeareanXPostCrew:
"""Shakespearean X Post Crew"""

agents_config = "config/agents.yaml"
tasks_config = "config/tasks.yaml"

@agent
def shakespearean_bard(self) -> Agent:
return Agent(
config=self.agents_config["shakespearean_bard"],
tools=[CharacterCounterTool()],
)

@task
def write_x_post(self) -> Task:
return Task(
config=self.tasks_config["write_x_post"],
)

@crew
def crew(self) -> Crew:
"""Creates the Shakespearean X Post Crew"""
return Crew(
agents=self.agents, # Automatically created by the @agent decorator
tasks=self.tasks, # Automatically created by the @task decorator
process=Process.sequential,
verbose=True,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
x_post_verifier:
role: >
X Post Verifier
goal: >
Ensure that any X post meets the strict guidelines:
it must be under 280 characters, contain no emojis, and be free of additional commentary.
backstory: >
You are a careful reviewer, skilled at understanding the core message of a post.
Your job is to maintain the clarity and brevity of the post by ensuring it contains no emojis,
unnecessary commentary, or excessive verbosity.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
verify_x_post:
description: >
Verify that the given X post meets the following criteria:
- It is between 200 and 280 characters inclusive.
- It contains no emojis.
- It contains only the post itself, without additional commentary.
The post should follow the 1-3-1 rule:
- 1 bold statement to hook the reader
- 3 lines of supporting information
- 1 sentence to summarize the post
Additionally, if you believe there are any issues with the post
or ways it could be improved, such as the structure of the post,
rhythm, word choice, please provide feedback.
If any of the criteria are not met, the post is considered invalid.
Provide actionable changes about what is wrong and what actions
need to be taken to fix the post.
Your final response must include:
- Valid: True/False
- Feedback: Provide commentary if the post fails any of the criteria.
X Post to Verify:
{x_post}
expected_output: >
Pass: True/False
Feedback: Commentary here if failed.
agent: x_post_verifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import Optional

from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
from pydantic import BaseModel
from self_evaluation_loop_flow.tools.CharacterCounterTool import CharacterCounterTool


class XPostVerification(BaseModel):
valid: bool
feedback: Optional[str]


@CrewBase
class XPostReviewCrew:
"""X Post Review Crew"""

agents_config = "config/agents.yaml"
tasks_config = "config/tasks.yaml"

@agent
def x_post_verifier(self) -> Agent:
return Agent(
config=self.agents_config["x_post_verifier"],
tools=[CharacterCounterTool()],
)

@task
def verify_x_post(self) -> Task:
return Task(
config=self.tasks_config["verify_x_post"],
output_pydantic=XPostVerification,
)

@crew
def crew(self) -> Crew:
"""Creates the X Post Review Crew"""
return Crew(
agents=self.agents,
tasks=self.tasks,
process=Process.sequential,
verbose=True,
)
Loading

0 comments on commit 71f0f20

Please sign in to comment.