Agentic RAG
Build an agentic chatbot using Knowledgebase (Legal Scotus)
This lab focuses on building an agentic chatbot that leverages the SCOTUS legal knowledge base to provide precise and context-aware legal insights. You will integrate retrieval mechanisms, natural language processing (NLP), and autonomous reasoning to create an intelligent assistant for legal research and case analysis.
Use case:
Build an Agentic chatbot with a Legal Supreme Court dataset.
Pre-requisites:
S3 bucket path with Supreme Court reviews.
Step 1: Create Knowledgebase using QnA Recipe Template
Navigate to Recipe.
Click the Add new button in the top corner of Recipe.
Provide a suitable name and description of the recipe.
Select type QnA.
Drag the Source tile from the Elements panel on the left-hand side onto the Central Canvas. In the source tile, select Amazon S3 as the connector. Enter Supreme Court reviews bucket path.
Add Dataset tile (Click + to create a new dataset).
Connect the Source tile to the Dataset tile.
Use Amazon Textract for OCR.
Add Knowledgebase tile.
Connect the Dataset tile to the Knowledgebase tile.
In Data Processing Preferences, Use the “Recursive” chunking type with 512 token size and select Embedding model(Amazon Titan Text Embeddings V2).
Save and Publish the recipe.
Run the recipe.
Step 2: Create a Summarization prompt in the playground.
Navigate to Prompt Playground.
Click the Add new button in the top corner of Prompt Playground.
Select prompt template Legal Summary.
Ensure you rename your prompt as loaded from the prompt template before saving it.
In the Test & Compare tab, choose the preferred models, assess their outputs, and identify the most optimal model. Subsequently, click "Select as Best Answer" to designate it as the Primary Model. Additionally, if necessary, you may assign an alternative model as the Fallback Model. However, selecting a Primary Model is mandatory.
Click "Save prompt run" button provided at the right corner.
Save and publish the prompt.
Step 3: Create an Agent prompt in the playground
Navigate to Prompt Playground.
Click the Add new button in the top corner of Prompt Playground.
Select prompt template Scotus Opinion Assistant.
Increase the Max State Updates from 3 to 20.
Add your natural language question "What was the central legal issue in the case Allen v. Cooper?" to the Agent Input (mandatory) text box.
Ensure you rename your prompt as loaded from the prompt template before saving it.
After saving the prompt, the Tool tab becomes visible within the prompt.
Create the following tools in the Agent prompt.
Set up Knowledgebase tool.
Click Add new in the tool and enter an appropriate name and description.
Select the type Dataset.
Select the dataset created in step 1 (Point number 6).
Select Use Embedding chunks in prompt context.
Set
top_k = 3
Enable Reranker and top_n = 2
Select Multi-quey rewrite in Advanced query reconstruction.
Save the tool.
Set up a tool with a Summarize prompt.
Click Add new in the tool and enter an appropriate name and description.
Select the type Prompt.
Select the prompt created in step 2.
Save tool.
Set up a tool with a Messaging tool.
Click Add new in the tool and enter an appropriate name and description.
Select the type Messaging.
Choose Email as the messaging type.
Configure email tool.
Enter Email tool input schema: <Update Default email>.
Hit enter after adding your email ID to the recipient email addresses.
Save the tool.
In the Test & Compare tab, choose the preferred models, assess their outputs, and identify the most optimal model. Subsequently, click "Select as Best Answer" to designate it as the Primary Model. Additionally, if necessary, you may assign an alternative model as the Fallback Model. However, selecting a Primary Model is mandatory.
Click "Save prompt run" button provided at the right corner.
Save and publish the prompt.
Step 3: Create an Agent 2.0 Recipe
Navigate to Recipe.
Click the Add New button in the top corner of Recipe.
Provide a suitable name and description of the recipe.
Select type Agent 2.0.
Setup following tiles.
Chat
Select 4 messages from the Conversation history dropdown.
Enable Generate follow-up questions.
Start - Connect the Chat tile to the Start tile.
Agent (Select the Agentic prompt created in Step 3).
Select All Messages in "Messages" dropdown agent state flag in the Agent tile.
Connect the Start tile to the Agent tile.
End - Connect Agent tile to End tile.
Save and Publish the recipe.
Click Test button on Chat tile to test the recipe.
Ask questions in the recipe Test.
What was the Supreme Court's decision regarding reconsidering a midtrial acquittal in Smith v. Massachusetts?
How did the Court interpret the language of the ISDEAA in relation to government contracts?
NOTE: Click on the Prompt Lens to inspect the Chatbot’s Response. Refer below image.
Step 4: Create a copilot.
Click the "Export" button located at the top-right corner of the recipe interface.
Click Add new button.
Configure the export form by referring to the sample resource agent recipe provided below.
Save the export form.
The Copilot will be displayed in the Copilot section of the interface.
Step 5: Ask Questions in the chatbot
Go to the Copilot tab and open your chatbot.
Ask questions
What was the Supreme Court's decision regarding reconsidering a midtrial acquittal in Smith v. Massachusetts?
How did the Court interpret the language of the ISDEAA in relation to government contracts?
Sample resources
Prompts-SCOTUS Opinion Assistant
QnA Recipe - Scotus Opinion Recipe
Agent recipe - SCOTUS Opinion Agent
Copilot - SCOTUS OpinionGuide AGENT
Refer the following video to create recipe.
Last updated