Skip to content

suyashw/ai-research-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Research Agent - Next.js Edition

A production-ready, full-stack research assistant built with Next.js 14, TypeScript, and Tailwind CSS. This application leverages OpenAI's GPT models and Firecrawl's deep research capabilities to perform comprehensive web research on any topic.

πŸš€ Features

  • Deep Web Research: Automatically searches the web, extracts content, and synthesizes findings using Firecrawl
  • AI-Powered Enhancement: Uses OpenAI GPT-4 to elaborate on research findings with additional context and insights
  • Modern UI: Beautiful, responsive interface built with Tailwind CSS and React
  • Type-Safe: Full TypeScript support for better developer experience
  • Production Ready: Optimized for performance with Next.js App Router and Server Components
  • Downloadable Reports: Export research findings as markdown files
  • Secure API Key Management: Client-side API key storage with localStorage
  • Dark Mode Support: Automatic dark mode based on system preferences

πŸ› οΈ Tech Stack

  • Framework: Next.js 14 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • AI: OpenAI GPT-4 Turbo
  • Web Scraping: Firecrawl Deep Research API
  • Deployment Ready: Vercel, Netlify, or any Node.js hosting

πŸ“‹ Prerequisites

πŸ—οΈ Installation

  1. Clone the repository:

    git clone <your-repo-url>
    cd ai-research-agent
  2. Install dependencies:

    npm install
    # or
    yarn install
    # or
    pnpm install
  3. Set up environment variables (optional): Create a .env.local file in the root directory:

    OPENAI_API_KEY=your_openai_api_key_here
    FIRECRAWL_API_KEY=your_firecrawl_api_key_here

    Note: API keys can also be configured directly in the UI. They are stored securely in your browser's localStorage.

  4. Run the development server:

    npm run dev
    # or
    yarn dev
    # or
    pnpm dev
  5. Open your browser: Navigate to http://localhost:3000

πŸ“– Usage

  1. Configure API Keys:

    • Click on "API Configuration" in the sidebar
    • Enter your OpenAI API key
    • Enter your Firecrawl API key
    • Keys are automatically saved to your browser's localStorage
  2. Enter Research Topic:

    • Type your research question or topic in the input field
    • Examples:
  • "Latest developments in quantum computing"
  • "Impact of climate change on marine ecosystems"
  • "Advancements in renewable energy storage"
  1. Start Research:

    • Click the "Start Research" button
    • The application will:
      1. Use Firecrawl to perform deep web research
      2. Generate an initial research report
      3. Enhance the report with GPT-4 for additional insights
      4. Display the enhanced report
  2. Download Report:

    • Click "Download Report" to save the research as a markdown file

πŸ›οΈ Project Structure

ai-research-agent/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   └── research/
β”‚   β”‚       └── route.ts          # API endpoint for research
β”‚   β”œβ”€β”€ globals.css               # Global styles
β”‚   β”œβ”€β”€ layout.tsx                # Root layout
β”‚   └── page.tsx                  # Main page component
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ ApiKeyConfig.tsx          # API key configuration component
β”‚   β”œβ”€β”€ ResearchForm.tsx          # Research input form
β”‚   └── ResearchResults.tsx       # Results display component
β”œβ”€β”€ public/                       # Static assets
β”œβ”€β”€ .gitignore                    # Git ignore rules
β”œβ”€β”€ next.config.js                # Next.js configuration
β”œβ”€β”€ package.json                  # Dependencies
β”œβ”€β”€ postcss.config.js             # PostCSS configuration
β”œβ”€β”€ tailwind.config.ts            # Tailwind CSS configuration
β”œβ”€β”€ tsconfig.json                 # TypeScript configuration
└── README.md                     # This file

πŸ”§ Configuration

Environment Variables

You can optionally set environment variables in .env.local:

  • OPENAI_API_KEY: Your OpenAI API key
  • FIRECRAWL_API_KEY: Your Firecrawl API key
  • NEXT_PUBLIC_APP_URL: Your application URL (for production)

Research Parameters

The research parameters are configured in app/api/research/route.ts:

  • maxDepth: Maximum depth for web crawling (default: 3)
  • timeLimit: Maximum time for research in seconds (default: 180)
  • maxUrls: Maximum number of URLs to crawl (default: 10)

You can modify these values in the deepResearch function call.

🚒 Deployment

Vercel (Recommended)

  1. Push your code to GitHub
  2. Import your repository in Vercel
  3. Add environment variables in Vercel dashboard
  4. Deploy!

Other Platforms

The application can be deployed to any platform that supports Next.js:

  • Netlify: Use the Next.js build preset
  • Railway: Connect your GitHub repo
  • AWS Amplify: Configure for Next.js
  • Docker: Use the included Dockerfile (if added)

Build command: npm run build Start command: npm start

πŸ”’ Security Considerations

  • API keys are stored in the browser's localStorage (client-side only)
  • API keys are never exposed in the client-side code
  • All API calls are made server-side through Next.js API routes
  • Consider implementing user authentication for production use
  • Use environment variables for server-side API keys in production

πŸ§ͺ Development

Type Checking

npm run type-check

Linting

npm run lint

Building for Production

npm run build

Running Production Build

npm start

πŸ“ API Reference

POST /api/research

Performs deep research on a given topic.

Request Body:

{
  "topic": "Your research topic",
  "openaiApiKey": "sk-...",
  "firecrawlApiKey": "fc-..."
}

Response:

{
  "report": "Enhanced research report in markdown format"
}

Error Response:

{
  "error": "Error message"
}

πŸ› Troubleshooting

Research fails with API errors

  • Verify your API keys are correct
  • Check your API key quotas and limits
  • Ensure you have sufficient credits in your OpenAI and Firecrawl accounts

Build errors

  • Ensure Node.js version is 18 or higher
  • Delete node_modules and .next folders, then reinstall dependencies
  • Check TypeScript errors with npm run type-check

API route not found

  • Ensure you're using Next.js 14+ with App Router
  • Check that the file structure matches the expected layout

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is open source and available under the MIT License.

πŸ™ Acknowledgments

πŸ“š Additional Resources


Built with ❀️ using Next.js, TypeScript, and modern web technologies.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors