sndev
Project CategoriesDeveloper LearnDeveloper Insights
LoginGet Started
sndevv1.0.0
AboutProject FeedInsightsYouTubePrivacy PolicyTerms of Service

© 2026 sndev • v1.0.0

Home
Categories
Dev Learn
Insights
Sign In
Agentic AI
Nov 29, 2026
s
sndev

Building and Deploying a Full-Stack AI Deep Research Agent | Part 13 – Final Chapter

“Complete the Deep Research Agent by building REST APIs, adding rate limiting, integrating WebSockets and Next.js, and deploying the application with Render and Vercel.”

Project SeriesPart 13 of 13

Deep Research Agent

Series Progress100%
Series Episodes (13)
Build an Autonomous Deep Research Agent | End-to-End Agentic AI Project | Part 1
Available
Setup & Installation for Autonomous Deep Research Agent | End-to-End Agentic AI Project | Part 2
Available
Building the Agentic AI Brain with LangGraph | Autonomous Deep Research Agent | Part 3
Available
Building AI Agent with LangGraph | Planner Agent Implementation | Deep Research Agent | Part 4
Available
Building AI Agent Tools | Rate Limiting & Source Credibility | Deep Research Agent | Part 5
Available
Building a Web Search Tool for AI Agents with Tavily API | Deep Research Agent Part 6
Available
Building arXiv Search, Cross-Referencing, and Citation Tools | Deep Research Agent Part 7
Available
Building the Researcher Agent with Web Search, arXiv & Source Ranking | Deep Research Agent Part 8
Available
Building the Critic Agent: Detecting Conflicting Research | Deep Research System Part 9
Available
Building the Writer Agent – Generating Structured AI Research Reports | Part 10
Available
Building a Multi-Agent Workflow with LangGraph | Deep Research Agent – Part 11
Available
Building a Real-Time WebSocket Streaming Engine with FastAPI | Deep Research Agent – Part 12
Available
P13
Building and Deploying a Full-Stack AI Deep Research Agent | Part 13 – Final Chapter
Current Part
Part 12

In the previous chapters, we built the core multi-agent research workflow using LangGraph, implemented real-time progress updates with FastAPI WebSockets, and connected our research agents.

In this final chapter, we bring everything together and turn the project into a working full-stack AI application.

We will build the remaining REST API endpoints, execute research tasks asynchronously, protect expensive AI operations with rate limiting, connect the Next.js frontend, test the complete workflow, and deploy the application.

1. Building the Reports API with FastAPI

We start by creating a dedicated reports.py file inside the router directory.

Instead of putting every endpoint inside main.py, we use FastAPI's APIRouter to keep the backend modular and organized.

We implement four main operations:

  • POST /reports: Creates a new research task and starts the agent workflow.

  • GET /reports/{report_id}: Retrieves a specific research report.

  • GET /reports: Retrieves previously generated reports with pagination.

  • DELETE /reports/{report_id}: Deletes a stored research report.

We also implement helper functions to convert MongoDB ObjectIds into regular strings for JSON responses and validate report IDs before querying the database.

2. Running Research Tasks in the Background

A deep research workflow involves multiple agents, external APIs, web searches, and LLM calls. Executing the entire workflow inside a normal HTTP request could cause long response times or gateway timeouts.

To solve this, we use FastAPI's BackgroundTasks.

When a user submits a research query, the API immediately creates a report record in MongoDB and returns a report ID with an HTTP 202 Accepted response.

The background worker then executes the LangGraph workflow independently.

Once the research is complete, it extracts the summary, report sections, citations, sources, and word count, and saves the final result in MongoDB.

If an exception occurs, the worker records the failure status and notifies the frontend through WebSockets.

3. Protecting AI APIs with SlowAPI Rate Limiting

Every research request can trigger multiple LLM calls, Tavily searches, and ArXiv queries. Uncontrolled requests can quickly increase infrastructure and API costs.

We integrate SlowAPI to introduce IP-based rate limiting.

This helps protect the application from excessive requests caused by bots, misuse, or accidental frontend request loops.

We configure request limits on the API endpoints and handle rate-limit exceptions centrally in FastAPI.

Think of rate limiting as a financial safeguard for an AI application: it helps control how frequently users can trigger expensive agent workflows.

4. Connecting REST APIs and WebSockets

After implementing the endpoints, we register the reports router and WebSocket router inside main.py under the /api/v1 prefix.

We also configure:

  • SlowAPI limiter initialization and exception handling.

  • CORS middleware to allow requests from the Next.js frontend.

  • MongoDB connection and application startup configuration.

The REST API handles report creation and retrieval, while WebSockets deliver live execution updates.

This separation allows the frontend to receive an immediate response while the research workflow continues in the background.

5. Testing the Complete Workflow with Postman

Before integrating the frontend, we test the backend independently using Postman.

The workflow is straightforward:

  1. Send a POST request with the research query and maximum number of sources.

  2. Receive the generated report ID.

  3. Connect to the WebSocket endpoint using that report ID.

  4. Observe live execution updates.

  5. Retrieve the completed report using the GET endpoint.

During execution, we can observe updates such as archive search, web search, researching, fact-checking, synthesizing, and completion.

The final API response contains the research query, status, executive summary, report sections, and citations with their source details.

6. Integrating the Next.js Frontend

With the backend working, we connect it to the Next.js frontend.

The interface allows users to submit research queries, select the maximum number of sources, and start the research process.

WebSocket messages power the live execution logs, while the REST API retrieves the completed report.

The final interface displays the generated report, its sections, sources, citations, and other research information.

7. Deploying the Application

The final step is deploying both parts of the application.

We use:

  • Backend: Render

  • Frontend: Vercel

  • Database: MongoDB Atlas

We connect the backend and frontend GitHub repositories to their respective deployment platforms and configure the required environment variables.

After deploying the backend, we update the frontend's public API URL. We then update the backend's CORS configuration to allow requests from the deployed Vercel domain.

Finally, we verify the deployed API, retrieve and delete reports, and run a complete research query through the live application.

Complete Application Architecture

The following diagram illustrates how the frontend, API layer, background research workflow, database, and WebSocket connection work together.

Generating Architecture Diagram…

Conclusion

With this chapter, we have completed the initial version of our Full-Stack AI Deep Research Agent.

We started with a multi-agent architecture and progressively built the research workflow, connected external search tools, implemented real-time updates, developed REST APIs, integrated a frontend, and deployed the application.

More importantly, this project demonstrates how different AI engineering components work together in a practical application—not just how to build an individual AI agent.

This is the foundation. In future enhancements, we can explore better retrieval mechanisms, persistent memory, evaluation, observability, and more advanced research capabilities.

The initial Deep Research Agent project is now complete!

Thanks for following the entire series. Keep building and keep experimenting.

— SN Dev

AgenticAI
DeepResearchAgent
FastAPI
GenerativeAI
Python
LangGraph
MongoDB
Series Navigation

You reached the end of this series!

You have completed all available parts of "Deep Research Agent". Stay tuned for more updates!

Part 12
Series Completed

Community Discussion
0

Ask questions, discuss architecture, and share insights with other developers.

Sort:

Sign in to join the discussion and share your thoughts with other developers.

Sign In to Comment
Loading discussions…