Article
legal-researchai-agentcase-lawpythonapiwestlawthomson-reutersmemo-drafting
Draft a Legal Memo with the AI-Powered Legal Research Agent
Use Westlaw's Legal Research Agent to analyze a legal question and generate a formatted memo. This guide shows how to define your research scope, generate a draft with supporting case law, and verify citations to build a strong argument.
intermediate30 min5 steps
The play
- Frame Your Legal QuestionStart with a precise, well-defined legal question. The quality of the agent's output depends directly on the clarity of your input. Specify the jurisdiction and the core legal issue you need to resolve. This focuses the search on relevant case law and statutes.
- Initiate AI-Powered ResearchInvoke the Legal Research Agent via its API. Pass your legal question, jurisdiction, and desired output format ('memo'). The agent will query Westlaw's databases for case law, statutes, and secondary sources to synthesize an initial draft.
- Review the Synthesized MemoAnalyze the generated memo. The Legal Research Agent provides a structured document with key arguments, supporting cases, and statutory references. Pay close attention to the confidence scores associated with each citation to gauge the strength of the source.
- Request a Precedent MapTo understand how the key precedent has been treated, ask the Legal Research Agent to generate a precedent map or a treatment analysis (e.g., 'KeyCite' in Westlaw). This visualizes how subsequent cases have followed, distinguished, or overruled the controlling case.
- Refine and FinalizeIncorporate your own expertise. Use the AI-generated memo as a powerful first draft. Edit the analysis, strengthen arguments using the precedent map, and format the document according to your firm's or court's specific requirements. The agent accelerates research, but the final work product is your responsibility.
Starter code
import os
import requests
import json
# NOTE: This is a hypothetical API for demonstration purposes.
# Replace with the actual API endpoint and key provided by Thomson Reuters Westlaw.
API_KEY = os.environ.get("WESTLAW_API_KEY", "YOUR_WESTLAW_API_KEY")
API_BASE_URL = "https://api.westlaw.com/v1/agent"
LEGAL_QUESTION = (
"Under California law, what is the standard for determining if an employee's social media post, "
"critical of their employer, constitutes protected concerted activity under the National Labor Relations Act (NLRA)?"
)
JURISDICTION = "California"
def run_legal_research_agent():
"""Demonstrates a call to the Legal Research Agent to generate a memo."""
if API_KEY == "YOUR_WESTLAW_API_KEY":
print("Error: Please set your WESTLAW_API_KEY environment variable.")
return
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
print(f"Submitting research request for jurisdiction: {JURISDICTION}...")
print(f"Query: {LEGAL_QUESTION}\n")
try:
# Step 1: Generate the initial research memo
response = requests.post(
f"{API_BASE_URL}/research",
headers=headers,
json={
"query": LEGAL_QUESTION,
"jurisdiction": JURISDICTION,
"output_format": "memo",
"include_confidence_scores": True,
"include_precedent_map": False
}
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
memo_data = response.json()
print("--- Generated Memo Draft ---")
print(json.dumps(memo_data, indent=2))
print("\n--- End of Memo ---\n")
# Example of a follow-up action: Verify a specific citation
if memo_data.get('citations'):
target_citation = memo_data['citations'][0]['citation_text']
print(f"Performing citation verification for: {target_citation}")
cite_check_response = requests.post(
f"{API_BASE_URL}/verify-citation",
headers=headers,
json={"citation": target_citation}
)
cite_check_response.raise_for_status()
verification_result = cite_check_response.json()
print("--- Citation Verification Result ---")
print(json.dumps(verification_result, indent=2))
except requests.exceptions.RequestException as e:
print(f"An API error occurred: {e}")
print("Please ensure the API endpoint is correct and your key is valid.")
print("Since this is a hypothetical example, the script simulates the workflow.")
if __name__ == "__main__":
run_legal_research_agent()