A code research tool that enables users to understand codebases through agentic AI analysis. The project combines a Modal-based FastAPI backend with a Next.js frontend to provide intelligent code exploration capabilities.
Users submit a GitHub repository and research query through the frontend. The Modal API processes the request using an AI agent equipped with specialized code analysis tools. The agent explores the codebase using various tools (search, symbol analysis, etc.) and results are returned to the frontend for display.
The backend is built using Modal and FastAPI, providing a serverless API endpoint for code research.
There is a main API endpoint that handles code research requests. It uses the codegen
library for codebase analysis.
The agent investigates the codebase through various research tools:
ViewFileTool
: Read file contentsListDirectoryTool
: Explore directory structuresSearchTool
: Text-based code searchSemanticSearchTool
: AI-powered semantic code searchRevealSymbolTool
: Analyze code symbols and relationships
tools = [
ViewFileTool(codebase),
ListDirectoryTool(codebase),
SearchTool(codebase),
SemanticSearchTool(codebase),
RevealSymbolTool(codebase)
]
# Initialize agent with research tools
agent = create_agent_with_tools(
codebase=codebase,
tools=tools,
chat_history=[SystemMessage(content=RESEARCH_AGENT_PROMPT)],
verbose=True
)
The frontend provides an interface for users to submit a GitHub repository and research query. The components come from the shadcn/ui library. This triggers the Modal API to perform the code research and returns the results to the frontend.
-
Set up environment variables in an
.env
file:OPENAI_API_KEY=your_key_here
-
Deploy or serve the Modal API:
modal serve backend/api.py
modal serve
runs the API locally for development, creating a temporary endpoint that's active only while the command is running.modal deploy backend/api.py
modal deploy
creates a persistent Modal app and deploys the FastAPI app to it, generating a permanent API endpoint.After deployment, you'll need to update the API endpoint in the frontend configuration to point to your deployed Modal app URL.
-
Run the Next.js frontend:
cd frontend npm install npm run dev
More information about the codegen
library can be found here.
For details on the agent implementation, check out Deep Code Research with AI from the Codegen docs. This tutorial provides an in-depth guide on how the research agent is created.