This project demonstrates a collaborative multi-agent system using LangChain
and LangGraph
. It is designed to process user queries by leveraging two specialized AI agents: a Research Agent and a Writer Agent. Each agent performs a distinct role and collaborates to generate high-quality answers.
-
Dynamic Multi-Agent Collaboration:
- The Research Agent fetches relevant information based on the user's query.
- The Writer Agent synthesizes the research results into a concise and well-structured summary.
-
Role-Specific Prompts:
- Tailored prompts ensure that each agent performs its role effectively using
ChatPromptTemplate
.
- Tailored prompts ensure that each agent performs its role effectively using
-
Workflow Orchestration:
- Built using
langgraph.graph.StateGraph
to manage the execution order and interaction between agents.
- Built using
-
Modular Design:
- Each agent's functionality is encapsulated, making the system easy to extend or modify.
-
Simple Execution:
- A single function,
run_multi_agent_system
, handles the user query and executes the workflow seamlessly.
- A single function,
-
Input:
- The user provides a query, such as a topic or question they need information about.
-
Agent Tasks:
- Research Agent: Gathers detailed information related to the query.
- Writer Agent: Summarizes the research results into a concise and polished format.
-
Output:
- The final output is a user-friendly summary of the research results.
For example, the query:
"What are the key challenges in AI-based electricity theft detection?"
Results in:
- The Research Agent fetching detailed insights.
- The Writer Agent summarizing those insights into a clear answer.
- LangChain:
- Provides prompt management and integration with OpenAI models.
- LangGraph:
- Manages the multi-agent workflow using a state graph.
- OpenAI API:
- Powers the agents using GPT-3.5-turbo.
- Python 3.8 or later
- OpenAI API key
-
Clone the repository:
git clone <repository-url> cd <repository-folder>
-
Create a virtual environment:
python -m venv env source env/bin/activate # On Windows: .\env\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set your OpenAI API key:
export OPENAI_API_KEY="your-openai-api-key" # On Windows: set OPENAI_API_KEY="your-openai-api-key"
-
Run the script:
python main.py
-
Enter your query when prompted:
Enter your query: What are the key benefits of AI in healthcare?
-
View the final summarized answer:
Final answer: AI in healthcare offers benefits like personalized treatments, early disease detection, and enhanced diagnostic accuracy.
-
Agents:
- Research Agent: Gathers information based on the query.
- Writer Agent: Summarizes the gathered information into a user-friendly answer.
-
Workflow Management:
- Built using
StateGraph
to define and orchestrate the multi-agent flow.
- Built using
-
research_agent_func: Fetches detailed information using the research prompt.
-
writer_agent_func: Summarizes the research results into a concise format.
-
run_multi_agent_system(query): Executes the workflow for a given query and returns the final answer.
- Add more specialized agents, such as:
- Validator Agent to verify the accuracy of research.
- Editor Agent to improve grammar and style.
- Expand the system to handle multi-query workflows.
- Integrate with external knowledge bases for enhanced research capabilities.
For any questions or collaboration opportunities, feel free to reach out:
- Email: aman_srivastava14@outlook.com
- LinkedIn: InfiniteLoopster-coder
- GitHub: InfiniteLoopster-coder