Skip to content

Research analyzer with bedrock #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ By [@joaomdmoura](https://x.com/joaomdmoura).
- [Create Instagram Post](https://github.com/joaomdmoura/crewAI-examples/tree/main/instagram_post)
- [Markdown Validator](https://github.com/joaomdmoura/crewAI-examples/tree/main/markdown_validator)
- [Using Azure OpenAI API](https://github.com/joaomdmoura/crewAI-examples/tree/main/azure_model)
- [Research Paper Analyzer with Bedrock](https://github.com/crewAIInc/crewAI-examples/tree/main/research_analyzer_with_bedrock)

Starting your own example
- [Starter Template](https://github.com/joaomdmoura/crewAI-examples/tree/main//starter_template)
### Advanced Examples
- [Stock Analysis](https://github.com/joaomdmoura/crewAI-examples/tree/main/stock_analysis)
- [Landing Page Generator](https://github.com/joaomdmoura/crewAI-examples/tree/main/landing_page_generator)
- [CrewAI + LangGraph](https://github.com/joaomdmoura/crewAI-examples/tree/main/CrewAI-LangGraph)
- [CrewAI + LangGraph](https://github.com/joaomdmoura/crewAI-examples/tree/main/CrewAI-LangGraph)
71 changes: 71 additions & 0 deletions research_analyzer_with_bedrock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Research Paper Analyzer

A sophisticated research paper analysis system powered by [CrewAI](https://crewai.com) and [Amazon Bedrock](https://aws.amazon.com/bedrock/) that analyzes academic papers and generates comprehensive reports with executive summaries, key insights, and actionable recommendations.

## Overview

The Research Paper Analyzer uses a team of specialized AI agents to analyze academic papers through several phases:

1. **Technical Analysis**: Detailed examination of methodology, statistical approaches, and results
2. **Literature Review**: Contextualization within the broader academic landscape
3. **Summary Creation**: Synthesis of key findings and contributions
4. **Final Report Generation**: Comprehensive report with insights and recommendations

### High-Level Architecture

The system operates through four specialized agents:

- **Research Director**: Coordinates analysis and ensures quality
- **Technical Expert**: Analyzes methodologies and statistical significance
- **Literature Specialist**: Reviews research context and connections
- **Summary Writer**: Creates clear, accessible summaries

## Installation

### Prerequisites

- Python 3.10+
- AWS Account with Amazon Bedrock access
- An AWS IAM role with permissions to access Amazon Bedrock, configured following [AWS IAM security best practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)
- [Access to Claude-3.5 Sonnet model](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access-modify.html) in Amazon Bedrock

### Setup

1. Clone the repository:
```bash
git clone https://github.com/crewAIInc/crewAI-examples.git
cd research_analyzer_with_bedrock
```
2. Install dependencies using Poetry:
```bash
poetry install --no-root
```
3. Create a .env file in the project root:
```bash
AWS_REGION_NAME=us-west-2
BEDROCK_MODEL_ID=bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0
MAX_OUTPUT_TOKENS=4096
TEMPERATURE=0.7
```
### Usage

Analyze a research paper using either method:
Direct Python execution:

poetry run python main.py path/to/your/paper.pdf

Using CrewAI CLI:

poetry run crew run --pdf_path path/to/your/paper.pdf

Features

Comprehensive Analysis: Multi-faceted examination of research papers
AWS Bedrock Integration: Leverages powerful Claude-3 model
Modular Architecture: Separate specialized agents for different aspects
PDF Processing: Automatic extraction and processing of PDF papers
Structured Output: Clear, organized analysis reports

## License

This project is licensed under the MIT License - see the LICENSE file for details.
81 changes: 81 additions & 0 deletions research_analyzer_with_bedrock/agents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from crewai import Agent
from utils.Bedrock import load_bedrock_llm

# Initialize Bedrock LLM instances for all agents
bedrock_llm = load_bedrock_llm()


class ResearchAgents:
"""
Factory class for creating specialized research analysis agents.
Each agent is configured with specific roles, goals, and expertise
for different aspects of research paper analysis.
"""

@staticmethod
def get_research_director() -> Agent:
"""
Creates a Research Director agent responsible for overseeing the entire
analysis process and ensuring quality of outputs.

Returns:
Agent: Configured Research Director agent instance
"""
return Agent(
role='Research Director',
goal='Coordinate research analysis and ensure high-quality comprehensive output',
backstory='Former Research Director at top universities with 15+ years of experience in managing research teams and projects',
verbose=True,
llm=bedrock_llm
)

@staticmethod
def get_technical_expert() -> Agent:
"""
Creates a Technical Expert agent specialized in analyzing methodologies,
statistical approaches, and technical aspects of research papers.

Returns:
Agent: Configured Technical Expert agent instance
"""
return Agent(
role='Technical Analysis Expert',
goal='Analyze technical methodologies, results, and statistical significance in research papers',
backstory='PhD in Data Science with 10+ years experience in research analysis and statistical methods',
verbose=True,
llm=bedrock_llm
)

@staticmethod
def get_literature_specialist() -> Agent:
"""
Creates a Literature Specialist agent focused on contextualizing research
within the broader academic landscape and identifying connections.

Returns:
Agent: Configured Literature Specialist agent instance
"""
return Agent(
role='Literature Review Specialist',
goal='Analyze research context and identify connections with existing literature',
backstory='Academic librarian with expertise in systematic reviews and meta-analyses',
verbose=True,
llm=bedrock_llm
)

@staticmethod
def get_summary_writer() -> Agent:
"""
Creates a Summary Writer agent specialized in distilling complex
research into clear, accessible summaries.

Returns:
Agent: Configured Summary Writer agent instance
"""
return Agent(
role='Summary Writer',
goal='Create clear, concise summaries of complex research papers',
backstory='Science communication expert with experience in top scientific journals',
verbose=True,
llm=bedrock_llm
)
128 changes: 128 additions & 0 deletions research_analyzer_with_bedrock/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
from crewai import Crew
from agents import ResearchAgents
from tasks import ResearchTasks
from utils.PdfReader import PdfReader
import sys


class ResearchAnalyzerCrew:
"""
Orchestrates the research paper analysis process using a crew of AI agents.
Manages the workflow of technical analysis, literature review, summarization,
and final report generation.
"""

def __init__(self, paper_content: str):
"""
Initialize the analyzer with research paper content.

Args:
paper_content (str): The extracted text content of the research paper
"""
self.paper_content = paper_content

def run(self) -> str:
"""
Executes the complete research paper analysis workflow.

The workflow consists of four main steps:
1. Technical analysis of the paper's methodology and results
2. Literature review and context analysis
3. Creation of a comprehensive summary
4. Generation of a final report with insights and recommendations

Returns:
str: The final analysis report
"""
# Initialize factory classes for agents and tasks
agents = ResearchAgents()
tasks = ResearchTasks()

# Initialize specialized agents for different aspects of analysis
research_director = agents.get_research_director()
technical_expert = agents.get_technical_expert()
literature_specialist = agents.get_literature_specialist()
summary_writer = agents.get_summary_writer()

# Define sequential analysis tasks with dependencies
technical_analysis_task = tasks.analyze_technical_components(
agent=technical_expert,
paper_content=self.paper_content
)

literature_review_task = tasks.review_literature_context(
agent=literature_specialist,
paper_content=self.paper_content,
technical_analysis="{{ technical_analysis_task.output }}" # Depends on technical analysis
)

summary_task = tasks.create_research_summary(
agent=summary_writer,
technical_analysis="{{ technical_analysis_task.output }}",
literature_review="{{ literature_review_task.output }}" # Depends on both previous tasks
)

final_report_task = tasks.create_final_report(
agent=research_director,
summary="{{ summary_task.output }}",
technical_analysis="{{ technical_analysis_task.output }}",
literature_review="{{ literature_review_task.output }}" # Integrates all previous outputs
)

# Configure the CrewAI workflow with agents and their tasks
crew = Crew(
agents=[
research_director,
technical_expert,
literature_specialist,
summary_writer
],
tasks=[
technical_analysis_task,
literature_review_task,
summary_task,
final_report_task
],
verbose=True # Enable detailed logging of the analysis process
)

# Execute the analysis workflow
result = crew.kickoff()
return result


if __name__ == "__main__":
print("## Welcome to Research Analyzer AI")
print("----------------------------------")

# Validate command line arguments
if len(sys.argv) != 2:
print("Usage: python main.py <path_to_pdf>")
print("Example: python main.py research_paper.pdf")
sys.exit(1)

pdf_path = sys.argv[1]
print(f"\nReading PDF file: {pdf_path}")

try:
# Extract and process PDF content
pdf_reader = PdfReader(pdf_path)
paper_content = pdf_reader.read()

print("\nPDF content extracted successfully!")
print(f"Content length: {len(paper_content)} characters")

# Initialize and execute the analysis workflow
print("\nStarting analysis...")
research_crew = ResearchAnalyzerCrew(paper_content)
result = research_crew.run()

# Display analysis results
print("\n\n########################")
print("## Research Analysis Results:")
print("########################\n")
print(result)

except Exception as e:
print(f"Error: {str(e)}")
sys.exit(1)
Loading