From a61502e59d075e6c930e5afab9ef2f89c0130b71 Mon Sep 17 00:00:00 2001 From: Madhu Shantan Date: Tue, 10 Dec 2024 13:12:18 +0530 Subject: [PATCH 1/4] added video file --- ai_agent_tutorials/ai_legal_agent_team/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ai_agent_tutorials/ai_legal_agent_team/README.md b/ai_agent_tutorials/ai_legal_agent_team/README.md index 6c7b2e6..edfb5e5 100644 --- a/ai_agent_tutorials/ai_legal_agent_team/README.md +++ b/ai_agent_tutorials/ai_legal_agent_team/README.md @@ -4,6 +4,8 @@ An intelligent legal document analysis Agent Team powered by GPT-4 and Qdrant ve ## Demo: +https://github.com/user-attachments/assets/e89f2fc9-6a66-4eac-98dd-b4cb04e50419 + ## Features - **Specialized Agent Team** From 5c7b92b65c9273a7eec4700378a64a201e1842ae Mon Sep 17 00:00:00 2001 From: ShubhamSaboo Date: Tue, 10 Dec 2024 17:54:18 -0600 Subject: [PATCH 2/4] added new demo --- .../ai_legal_agent_team/README.md | 10 +--- .../{main.py => legal_agent_team.py} | 57 +++++++++++++------ 2 files changed, 42 insertions(+), 25 deletions(-) rename ai_agent_tutorials/ai_legal_agent_team/{main.py => legal_agent_team.py} (89%) diff --git a/ai_agent_tutorials/ai_legal_agent_team/README.md b/ai_agent_tutorials/ai_legal_agent_team/README.md index edfb5e5..eda43ae 100644 --- a/ai_agent_tutorials/ai_legal_agent_team/README.md +++ b/ai_agent_tutorials/ai_legal_agent_team/README.md @@ -1,10 +1,6 @@ -# 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. - -## Demo: - -https://github.com/user-attachments/assets/e89f2fc9-6a66-4eac-98dd-b4cb04e50419 +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. ## Features @@ -54,7 +50,7 @@ https://github.com/user-attachments/assets/e89f2fc9-6a66-4eac-98dd-b4cb04e50419 ## Notes - Supports PDF documents only -- Uses GPT-4 for analysis +- Uses GPT-4o for analysis - Uses text-embedding-3-small for embeddings - Requires stable internet connection - API usage costs apply diff --git a/ai_agent_tutorials/ai_legal_agent_team/main.py b/ai_agent_tutorials/ai_legal_agent_team/legal_agent_team.py similarity index 89% rename from ai_agent_tutorials/ai_legal_agent_team/main.py rename to ai_agent_tutorials/ai_legal_agent_team/legal_agent_team.py index 51b2697..319d570 100644 --- a/ai_agent_tutorials/ai_legal_agent_team/main.py +++ b/ai_agent_tutorials/ai_legal_agent_team/legal_agent_team.py @@ -7,6 +7,7 @@ from phi.model.openai import OpenAIChat from phi.embedder.openai import OpenAIEmbedder import tempfile import os + #initializing the session state variables def init_session_state(): """Initialize session state variables""" @@ -30,7 +31,7 @@ def init_qdrant(): if not st.session_state.qdrant_url: raise ValueError("Qdrant URL not provided") - return Qdrant( #from the phidata Qdrant docs + return Qdrant( collection="legal_knowledge", url=st.session_state.qdrant_url, 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") init_session_state() - st.title("AI Legal Agent Team") + st.title("AI Legal Agent Team 👨‍⚖️") with st.sidebar: st.header("🔑 API Configuration") @@ -131,7 +132,7 @@ def main(): legal_researcher = Agent( name="Legal Researcher", role="Legal research specialist", - model=OpenAIChat(model="gpt-4"), + model=OpenAIChat(model="gpt-4o"), tools=[DuckDuckGo()], knowledge=st.session_state.knowledge_base, search_knowledge=True, @@ -148,7 +149,7 @@ def main(): contract_analyst = Agent( name="Contract Analyst", role="Contract analysis specialist", - model=OpenAIChat(model="gpt-4"), + model=OpenAIChat(model="gpt-4o"), knowledge=knowledge_base, search_knowledge=True, instructions=[ @@ -162,7 +163,7 @@ def main(): legal_strategist = Agent( name="Legal Strategist", role="Legal strategy specialist", - model=OpenAIChat(model="gpt-4"), + model=OpenAIChat(model="gpt-4o"), knowledge=knowledge_base, search_knowledge=True, instructions=[ @@ -177,7 +178,7 @@ def main(): st.session_state.legal_team = Agent( name="Legal Team Lead", role="Legal team coordinator", - model=OpenAIChat(model="gpt-4"), + model=OpenAIChat(model="gpt-4o"), team=[legal_researcher, contract_analyst, legal_strategist], knowledge=st.session_state.knowledge_base, search_knowledge=True, @@ -218,7 +219,17 @@ def main(): elif not uploaded_file: st.info("👈 Please upload a legal document to begin analysis") 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 = { "Contract Review": { @@ -249,15 +260,22 @@ def main(): } 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 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..."): try: # Ensure OpenAI API key is set @@ -269,14 +287,19 @@ def main(): Using the uploaded document as reference: 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'])} Please search the knowledge base and provide specific references from the document. """ 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) @@ -326,8 +349,6 @@ def main(): except Exception as e: st.error(f"Error during analysis: {str(e)}") - else: - st.warning("Please enter a query or select an analysis type") else: st.info("Please upload a legal document to begin analysis") From 65b9aa28a2023675b81df2745ad281f9af7ead04 Mon Sep 17 00:00:00 2001 From: ShubhamSaboo Date: Tue, 10 Dec 2024 17:56:10 -0600 Subject: [PATCH 3/4] chore: updated README --- README.md | 1 + ai_agent_tutorials/ai_legal_agent_team/README.md | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 18e2022..d3fecb2 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ A curated collection of awesome LLM apps built with RAG and AI agents. This repo ### AI Agents - [💼 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 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 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) diff --git a/ai_agent_tutorials/ai_legal_agent_team/README.md b/ai_agent_tutorials/ai_legal_agent_team/README.md index eda43ae..765d245 100644 --- a/ai_agent_tutorials/ai_legal_agent_team/README.md +++ b/ai_agent_tutorials/ai_legal_agent_team/README.md @@ -4,14 +4,14 @@ A Streamlit application that simulates a full-service legal team using multiple ## Features -- **Specialized 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. +- **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. - - 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** - Contract Review - Done by Contract Analyst From c482acf4c149b8a0b0a53b21ee879359cdca4208 Mon Sep 17 00:00:00 2001 From: ShubhamSaboo Date: Tue, 10 Dec 2024 19:38:51 -0600 Subject: [PATCH 4/4] chore: updated README --- ai_agent_tutorials/ai_legal_agent_team/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ai_agent_tutorials/ai_legal_agent_team/README.md b/ai_agent_tutorials/ai_legal_agent_team/README.md index 765d245..8f340fc 100644 --- a/ai_agent_tutorials/ai_legal_agent_team/README.md +++ b/ai_agent_tutorials/ai_legal_agent_team/README.md @@ -38,7 +38,7 @@ A Streamlit application that simulates a full-service legal team using multiple 3. **Run the Application** ```bash - streamlit run main.py + streamlit run legal_agent_team.py ``` 4. **Use the Interface** - Enter API credentials