Skip to content

AI Research Agent πŸ” secure Academic Research Assistant with AI Integration. A full-stack web application leveraging OpenAI and LangChain to provide authenticated users with AI-powered research capabilities. Features secure JWT authentication, real-time web/Wikipedia integration, Markdown report generation, and Docker deployment.

License

Notifications You must be signed in to change notification settings

adexoxo13/ResearchAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ResearchAgent

CI

Overview

ResearchAgent is a powerful AI-driven research assistant that integrates various tools for intelligent web search, Wikipedia querying, and persistent storage. This agent is designed to help users quickly gather, validate, and store research data in a structured format. The system leverages advanced models and external APIs to perform real-time searches, access verified information from Wikipedia, and save findings into a local file system.

This project is built with Flask and integrates several LangChain components for dynamic research automation. Additionally, it features user authentication and a secure environment to manage research data.

Table of Contents

Features

  • Web and Wikipedia Search: Real-time search and retrieval of information using DuckDuckGo and Wikipedia.
  • Persistent Storage: Saves research findings in a markdown format with timestamps for chronological tracking.
  • Token-based Authentication: Secures access with JWT tokens, preventing unauthorized access.
  • Modular Tooling: Leverages LangChain tools for seamless interaction with APIs, search engines, and file storage.

Requirements

  • Python Version: 3.10 or higher
  • External Dependencies: Managed through requirements.txt
  • Flask for the web framework
  • LangChain for handling AI-driven research
  • DuckDuckGo and Wikipedia API integrations for knowledge retrieval
  • JWT (JSON Web Token) for secure authentication

File Structure

Below is a breakdown of the project structure and the purpose of each file:

ResearchAgent/
β”‚
β”œβ”€β”€ .env.secure              # Secure environment variables for production (do not share)
β”œβ”€β”€ .env                     # Environment configuration (e.g., API keys, secret keys)
β”œβ”€β”€ .dockerignore            # Docker ignore file (helps in excluding unnecessary files)
β”œβ”€β”€ Dockerfile               # Docker container configuration for the app
β”œβ”€β”€ requirements.txt         # Project dependencies
β”œβ”€β”€ .static/
β”‚   β”œβ”€β”€ loading.svg          # SVG image for loading screen
β”‚   └── style.css            # CSS file for styling the frontend UI
β”œβ”€β”€ .templates/
β”‚   β”œβ”€β”€ login.html           # HTML template for user login page
β”‚   └── app.html             # Main application interface
β”œβ”€β”€ api/
β”‚   └── research_api.py      # API endpoints for handling research logic
β”œβ”€β”€ auth/
β”‚   └── auth.py              # Handles authentication (basic and JWT)
β”œβ”€β”€ tools.py                 # Implements core tools (web search, Wikipedia, saving data)
β”œβ”€β”€ utils/
β”‚   └── agent_setup.py       # Initializes LangChain agent and configurations
β”œβ”€β”€ security_key.py          # API key and secret key management
β”œβ”€β”€ main.py                  # Main entry point to run the Flask application
└── static/
    β”œβ”€β”€ loading.svg          # Loading spinner for the frontend
    └── style.css            # Custom styles for the user interface

Key Files

  • main.py: Entry point for running the Flask app. It starts the server and handles requests.
  • auth.py: Contains logic for user authentication and JWT token management.
  • tools.py: Implements the research tools, such as search functionality, Wikipedia queries, and file-saving.
  • research_api.py: Defines the API endpoints for research functionalities like initiating research tasks.
  • agent_setup.py: Configures and sets up the LangChain agent that drives the research process.

Setup Instructions

1. Clone the Repository

git clone https://github.com/yourusername/ResearchAgent.git
cd ResearchAgent

2. Generate Security Key

Run the security_key.py script to generate a secret key for your application. This key will be used for JWT token creation and should be securely stored.

python security_key.py

Once the key is generated, store it safely in .env.secure for future use.

3. Get Your OpenAI API Key

To access the research assistant's capabilities, you need an OpenAI API Key. You can obtain it from the OpenAI platform.

After you have the key, store it in your .env file as follows:

OPENAI_API_KEY=your-openai-api-key-here

4. Set Up Authentication

In the .env file, you can set your own authentication details. For example:

BASIC_AUTH_USERNAME=admin
BASIC_AUTH_PASSWORD=your-password-here
SECRET_KEY=your-generated-secret-key

Remember the BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD values, as they will be used to log in later.

Usage

Building and Running with Docker

To start the application, use Docker to build the container and run it:

docker build -t research-bot .

Then, run the container with the required environment variables:

docker run -p 5000:5000 --rm \
  -e OPENAI_API_KEY="your-openai-api-key" \
  -e BASIC_AUTH_USERNAME="admin" \
  -e BASIC_AUTH_PASSWORD="securepassword123" \
  -e SECRET_KEY="secret-key-you-generated-by-security_key.py" \
  research-bot

Accessing the Research Portal

  1. Navigate to http://localhost:5000/login to log in
Login Page
  1. Upon successful authentication, you'll be redirected to the research dashboard (/app)
Login Page night mode Login Page day mode
  1. From the dashboard, you can:
    • Perform web searches
    • Query Wikipedia
    • Save research findings
Query Page day mode Query Page night mode

Authentication System

Token-Based Authentication

  • Uses JWT tokens to secure access
  • Flow:
    1. Visit /login and enter credentials
    2. Successful authentication generates a JWT token
    3. Token is attached to URL for subsequent requests

Manual Authentication Flow

  • The system validates credentials against environment variables (BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD). Once validated, a token is generated using the secret key defined in .env.

Security Considerations

  • Sensitive Information: Ensure that .env.secure and .env files are never pushed to public repositories.

  • Password Hashing: The current implementation uses plaintext passwords for authentication. Do not use in production; integrate a password hashing mechanism (e.g., bcrypt) for better security.

  • Token Expiry: JWT tokens are configured to expire after 24 hours to reduce security risks from session hijacking.

  • HTTPS: Use HTTPS (via reverse proxy like Nginx) in production to protect sensitive data such as JWT tokens.

  • Rate Limiting: For API security, implement rate limiting to avoid excessive requests from users.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

We welcome contributions to ResearchAgent. Please fork the repository and submit a pull request for any changes. For major changes, please open an issue first to discuss what you would like to change.

Conclusion

The ResearchAgent is a robust tool for automating research tasks, offering real-time search, Wikipedia querying, and persistent storage. By setting up the environment correctly and following the steps outlined in this README, you'll be ready to harness the full power of this agent for your research automation needs.

πŸ“¬ Contact

Feel free to reach out or connect with me:

About

AI Research Agent πŸ” secure Academic Research Assistant with AI Integration. A full-stack web application leveraging OpenAI and LangChain to provide authenticated users with AI-powered research capabilities. Features secure JWT authentication, real-time web/Wikipedia integration, Markdown report generation, and Docker deployment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published