Made basic crewai flow.
This commit is contained in:
56
README.md
56
README.md
@@ -1,2 +1,56 @@
|
|||||||
# repo_software_builder_agent
|
# {{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.14 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/repo_software_builder_agent/config/agents.yaml` to define your agents
|
||||||
|
- Modify `src/repo_software_builder_agent/config/tasks.yaml` to define your tasks
|
||||||
|
- Modify `src/repo_software_builder_agent/crew.py` to add your own logic, tools and specific args
|
||||||
|
- Modify `src/repo_software_builder_agent/main.py` to add custom inputs for your agents and tasks
|
||||||
|
|
||||||
|
## Running the Project
|
||||||
|
|
||||||
|
To kickstart your flow and begin execution, run this from the root folder of your project:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
crewai run
|
||||||
|
```
|
||||||
|
|
||||||
|
This command initializes the repo_software_builder_agent Flow as defined in your configuration.
|
||||||
|
|
||||||
|
This example, unmodified, will run a content creation flow on AI Agents and save the output to `output/post.md`.
|
||||||
|
|
||||||
|
## Understanding Your Crew
|
||||||
|
|
||||||
|
The repo_software_builder_agent 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.
|
||||||
|
|||||||
22
pyproject.toml
Normal file
22
pyproject.toml
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
[project]
|
||||||
|
name = "repo_software_builder_agent"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "repo_software_builder_agent using crewAI"
|
||||||
|
authors = [{ name = "Your Name", email = "you@example.com" }]
|
||||||
|
requires-python = ">=3.10,<3.14"
|
||||||
|
dependencies = [
|
||||||
|
"crewai[tools]==1.14.2"
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
kickoff = "repo_software_builder_agent.main:kickoff"
|
||||||
|
run_crew = "repo_software_builder_agent.main:kickoff"
|
||||||
|
plot = "repo_software_builder_agent.main:plot"
|
||||||
|
run_with_trigger = "repo_software_builder_agent.main:run_with_trigger"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["hatchling"]
|
||||||
|
build-backend = "hatchling.build"
|
||||||
|
|
||||||
|
[tool.crewai]
|
||||||
|
type = "flow"
|
||||||
0
src/repo_software_builder_agent/__init__.py
Normal file
0
src/repo_software_builder_agent/__init__.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
planner:
|
||||||
|
role: >
|
||||||
|
Content Planner
|
||||||
|
goal: >
|
||||||
|
Plan a detailed and engaging blog post outline on {topic}
|
||||||
|
backstory: >
|
||||||
|
You're an experienced content strategist who excels at creating
|
||||||
|
structured outlines for blog posts. You know how to organize ideas
|
||||||
|
into a logical flow that keeps readers engaged from start to finish.
|
||||||
|
|
||||||
|
writer:
|
||||||
|
role: >
|
||||||
|
Content Writer
|
||||||
|
goal: >
|
||||||
|
Write a compelling and well-structured blog post on {topic}
|
||||||
|
based on the provided outline
|
||||||
|
backstory: >
|
||||||
|
You're a skilled writer with a talent for turning outlines into
|
||||||
|
engaging, informative blog posts. Your writing is clear, conversational,
|
||||||
|
and backed by solid reasoning. You adapt your tone to the subject matter
|
||||||
|
while keeping things accessible to a broad audience.
|
||||||
|
|
||||||
|
editor:
|
||||||
|
role: >
|
||||||
|
Content Editor
|
||||||
|
goal: >
|
||||||
|
Review and polish the blog post on {topic} to ensure it is
|
||||||
|
publication-ready
|
||||||
|
backstory: >
|
||||||
|
You're a meticulous editor with years of experience refining written
|
||||||
|
content. You have an eye for clarity, flow, grammar, and consistency.
|
||||||
|
You improve prose without changing the author's voice and ensure every
|
||||||
|
piece you touch is polished and professional.
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
planning_task:
|
||||||
|
description: >
|
||||||
|
Create a detailed outline for a blog post about {topic}.
|
||||||
|
|
||||||
|
The outline should include:
|
||||||
|
- A compelling title
|
||||||
|
- An introduction hook
|
||||||
|
- 3-5 main sections with key points to cover in each
|
||||||
|
- A conclusion with a call to action
|
||||||
|
|
||||||
|
Make the outline detailed enough that a writer can produce
|
||||||
|
a full blog post from it without additional research.
|
||||||
|
expected_output: >
|
||||||
|
A structured blog post outline with a title, introduction notes,
|
||||||
|
detailed section breakdowns, and conclusion notes.
|
||||||
|
agent: planner
|
||||||
|
|
||||||
|
writing_task:
|
||||||
|
description: >
|
||||||
|
Using the outline provided, write a full blog post about {topic}.
|
||||||
|
|
||||||
|
Requirements:
|
||||||
|
- Follow the outline structure closely
|
||||||
|
- Write in a clear, engaging, and conversational tone
|
||||||
|
- Each section should be 2-3 paragraphs
|
||||||
|
- Include a strong introduction and conclusion
|
||||||
|
- Target around 800-1200 words
|
||||||
|
expected_output: >
|
||||||
|
A complete blog post in markdown format, ready for editing.
|
||||||
|
The post should follow the outline and be well-written with
|
||||||
|
clear transitions between sections.
|
||||||
|
agent: writer
|
||||||
|
|
||||||
|
editing_task:
|
||||||
|
description: >
|
||||||
|
Review and edit the blog post about {topic}.
|
||||||
|
|
||||||
|
Focus on:
|
||||||
|
- Fixing any grammar or spelling errors
|
||||||
|
- Improving sentence clarity and flow
|
||||||
|
- Ensuring consistent tone throughout
|
||||||
|
- Strengthening the introduction and conclusion
|
||||||
|
- Removing any redundancy
|
||||||
|
|
||||||
|
Do not rewrite the post — refine and polish it.
|
||||||
|
expected_output: >
|
||||||
|
The final, polished blog post in markdown format without '```'.
|
||||||
|
Publication-ready with clean formatting and professional prose.
|
||||||
|
agent: editor
|
||||||
|
output_file: output/post.md
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
from crewai import Agent, Crew, Process, Task
|
||||||
|
from crewai.agents.agent_builder.base_agent import BaseAgent
|
||||||
|
from crewai.project import CrewBase, agent, crew, task
|
||||||
|
|
||||||
|
# If you want to run a snippet of code before or after the crew starts,
|
||||||
|
# you can use the @before_kickoff and @after_kickoff decorators
|
||||||
|
# https://docs.crewai.com/concepts/crews#example-crew-class-with-decorators
|
||||||
|
|
||||||
|
|
||||||
|
@CrewBase
|
||||||
|
class ContentCrew:
|
||||||
|
"""Content Crew"""
|
||||||
|
|
||||||
|
agents: list[BaseAgent]
|
||||||
|
tasks: list[Task]
|
||||||
|
|
||||||
|
# Learn more about YAML configuration files here:
|
||||||
|
# Agents: https://docs.crewai.com/concepts/agents#yaml-configuration-recommended
|
||||||
|
# Tasks: https://docs.crewai.com/concepts/tasks#yaml-configuration-recommended
|
||||||
|
agents_config = "config/agents.yaml"
|
||||||
|
tasks_config = "config/tasks.yaml"
|
||||||
|
|
||||||
|
# If you would like to add tools to your crew, you can learn more about it here:
|
||||||
|
# https://docs.crewai.com/concepts/agents#agent-tools
|
||||||
|
@agent
|
||||||
|
def planner(self) -> Agent:
|
||||||
|
return Agent(
|
||||||
|
config=self.agents_config["planner"], # type: ignore[index]
|
||||||
|
)
|
||||||
|
|
||||||
|
@agent
|
||||||
|
def writer(self) -> Agent:
|
||||||
|
return Agent(
|
||||||
|
config=self.agents_config["writer"], # type: ignore[index]
|
||||||
|
)
|
||||||
|
|
||||||
|
@agent
|
||||||
|
def editor(self) -> Agent:
|
||||||
|
return Agent(
|
||||||
|
config=self.agents_config["editor"], # type: ignore[index]
|
||||||
|
)
|
||||||
|
|
||||||
|
# To learn more about structured task outputs,
|
||||||
|
# task dependencies, and task callbacks, check out the documentation:
|
||||||
|
# https://docs.crewai.com/concepts/tasks#overview-of-a-task
|
||||||
|
@task
|
||||||
|
def planning_task(self) -> Task:
|
||||||
|
return Task(
|
||||||
|
config=self.tasks_config["planning_task"], # type: ignore[index]
|
||||||
|
)
|
||||||
|
|
||||||
|
@task
|
||||||
|
def writing_task(self) -> Task:
|
||||||
|
return Task(
|
||||||
|
config=self.tasks_config["writing_task"], # type: ignore[index]
|
||||||
|
)
|
||||||
|
|
||||||
|
@task
|
||||||
|
def editing_task(self) -> Task:
|
||||||
|
return Task(
|
||||||
|
config=self.tasks_config["editing_task"], # type: ignore[index]
|
||||||
|
)
|
||||||
|
|
||||||
|
@crew
|
||||||
|
def crew(self) -> Crew:
|
||||||
|
"""Creates the Content Crew"""
|
||||||
|
# To learn how to add knowledge sources to your crew, check out the documentation:
|
||||||
|
# https://docs.crewai.com/concepts/knowledge#what-is-knowledge
|
||||||
|
|
||||||
|
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,
|
||||||
|
)
|
||||||
92
src/repo_software_builder_agent/main.py
Normal file
92
src/repo_software_builder_agent/main.py
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from crewai.flow import Flow, listen, start
|
||||||
|
|
||||||
|
from repo_software_builder_agent.crews.content_crew.content_crew import ContentCrew
|
||||||
|
|
||||||
|
|
||||||
|
class ContentState(BaseModel):
|
||||||
|
topic: str = ""
|
||||||
|
outline: str = ""
|
||||||
|
draft: str = ""
|
||||||
|
final_post: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
class ContentFlow(Flow[ContentState]):
|
||||||
|
|
||||||
|
@start()
|
||||||
|
def plan_content(self, crewai_trigger_payload: dict = None):
|
||||||
|
print("Planning content")
|
||||||
|
|
||||||
|
if crewai_trigger_payload:
|
||||||
|
self.state.topic = crewai_trigger_payload.get("topic", "AI Agents")
|
||||||
|
print(f"Using trigger payload: {crewai_trigger_payload}")
|
||||||
|
else:
|
||||||
|
self.state.topic = "AI Agents"
|
||||||
|
|
||||||
|
print(f"Topic: {self.state.topic}")
|
||||||
|
|
||||||
|
@listen(plan_content)
|
||||||
|
def generate_content(self):
|
||||||
|
print(f"Generating content on: {self.state.topic}")
|
||||||
|
result = (
|
||||||
|
ContentCrew()
|
||||||
|
.crew()
|
||||||
|
.kickoff(inputs={"topic": self.state.topic})
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Content generated")
|
||||||
|
self.state.final_post = result.raw
|
||||||
|
|
||||||
|
@listen(generate_content)
|
||||||
|
def save_content(self):
|
||||||
|
print("Saving content")
|
||||||
|
output_dir = Path("output")
|
||||||
|
output_dir.mkdir(exist_ok=True)
|
||||||
|
with open(output_dir / "post.md", "w") as f:
|
||||||
|
f.write(self.state.final_post)
|
||||||
|
print("Post saved to output/post.md")
|
||||||
|
|
||||||
|
|
||||||
|
def kickoff():
|
||||||
|
content_flow = ContentFlow()
|
||||||
|
content_flow.kickoff()
|
||||||
|
|
||||||
|
|
||||||
|
def plot():
|
||||||
|
content_flow = ContentFlow()
|
||||||
|
content_flow.plot()
|
||||||
|
|
||||||
|
|
||||||
|
def run_with_trigger():
|
||||||
|
"""
|
||||||
|
Run the flow with trigger payload.
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# Get trigger payload from command line argument
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
raise Exception("No trigger payload provided. Please provide JSON payload as argument.")
|
||||||
|
|
||||||
|
try:
|
||||||
|
trigger_payload = json.loads(sys.argv[1])
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
raise Exception("Invalid JSON payload provided as argument")
|
||||||
|
|
||||||
|
# Create flow and kickoff with trigger payload
|
||||||
|
# The @start() methods will automatically receive crewai_trigger_payload parameter
|
||||||
|
content_flow = ContentFlow()
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = content_flow.kickoff({"crewai_trigger_payload": trigger_payload})
|
||||||
|
return result
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(f"An error occurred while running the flow with trigger: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
kickoff()
|
||||||
0
src/repo_software_builder_agent/tools/__init__.py
Normal file
0
src/repo_software_builder_agent/tools/__init__.py
Normal file
21
src/repo_software_builder_agent/tools/custom_tool.py
Normal file
21
src/repo_software_builder_agent/tools/custom_tool.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from typing import Type
|
||||||
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
from crewai.tools import BaseTool
|
||||||
|
|
||||||
|
|
||||||
|
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, your agent will need this information to use it."
|
||||||
|
args_schema: Type[BaseModel] = MyCustomToolInput
|
||||||
|
|
||||||
|
def _run(self, argument: str) -> str:
|
||||||
|
# Implementation goes here
|
||||||
|
return "this is an example of a tool output, ignore it and move along."
|
||||||
Reference in New Issue
Block a user