Skip to content

armgit / camel

Public Imported from GitHub
0

๐Ÿซ CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

usecase: Research assistant (#2484)

Bipul707015491604c0f07
diff --git a/examples/usecases/multi_agent_research_assistant/.env.template b/examples/usecases/multi_agent_research_assistant/.env.template
new file mode 100644
index 000000000..b71a0d619
--- /dev/null
+++ b/examples/usecases/multi_agent_research_assistant/.env.template
@@ -0,0 +1,8 @@
+GOOGLE_API_KEY=''
+SEARCH_ENGINE_ID=''
+OPENAI_API_KEY=''
+DEEPSEEK_API_KEY=''
+CHUNKR_API_KEY=''
+FIRECRAWL_API_KEY=''
+ASKNEWS_CLIENT_ID=''
+ASKNEWS_CLIENT_SECRET=''
diff --git a/examples/usecases/multi_agent_research_assistant/README.md b/examples/usecases/multi_agent_research_assistant/README.md
new file mode 100644
index 000000000..71209cd08
--- /dev/null
+++ b/examples/usecases/multi_agent_research_assistant/README.md
@@ -0,0 +1,85 @@
+# ๐Ÿง  CAMEL Multi-Agent Research Assistant
+
+A powerful, AI-driven research assistant built using the [CAMEL-AI](https://www.camel-ai.org/) framework. This application leverages multiple specialized toolkits and a role-playing agent architecture to autonomously generate comprehensive research reports on any given topic.
+
+## ๐Ÿš€ Features
+
+- **Multi-Agent Collaboration**: Utilizes CAMEL's role-playing framework to simulate interactions between a "Project Manager" and a "Researcher Agent" for dynamic task execution.
+- **Diverse Toolkit Integration**: Incorporates various CAMEL toolkits including:
+ - `GoogleScholarToolkit` and `SemanticScholarToolkit` for academic paper retrieval.
+ - `ArxivToolkit` for accessing preprints.
+ - `AskNewsToolkit` for fetching relevant news articles.
+ - `ThinkingToolkit` for planning and synthesis.
+ - `FileWriteToolkit` for saving reports locally.
+ - `LinkedInToolkit` for potential dissemination.
+ - `DalleToolkit` for generating illustrative images.
+- **Streamlit Interface**: Provides an intuitive web interface for users to input topics and receive generated reports.
+
+## ๐Ÿ› ๏ธ Installation
+
+1. **Clone the Repository**:
+
+ ```bash
+ git clone https://github.com/camel-ai/camel.git
+ cd camel/examples/usecases/multi_agent_research_assistant
+ ```
+
+2. **Create and Activate a Virtual Environment**:
+
+ ```bash
+ python -m venv venv
+ source venv/bin/activate # On Windows: venv\Scripts\activate
+ ```
+
+3. **Install Dependencies**:
+
+ ```bash
+ pip install -r requirements.txt
+ ```
+
+4. ## ๐Ÿ› ๏ธ Setup Environment Variables
+
+ Copy the provided `.env.template` to `.env`:
+
+ Open the `.env` file in your preferred editor and add your required API keys. At a minimum, you need to provide your OpenAI API key:
+
+ ```env
+ OPENAI_API_KEY=your_openai_api_key
+ ```
+
+ Replace `your_openai_api_key` with your actual key from OpenAI.
+
+ Additional environment variables may be required depending on the toolkits you enable (e.g., for LinkedIn, DALLยทE, news APIs, etc.).
+
+
+## โ–ถ๏ธ Running the Application
+
+Start the Streamlit application:
+
+```bash
+streamlit run app.py
+```
+
+This will open the application in your default web browser. Enter a research topic and click "Generate Report" to initiate the multi-agent research process.
+
+## ๐Ÿ“‚ Project Structure
+
+```
+camel-research-assistant/
+โ”œโ”€โ”€ app.py # Main Streamlit application
+โ”œโ”€โ”€ requirements.txt # Python dependencies
+โ”œโ”€โ”€ .env # Environment variables (not included in version control)
+โ””โ”€โ”€ README.md # Project documentation
+```
+
+## ๐Ÿงช Example Usage
+
+1. Launch the application.
+2. Input a topic, e.g., "Latest breakthroughs in quantum computing".
+3. Click "Generate Report".
+4. The application will:
+ - Identify top researchers in the field.
+ - Retrieve relevant academic papers and news articles.
+ - Generate a comprehensive report.
+ - Save the report locally.
+ - Optionally, generate illustrative images and prepare content for LinkedIn dissemination.
\ No newline at end of file
diff --git a/examples/usecases/multi_agent_research_assistant/app.py b/examples/usecases/multi_agent_research_assistant/app.py
new file mode 100644
index 000000000..518f8baa7
--- /dev/null
+++ b/examples/usecases/multi_agent_research_assistant/app.py
@@ -0,0 +1,172 @@
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+
+import streamlit as st
+from dotenv import load_dotenv
+from camel.societies import RolePlaying
+from camel.models import ModelFactory
+from camel.types import ModelPlatformType, ModelType
+from camel.toolkits import (
+ GoogleScholarToolkit, SemanticScholarToolkit, ArxivToolkit,
+ AskNewsToolkit, ThinkingToolkit,
+ FileWriteToolkit, LinkedInToolkit
+)
+from camel.logger import set_log_level
+import logging
+
+logging.basicConfig(level=logging.DEBUG)
+load_dotenv()
+set_log_level(level="DEBUG")
+
+# Model Setup
+model = ModelFactory.create(
+ model_platform=ModelPlatformType.OPENAI,
+ model_type=ModelType.GPT_4O,
+ model_config_dict={"temperature": 0.0}
+)
+
+class DynamicResearchAgent:
+ """
+ Research agent that can dynamically add GoogleScholar tools based on discovered authors
+ """
+ def __init__(self, base_tools):
+ self.base_tools = base_tools
+ self.google_scholar_tools = {}
+
+ def add_google_scholar_for_author(self, author_identifier: str, author_name: str = None):
+ """Add GoogleScholar tools for a specific author"""
+ if author_identifier not in self.google_scholar_tools:
+ try:
+ toolkit = GoogleScholarToolkit(author_identifier=author_identifier)
+ self.google_scholar_tools[author_identifier] = toolkit.get_tools()
+ return True
+ except Exception as e:
+ st.warning(f"Could not create GoogleScholar toolkit for {author_name or author_identifier}: {e}")
+ return False
+ return True
+
+ def get_all_tools(self):
+ """Get all available tools including dynamically added ones"""
+ all_tools = list(self.base_tools)
+ for tools in self.google_scholar_tools.values():
+ all_tools.extend(tools)
+ return all_tools
+
+# Streamlit UI
+st.title("CAMEL Dynamic Research Assistant")
+topic = st.text_input("Enter a research topic:", value="latest breakthroughs in quantum computing")
+
+if st.button("Generate Report") and topic:
+ st.info("๐Ÿค– Starting research agent...")
+
+ # Base tools that don't require author identifiers
+ base_tools = [
+ *SemanticScholarToolkit().get_tools(),
+ *ArxivToolkit().get_tools(),
+ *AskNewsToolkit().get_tools(),
+ *ThinkingToolkit().get_tools(),
+ *FileWriteToolkit().get_tools(),
+ *LinkedInToolkit().get_tools(),
+ ]
+
+ # Create dynamic research agent
+ research_agent = DynamicResearchAgent(base_tools)
+
+ # Enhanced task prompt that explains available capabilities
+ task_prompt = f"""
+ Create a comprehensive research report on: {topic}
+
+ Your complete task includes:
+ 1. Search for recent and relevant papers using SemanticScholar and ArXiv
+ 2. Identify key researchers and their contributions in this field
+ 3. If you find important authors, mention their IDs for potential GoogleScholar integration
+ 4. Analyze the latest trends, breakthroughs, and developments
+ 5. Get recent news using AskNews if relevant
+ 6. Synthesize ALL findings into a well-structured comprehensive report
+ 7. Save the final report as a local file using FileWrite tools
+ 8. When the report is complete and saved, respond with "CAMEL_TASK_DONE"
+
+ Available tools:
+ - SemanticScholar: Search academic papers, get author information
+ - ArXiv: Search preprints and recent papers
+ - AskNews: Get recent news and developments
+ - Thinking: Plan and reflect on your research strategy
+ - FileWrite: Save your findings and reports
+ - LinkedIn: Research author profiles if needed
+
+ IMPORTANT: Don't just list papers - create a comprehensive analysis report that synthesizes
+ the information, identifies trends, and provides insights. Save this report to a file.
+ """
+
+ # Initialize RolePlaying session
+ role_play = RolePlaying(
+ assistant_role_name="Senior Research Analyst",
+ user_role_name="Research Director",
+ assistant_agent_kwargs=dict(
+ model=model,
+ tools=research_agent.get_all_tools()
+ ),
+ user_agent_kwargs=dict(model=model),
+ task_prompt=task_prompt,
+ with_task_specify=False
+ )
+
+ # Start conversation
+ next_msg = role_play.init_chat()
+
+ # Conversation loop with dynamic tool addition
+ conversation_container = st.container()
+ step_count = 0
+
+ with conversation_container:
+ while True:
+ step_count += 1
+
+ with st.expander(f"Step {step_count}: Agent Interaction", expanded=True):
+ assistant_resp, user_resp = role_play.step(next_msg)
+
+ if assistant_resp.terminated or user_resp.terminated:
+ st.info("๐Ÿ Conversation terminated by agent")
+ break
+
+ # Check if agent mentions needing GoogleScholar for specific authors
+ # This is a simple pattern - you could make this more sophisticated
+ content = assistant_resp.msg.content.lower()
+ if "google scholar" in content and "author" in content:
+ st.info("๐Ÿ” Agent requested GoogleScholar tools - this could be implemented with author discovery")
+
+ # Display conversation
+ st.markdown("**๐Ÿค– Research Analyst:**")
+ st.write(assistant_resp.msg.content)
+
+ st.markdown("**๐Ÿ‘ค Research Director:**")
+ st.write(user_resp.msg.content)
+
+ # Check for completion in both agent responses
+ if ("CAMEL_TASK_DONE" in user_resp.msg.content or
+ "CAMEL_TASK_DONE" in assistant_resp.msg.content or
+ "report is complete" in assistant_resp.msg.content.lower() or
+ "task completed" in assistant_resp.msg.content.lower()):
+ st.success("โœ… Task completed successfully!")
+ break
+
+ next_msg = assistant_resp.msg
+
+ # Safety break to prevent infinite loops
+ if step_count > 20:
+ st.warning("โš ๏ธ Maximum steps reached. Stopping conversation.")
+ break
+
+ st.success("๐ŸŽ‰ Report generation completed!")
+ st.info("๐Ÿ“„ The research report has been saved locally by the agent.")
\ No newline at end of file
diff --git a/examples/usecases/multi_agent_research_assistant/requirements.txt b/examples/usecases/multi_agent_research_assistant/requirements.txt
new file mode 100644
index 000000000..c913a7079
--- /dev/null
+++ b/examples/usecases/multi_agent_research_assistant/requirements.txt
@@ -0,0 +1,6 @@
+chunkr-ai==0.1.3
+python-dotenv==1.1.0
+streamlit==1.5.1
+camel-ai[all]==0.2.62
+docx2markdown==0.1.0
+asknews==0.11.10
\ No newline at end of file