CrewAI
Code Review Agent with CrewAI
Build an AI code review agent that reads files, searches for patterns, analyzes code quality, and suggests improvements — with CrewAI.
code reviewstatic analysisqualitydeveloper tools
Working Code
from crewai import Agent, Crew, Taskfrom langchain_openai import ChatOpenAIfrom langchain_core.tools import tool
@tooldef read_file(path: str) -> str: """Read a file from the project.""" return Path(path).read_text()
@tooldef find_files(pattern: str) -> str: """Find files matching a glob pattern.""" files = list(Path(".").rglob(pattern)) return "\n".join(str(f) for f in files[:20])
@tooldef search_code(pattern: str, path: str = ".") -> str: """Search for a regex pattern in source files.""" import subprocess result = subprocess.run( ["grep", "-rn", pattern, path, "--include=*.py"], capture_output=True, text=True, ) return result.stdout[:3000] or "No matches found."
agent = Agent( role="Specialist", goal="You are a code reviewer. Find relevant files, read them, search for patterns, and provide a structured review covering security, performance, and best practices.", tools=[read_file, find_files, search_code], llm=ChatOpenAI(model="gpt-4o"),)
task = Task( description="Review the Python files in src/ for common security issues", expected_output="Detailed response", agent=agent,)
crew = Crew(agents=[agent], tasks=[task])result = crew.kickoff()print(result.raw)Step by Step
1
Install dependencies
Install CrewAI and the required tools for this use case.
2
Define your tools
Create the domain-specific tool functions your agent will use to interact with external services.
3
Create the agent and run
Initialize the CrewAI agent with your tools, set the system prompt, and execute a query.
Build with other frameworks
Ready to build with CrewAI?
Generate a production-ready project with CrewAI pre-configured — FastAPI + Next.js, auth, streaming, and more.
Get StartedReady to build your first production AI agent?
Open-source tools, battle-tested patterns, zero boilerplate. Configure your stack and ship in minutes — not months.