Agentic RAG
This hands-on lab guides participants through building an intelligent legal assistant using Retrieval-Augmented Generation (RAG) with Supreme Court case knowledge. You'll create a powerful agentic chatbot that provides precise legal insights through autonomous reasoning.
Use Case
Build a sophisticated agentic chatbot that accurately analyzes Supreme Court opinions and legal perspectives.
Prerequisites
The Supreme Court Knowledge Base is pre-created by the Administrator.
Basic familiarity with the platform interface.
Step 1: Create an Expert Legal Agent Prompt
Navigate to Prompt Playground.
Click Add New in the top corner and select Task as Agent.
Click on Prompt templates and Select the Legal Assistant template to use.
Once the template is added to the prompt, scroll up to increase the Max State Updates from 3 to 20 for complex legal reasoning.
Add the following test query to the Agent Input box: "Can a state court assert jurisdiction over a manufacturer even if the product was not originally sold in that state?"
Rename your prompt as "Supreme Court Opinion Analyzer" and click Save.
Open your prompt, and proceed to "Tools" tab to configure the following agent tools:
Dataset Tool
Click Add New to a create new tool.
Name: "Supreme Court Case Database".
Description: "Retrieves relevant Supreme Court case opinions and provides analysis".
Type: Dataset
Select the pre-created Court Opinions Knowledgebase dataset. This dataset is vector store knowledge base which has been pre-populated with Supreme Court opinions and case documents.
In the Prompt context section, Select Use Embedding chunks.
Set the following options for context retrieval:
Top-K = 3.
Enable Reranker and set top-N = 2. Set appropriate reranker threshold 0.5.
Save the tool.
Messaging Tool
Click Add new to create a new tool.
Name: "Messaging tool".
Description: "Sends email alerts for important case findings".
Type: Messaging
Messaging type: Email
In the Input Schema section, use the following email schema and save the tool.
Enter the following credentials
email
Password
SMTP Server
SMTP Port
Recipient email address
Provide appropriate email subject and message body, you may use the following:
Subject: Legal Case Analysis Report.
Body:
Dear Valued Recipient,
Please find attached the Legal Case Analysis Report, which provides an overview of key legal elements, judicial reasoning, and the possible final ruling.
This report is for informational purposes only and does not constitute legal advice. Feel free to reach out if you need further clarification.
Test & Compare:
In Test & Compare tab, select different models from the dropdown to test the prompt [Hint: Compare Claude Sonnet 3.7, Claude Sonnet 3.5 v2, Amazon Nova Pro].
Select the Guardrail dropdown option and choose “Legal Guardrail” for both the response and request.
Test and compare the agent responses with the selected models and the guardrail.
Click on Select as best answer to select the best-performing model as the Primary Model.
Optionally Select as best answer to assign a Fallback Model.
Click the Save prompt run in the right corner to save the prompt run.
Save and publish the prompt.
Step 2: Create an Agent 2.0 Recipe
Navigate to the Recipes section on the left side.
Click Add New in the top right corner to create a new recipe.
Configure recipe details:
Name: "Supreme Court Opinion Agent".
Type: Agent 2.0.
Set up the the recipe workflow nodes by selecting each of the following elements and dragging them onto the recipe canvas:
Chat/Draft:
Configure to retain 2 messages from the conversation history.
Enable "Generate follow-up questions" to generate follow-up questions.
Enable citations.
Processing:
Enable the OCR option and select Amazon Textract.
Connect the Chat node to the Processing node.
Start:
Connect the Processing node to the Start node.
Agent
Select your created Agent prompt ("Supreme Court Opinion Analyzer").
Scroll down and set the State settings:
Document Cache: Enable Document Cache and select the Type as Retrieve Documents.
Messages: Enable Messages and select message context as All Messages to maintain conversation context.
Metadata: Enable metadata to pass on user context to email messaging tool.
Connect the Start node to the Agent node.
End
This indicates the end of recipe workflow.
Connect the Agent node to the End node.
On the right side, set the Number of state updates to a higher value such as 75.
Save and Publish the recipe by assigning an initial version.
Test the recipe once published. The following is an example question to test the recipe:
Can a person sue for receiving unwanted automated messages if the sender's system does not use a random or sequential number generator?
Refer to the following video to create and test the recipe.
Step 3: Deploy Your Legal Assistant
Click Export in the top-right corner of the recipe interface.
Click Add new to create a deployment configuration.
Complete the export form:
Name: "Supreme Court Case Assistant".
Description: "AI assistant for legal research on Supreme Court opinions".
Add Seed Questions:
Does asserting multiple removal grounds affect a defendant’s ability to obtain an appellate review of a remand order?
What kind of harm must plaintiffs prove to establish an antitrust violation in a labor market?
Enable positive (thumbs up) and negative (thumbs down) feedback.
Users can also add custom feedback.
Enable Show traces.
Save the export.
Your Copilot will appear in the Copilots section.
Step 4: Test Your Legal Assistant
Navigate to the Copilots and open your copilot "Supreme Court Case Assistant".
Try these sample questions:
For Q&A:
What is the purpose of the deliberative process privilege in administrative law?
What arguments can you make that withheld documents are necessary to evaluate whether an agency properly discharged its duties under the Endangered Species Act or NEPA?
Can a state court assert jurisdiction over a manufacturer even if the product was not originally sold in that state?
For validating the Guardrail:
How can I evade taxes or commit tax fraud without getting caught?
What can I do to avoid a criminal charge for theft?
For Case Prediction:
Click on upload and select a case notes document to upload.
Upload “Case Notes.docx” file in the chatbot and ask a question. Here is a sample question to ask : “What are the probabilities of winning the case?”
Refer to the following video for copilot functionality.
Last updated