CrewAI enables AI agents to collaborate on tasks, making it ideal for software development. Let’s explore a use case where a coding crew builds and verifies a Python game.
We create three agents, each with a specific role:
from crewai import Agent, Task, Crew, Process
from textwrap import dedent
# User input for game mechanics
game = input("Enter game idea and mechanics:\n")
# Define agents
senior_engineer = Agent(
role="Senior Software Engineer",
goal="Write a Python game",
backstory=dedent("Expert Python developer ensuring high-quality code."),
verbose=True
)
qa_engineer = Agent(
role="QA Engineer",
goal="Identify code issues",
backstory=dedent("Experienced tester detecting syntax and logic errors."),
verbose=True
)
chief_qa_engineer = Agent(
role="Chief QA Engineer",
goal="Ensure the code works",
backstory=dedent("Final reviewer ensuring game functionality."),
allow_delegation=True,
verbose=True
)
# Define tasks
code_task = Task(
description=f"Write a Python game based on: {game}",
expected_output="Full Python code of the game.",
agent=senior_engineer
)
qa_task = Task(
description="Review the game code for syntax, logic, and security errors.",
expected_output="List of detected issues.",
agent=qa_engineer
)
final_review_task = Task(
description="Ensure the game functions correctly.",
expected_output="Final, corrected Python code.",
agent=chief_qa_engineer
)
# Create Crew
crew = Crew(
agents=[senior_engineer, qa_engineer, chief_qa_engineer],
tasks=[code_task, qa_task, final_review_task],
verbose=2,
process=Process.sequential
)
# Execute
result = crew.kickoff()
print(result)In the above use case: