Skip to content
LangChain

Agent do code review z LangChain

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

code reviewstatic analysisqualitydeveloper tools

Działający kod

LangChain
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."
model = ChatOpenAI(model="gpt-4o")
model_with_tools = model.bind_tools([read_file, find_files, search_code])
response = model_with_tools.invoke([
("system", "You are a code reviewer. Find relevant files, read them, search for patterns, and provide a structured review covering security, performance, and best practices."),
("user", "Review the Python files in src/ for common security issues"),
])

Krok po kroku

1

Zainstaluj zależności

Zainstaluj LangChain 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 LangChain z narzędziami, ustaw prompt systemowy i wykonaj zapytanie.

Gotowy do budowania z LangChain?

Wygeneruj gotowy do produkcji projekt z LangChain — 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.