Overview

This project is a local Legal AI application that combines document upload, conversation memory, legal workflow skills, and retrieval optimization. The goal is not simply to build another chat interface, but to explore how a legal assistant can use memory and context more deliberately when answering legal and contract-related questions.

In the application, a user can upload a legal document, ask a general legal question, or ask for a document-specific review. The system stores useful conversation context with SimpleMem, retrieves relevant uploaded document chunks, detects the type of legal task automatically, and applies a matching legal workflow such as contract review, clause risk analysis, compliance checking, negotiation, missing-protection review, or plain-English explanation.

The project repository is available at github.com/mohammed840/simplemem-legal-ai, and the SimpleMem paper is available on arXiv at arxiv.org/abs/2605.13941.

Why Simple Chat Is Not Enough

Legal work is context-heavy. A user may first ask about the difference between an employee and an independent contractor, then upload a contractor agreement, then ask whether the agreement creates worker misclassification risk. A basic chatbot may answer each step separately. A memory-aware legal assistant should connect those steps.

That is the main idea behind this implementation. The app does not only pass the latest user message to a model. It also asks:

  • What did the user already ask about?
  • Is there a document that should ground the answer?
  • Which legal workflow best matches this question?
  • What prior memory or uploaded source should be retrieved?
  • Has retrieval been optimized based on previous failures?

This turns the assistant from a one-shot responder into a system that can build continuity across a legal workflow.

Connection to the SimpleMem Paper

The SimpleMem paper, referenced in this project as arXiv 2605.13941v1, is important because it treats memory as a first-class part of an AI system rather than as an afterthought. Instead of relying only on the model’s context window, SimpleMem provides a structured way to store, retrieve, and reuse information across interactions.

The paper also motivates the idea that memory systems should improve over time. That is where EvolveMem and AutoResearch-style optimization matter. A memory system should not only retrieve information; it should evaluate whether the retrieval helped, diagnose weak answers, and adjust retrieval behavior.

This project applies that idea to Legal AI. Legal questions often fail when the assistant retrieves the wrong context, misses the relevant clause, or answers too generally. By using SimpleMem memory and an AutoResearch-style feedback loop, the application can track failures, adjust retrieval settings, and explain which memory or document context shaped the answer.

What We Built

The implementation includes four main layers.

Layer Role
Ask AI interface Provides a local browser app where users can ask legal questions and upload documents.
Document memory layer Indexes uploaded files so the model can answer from the actual source material rather than relying only on general knowledge.
SimpleMem memory layer Stores useful prior interactions so the system can reuse legal context from previous questions.
Workflow skill layer Imports legal task instructions from ai-legal-claude and loads the appropriate workflow for contract review, clause risk analysis, negotiation, compliance, or explanation.

Together, these layers create a legal assistant that can move across a workflow instead of answering each message in isolation.

user question + uploaded document
        |
        v
task detection -> document retrieval -> SimpleMem retrieval
        |                  |                    |
        v                  v                    v
legal workflow skill -> source-aware answer -> memory update

AutoResearch Reasoning

The application also includes a visible AutoResearch Reasoning step. Before the final answer, the app explains whether it used uploaded documents, SimpleMem memory, or an optimized retrieval configuration.

This is important for Legal AI because users need to know what an answer is based on. If the answer came from an uploaded agreement, the system should say that. If it used prior memory, it should say that too. If no source was retrieved and the answer relies on general model knowledge, the user should see that distinction.

The visible reasoning is not hidden chain-of-thought. It is a user-facing summary of the retrieval and source-selection process.

Example Workflow

A typical interaction looks like this:

User: What is the difference between an employee and an independent contractor?
Assistant: Gives a general legal explanation and stores the context.

User: Uploads a contractor agreement.
Assistant: Indexes the document and stores document metadata.

User: Does this agreement create misclassification risk?
Assistant:
  1. Detects a contract-risk review task.
  2. Retrieves relevant agreement chunks.
  3. Retrieves the prior worker-classification memory.
  4. Applies the clause risk workflow.
  5. Explains which document and memory context shaped the answer.

This is the behavior I wanted from the system: not just a fluent legal answer, but a continuity-aware workflow that remembers the legal issue, grounds the review in the uploaded agreement, and exposes how the answer was assembled.

Why This Matters

Legal AI systems need more than fluent text generation. They need memory, source awareness, workflow discipline, and retrieval transparency. Without those layers, the model may sound confident while missing the clause, the prior context, or the jurisdictional issue that actually matters.

This application shows one practical direction: combine SimpleMem memory, uploaded-document retrieval, AutoResearch-style optimization, and legal workflow skills into a local legal assistant. The result is a system that can answer general legal questions, review uploaded agreements, reuse prior context, and explain how its retrieval process influenced the final answer.

In short, the project demonstrates how memory can make Legal AI more useful, more transparent, and more aligned with real legal workflows.