Skip to content
CrewAI

Agent do code review z CrewAI

Zbuduj agenta AI do code review, który czyta pliki, szuka wzorców, analizuje jakość kodu i sugeruje ulepszenia — z CrewAI.

code reviewstatic analysisqualitydeveloper tools

Działający kod

CrewAI
from crewai import Agent, Crew, Task
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
@tool
def read_file(path: str) -> str:
"""Read a file from the project."""
return Path(path).read_text()
@tool
def 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])
@tool
def 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)

Krok po kroku

1

Zainstaluj zależności

Zainstaluj CrewAI i wymagane narzędzia do tego przypadku użycia.

2

Zdefiniuj narzędzia

Stwórz specyficzne dla domeny funkcje narzędzi, których agent będzie używał do interakcji z zewnętrznymi serwisami.

3

Stwórz agenta i uruchom

Zainicjalizuj agenta CrewAI z narzędziami, ustaw prompt systemowy i wykonaj zapytanie.

Gotowy do budowania z CrewAI?

Wygeneruj gotowy do produkcji projekt z CrewAI — FastAPI + Next.js, autoryzacja, streaming i więcej.

Rozpocznij

Gotowy, żeby zbudować swojego pierwszego agenta AI?

Open-source'owe narzędzia, sprawdzone wzorce, zero boilerplate'u. Skonfiguruj swój stos i wyślij w minuty — nie miesiące.