Merge remote-tracking branch 'origin/ai-legal-agents' into ai-legal-agents

hould be don  the commit.
This commit is contained in:
Madhu 2024-12-11 23:51:13 +05:30
commit 304d1130c3
3 changed files with 49 additions and 29 deletions

View file

@ -36,6 +36,7 @@ A curated collection of awesome LLM apps built with RAG and AI agents. This repo
### AI Agents ### AI Agents
- [💼 AI Customer Support Agent](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_customer_support_agent) - [💼 AI Customer Support Agent](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_customer_support_agent)
- [📈 AI Investment Agent](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_investment_agent) - [📈 AI Investment Agent](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_investment_agent)
- [👨‍⚖️ AI Legal Agent Team](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_legal_agent_team)
- [👨‍💼 AI Services Agency](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_services_agency) - [👨‍💼 AI Services Agency](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_services_agency)
- [🏋️‍♂️ AI Health & Fitness Planner Agent](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_health_fitness_agent) - [🏋️‍♂️ AI Health & Fitness Planner Agent](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_health_fitness_agent)
- [📈 AI Startup Trend Analysis Agent](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_startup_trend_analysis_agent) - [📈 AI Startup Trend Analysis Agent](https://github.com/Shubhamsaboo/awesome-llm-apps/tree/main/ai_agent_tutorials/ai_startup_trend_analysis_agent)

View file

@ -1,19 +1,17 @@
# AI Legal Agent Team # 👨‍⚖️ AI Legal Agent Team
An intelligent legal document analysis Agent Team powered by GPT-4 and Qdrant vector database. The system uses a team of specialized AI agents to analyze legal documents, providing comprehensive insights, key points, and recommendations. We used phi-agent to create the agent team. A Streamlit application that simulates a full-service legal team using multiple AI agents to analyze legal documents and provide comprehensive legal insights. Each agent represents a different legal specialist role, from research and contract analysis to strategic planning, working together to provide thorough legal analysis and recommendations.
## Demo:
## Features ## Features
- **Specialized Agent Team** - **Specialized Legal AI Agent Team**
- Legal Researcher: Equipped with DuckDuckGo search tool to find and cite relevant legal cases and precedents. Provides detailed research summaries with sources and references specific sections from uploaded documents. - **Legal Researcher**: Equipped with DuckDuckGo search tool to find and cite relevant legal cases and precedents. Provides detailed research summaries with sources and references specific sections from uploaded documents.
- Contract Analyst: Specializes in thorough contract review, identifying key terms, obligations, and potential issues. References specific clauses from documents for detailed analysis. - **Contract Analyst**: Specializes in thorough contract review, identifying key terms, obligations, and potential issues. References specific clauses from documents for detailed analysis.
- Legal Strategist: Focuses on developing comprehensive legal strategies, providing actionable recommendations while considering both risks and opportunities. - **Legal Strategist**: Focuses on developing comprehensive legal strategies, providing actionable recommendations while considering both risks and opportunities.
- Team Lead: Coordinates analysis between team members, ensures comprehensive responses, properly sourced recommendations, and references to specific document parts. Acts as an Agent Team coordinator for all three agents. - **Team Lead**: Coordinates analysis between team members, ensures comprehensive responses, properly sourced recommendations, and references to specific document parts. Acts as an Agent Team coordinator for all three agents.
- **Document Analysis Types** - **Document Analysis Types**
- Contract Review - Done by Contract Analyst - Contract Review - Done by Contract Analyst
@ -40,7 +38,7 @@ An intelligent legal document analysis Agent Team powered by GPT-4 and Qdrant ve
3. **Run the Application** 3. **Run the Application**
```bash ```bash
streamlit run main.py streamlit run legal_agent_team.py
``` ```
4. **Use the Interface** 4. **Use the Interface**
- Enter API credentials - Enter API credentials
@ -52,7 +50,7 @@ An intelligent legal document analysis Agent Team powered by GPT-4 and Qdrant ve
## Notes ## Notes
- Supports PDF documents only - Supports PDF documents only
- Uses GPT-4 for analysis - Uses GPT-4o for analysis
- Uses text-embedding-3-small for embeddings - Uses text-embedding-3-small for embeddings
- Requires stable internet connection - Requires stable internet connection
- API usage costs apply - API usage costs apply

View file

@ -7,6 +7,7 @@ from phi.model.openai import OpenAIChat
from phi.embedder.openai import OpenAIEmbedder from phi.embedder.openai import OpenAIEmbedder
import tempfile import tempfile
import os import os
#initializing the session state variables #initializing the session state variables
def init_session_state(): def init_session_state():
"""Initialize session state variables""" """Initialize session state variables"""
@ -30,7 +31,7 @@ def init_qdrant():
if not st.session_state.qdrant_url: if not st.session_state.qdrant_url:
raise ValueError("Qdrant URL not provided") raise ValueError("Qdrant URL not provided")
return Qdrant( #from the phidata Qdrant docs return Qdrant(
collection="legal_knowledge", collection="legal_knowledge",
url=st.session_state.qdrant_url, url=st.session_state.qdrant_url,
api_key=st.session_state.qdrant_api_key, api_key=st.session_state.qdrant_api_key,
@ -76,7 +77,7 @@ def main():
st.set_page_config(page_title="Legal Document Analyzer", layout="wide") st.set_page_config(page_title="Legal Document Analyzer", layout="wide")
init_session_state() init_session_state()
st.title("AI Legal Agent Team") st.title("AI Legal Agent Team 👨‍⚖️")
with st.sidebar: with st.sidebar:
st.header("🔑 API Configuration") st.header("🔑 API Configuration")
@ -131,7 +132,7 @@ def main():
legal_researcher = Agent( legal_researcher = Agent(
name="Legal Researcher", name="Legal Researcher",
role="Legal research specialist", role="Legal research specialist",
model=OpenAIChat(model="gpt-4"), model=OpenAIChat(model="gpt-4o"),
tools=[DuckDuckGo()], tools=[DuckDuckGo()],
knowledge=st.session_state.knowledge_base, knowledge=st.session_state.knowledge_base,
search_knowledge=True, search_knowledge=True,
@ -148,7 +149,7 @@ def main():
contract_analyst = Agent( contract_analyst = Agent(
name="Contract Analyst", name="Contract Analyst",
role="Contract analysis specialist", role="Contract analysis specialist",
model=OpenAIChat(model="gpt-4"), model=OpenAIChat(model="gpt-4o"),
knowledge=knowledge_base, knowledge=knowledge_base,
search_knowledge=True, search_knowledge=True,
instructions=[ instructions=[
@ -162,7 +163,7 @@ def main():
legal_strategist = Agent( legal_strategist = Agent(
name="Legal Strategist", name="Legal Strategist",
role="Legal strategy specialist", role="Legal strategy specialist",
model=OpenAIChat(model="gpt-4"), model=OpenAIChat(model="gpt-4o"),
knowledge=knowledge_base, knowledge=knowledge_base,
search_knowledge=True, search_knowledge=True,
instructions=[ instructions=[
@ -177,7 +178,7 @@ def main():
st.session_state.legal_team = Agent( st.session_state.legal_team = Agent(
name="Legal Team Lead", name="Legal Team Lead",
role="Legal team coordinator", role="Legal team coordinator",
model=OpenAIChat(model="gpt-4"), model=OpenAIChat(model="gpt-4o"),
team=[legal_researcher, contract_analyst, legal_strategist], team=[legal_researcher, contract_analyst, legal_strategist],
knowledge=st.session_state.knowledge_base, knowledge=st.session_state.knowledge_base,
search_knowledge=True, search_knowledge=True,
@ -218,7 +219,17 @@ def main():
elif not uploaded_file: elif not uploaded_file:
st.info("👈 Please upload a legal document to begin analysis") st.info("👈 Please upload a legal document to begin analysis")
elif st.session_state.legal_team: elif st.session_state.legal_team:
st.header("Document Analysis") # Create a dictionary for analysis type icons
analysis_icons = {
"Contract Review": "📑",
"Legal Research": "🔍",
"Risk Assessment": "⚠️",
"Compliance Check": "",
"Custom Query": "💭"
}
# Dynamic header with icon
st.header(f"{analysis_icons[analysis_type]} {analysis_type} Analysis")
analysis_configs = { analysis_configs = {
"Contract Review": { "Contract Review": {
@ -249,15 +260,22 @@ def main():
} }
st.info(f"📋 {analysis_configs[analysis_type]['description']}") st.info(f"📋 {analysis_configs[analysis_type]['description']}")
st.write(f"🤖 Active Agents: {', '.join(analysis_configs[analysis_type]['agents'])}") #dictionary!! st.write(f"🤖 Active Legal AI Agents: {', '.join(analysis_configs[analysis_type]['agents'])}") #dictionary!!
# Replace the existing user_query section with this:
if analysis_type == "Custom Query":
user_query = st.text_area(
"Enter your specific query:",
help="Add any specific questions or points you want to analyze"
)
else:
user_query = None # Set to None for non-custom queries
user_query = st.text_area(
"Enter your specific query:",
help="Add any specific questions or points you want to analyze"
)
if st.button("Analyze"): if st.button("Analyze"):
if user_query or analysis_type != "Custom Query": if analysis_type == "Custom Query" and not user_query:
st.warning("Please enter a query")
else:
with st.spinner("Analyzing document..."): with st.spinner("Analyzing document..."):
try: try:
# Ensure OpenAI API key is set # Ensure OpenAI API key is set
@ -269,14 +287,19 @@ def main():
Using the uploaded document as reference: Using the uploaded document as reference:
Primary Analysis Task: {analysis_configs[analysis_type]['query']} Primary Analysis Task: {analysis_configs[analysis_type]['query']}
Additional User Query: {user_query if user_query else 'None'}
Focus Areas: {', '.join(analysis_configs[analysis_type]['agents'])} Focus Areas: {', '.join(analysis_configs[analysis_type]['agents'])}
Please search the knowledge base and provide specific references from the document. Please search the knowledge base and provide specific references from the document.
""" """
else: else:
combined_query = user_query combined_query = f"""
Using the uploaded document as reference:
{user_query}
Please search the knowledge base and provide specific references from the document.
Focus Areas: {', '.join(analysis_configs[analysis_type]['agents'])}
"""
response = st.session_state.legal_team.run(combined_query) response = st.session_state.legal_team.run(combined_query)
@ -326,8 +349,6 @@ def main():
except Exception as e: except Exception as e:
st.error(f"Error during analysis: {str(e)}") st.error(f"Error during analysis: {str(e)}")
else:
st.warning("Please enter a query or select an analysis type")
else: else:
st.info("Please upload a legal document to begin analysis") st.info("Please upload a legal document to begin analysis")