-
Notifications
You must be signed in to change notification settings - Fork 136
feat: Add MoU Drafter — AI-powered MoU & vendor-contract drafting with LaTeX/PDF output agentkit-challenge #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 34 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
cc3e641
feat: Add mou-drafter agent kit
rohith0110 302fa25
Some extra files
rohith0110 8d07d54
Updated all the dependencies
rohith0110 9630738
feat: Add postcss.config.mjs to enable Tailwind CSS processing
rohith0110 b34ef0a
feat: Add glassmorphism, force default dark mode, and replace browser…
rohith0110 b39f747
feat: Replace background gradients with a structural grid pattern and…
rohith0110 9f0335c
feat: Adjust glass-card transparency to 1.5% and set site background …
rohith0110 96e83ff
feat: Convert cards to transparent containers and style inputs for an…
rohith0110 8c55047
feat: Restore card outlines and padding with a highly transparent gla…
rohith0110 acaa9bb
feat: Enhance card background visibility/shadows and add red required…
rohith0110 81b9d5d
feat: Shift cards to pure pitch-black and set site background to grap…
rohith0110 d85236e
feat: Add MoU Drafter agent kit with UI and formatting critique fixes
rohith0110 7f7b2f3
Made a lot of changes to the flow and the website
rohith0110 3ddad46
feat(mou-drafter): server-side pdflatex preview (dev-only) + Overleaf…
rohith0110 a5bbc61
README.md changes
rohith0110 95b9480
fix(mou-drafter): resolve commercial-terms duplicate deadline, accept…
rohith0110 1eeab5c
Synced local files with flow export
rohith0110 cae22a9
Merge pull request #1 from rohith0110/feat/mou-drafter
rohith0110 75d8c5f
Merge branch 'main' into main
rohith0110 629a232
Suggested improvements by github actions bot
rohith0110 746b994
Merge pull request #2 from rohith0110/feat/mou-drafter
rohith0110 4346122
chore: update registry.json after merging PR #2
github-actions[bot] 83739dd
Externalize MoU drafter system prompt
rohith0110 b85209d
Code rabbit suggestions fixed
rohith0110 73c256c
minor fix to nextjs site code not being able to read lamatic config
rohith0110 06fceec
Merge pull request #3 from rohith0110/feat/mou-drafter
rohith0110 5aea9de
chore: update registry.json after merging PR #3
github-actions[bot] 944853f
more fixes for vercel
rohith0110 54fb09b
Merge pull request #4 from rohith0110/feat/mou-drafter
rohith0110 7bb9eb0
chore: update registry.json after merging PR #4
github-actions[bot] 557d761
more vercel fixes
rohith0110 02cc5b3
Merge pull request #5 from rohith0110/feat/mou-drafter
rohith0110 535eaff
chore: update registry.json after merging PR #5
github-actions[bot] 6048aee
Align MoU drafter app with supported Next stack
rohith0110 772d8b4
Reset teh changes made to registry json
rohith0110 f023108
fix(mou-drafter): enable strict TS and remove duplicate path entry
rohith0110 2fb261b
fix(mou-drafter): address code review issues across app and E2E test
rohith0110 cc6d71d
fix(mou-drafter): update downstream imports to use getLamaticClient f…
rohith0110 668216c
fix(mou-drafter): unquote config keys, populate metadata, fix Vercel …
rohith0110 9e1d9a2
updated lamatic config
rohith0110 43d20cd
Registry.json fix
rohith0110 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| MOU_DRAFTER_FLOW_ID="your-flow-id-here" | ||
| LAMATIC_API_URL="your-lamatic-api-url" | ||
| LAMATIC_PROJECT_ID="your-lamatic-project-id" | ||
| LAMATIC_API_KEY="your-lamatic-api-key" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| # MoU Drafter Agent Kit | ||
|
|
||
| <p align="center"> | ||
| <img src="https://img.shields.io/badge/Status-Beta-blue" alt="Status" /> | ||
| <img src="https://img.shields.io/badge/Aesthetics-Rich-purple" alt="Aesthetics" /> | ||
| </p> | ||
|
|
||
| **MoU Drafter** is an AI-powered contract and Memorandum of Understanding (MoU) drafting assistant. It takes a structured form input, runs it through a 21-point risk-management validation process, and generates a LaTeX-formatted document that can be compiled to PDF in a local sandbox or opened directly in Overleaf. | ||
|
|
||
| It is designed to produce a strong first draft that encodes protective legal patterns drawn from real vendor work for human review — it is not legal advice. | ||
|
|
||
| --- | ||
|
|
||
| ## 🚀 What It Does | ||
|
|
||
| 1. **Structured Form Intake**: Validates and normalizes 55 key agreement fields. | ||
| 2. **21 Risk-Management Patterns**: Automatically gates and embeds clause protections: | ||
| - Tie payment to milestone acceptance (versus lump-sum upfront risk). | ||
| - Deemed-acceptance windows. | ||
| - Mutual indemnity caps (1x fee multiplier) with gross-negligence carve-outs. | ||
| - Liquidated damages / late-delivery credits (gated on US/Canada governing law). | ||
| - Work-for-hire IP assignment and vendor pre-existing IP licensing. | ||
| - Force Majeure with modern cyberattack and pandemic carve-outs. | ||
| - 3-year confidentiality survival, subcontracting prior-consent, and marketing publicity approval. | ||
| 3. **LaTeX Output**: Generates clean, typographic LaTeX using the `article` class with defined terms formatted in small caps (`\textsc`). | ||
| 4. **PDF Compilation & Preview**: Compiles the LaTeX source to PDF through the development-only sandboxed compile route. | ||
| 5. **Direct Integrations**: Provides immediate options to download `.tex`, `.pdf`, or open the document directly in Overleaf via deep-link. | ||
|
|
||
| --- | ||
|
|
||
| ## 🛠️ Tech Stack | ||
|
|
||
| - **Framework**: Next.js (App Router), React, TypeScript | ||
| - **Forms**: `react-hook-form` + `zod` | ||
| - **Styling**: Tailwind CSS, CSS variables | ||
| - **Lamatic Integration**: `lamatic` SDK client for running the deployed flow | ||
| - **PDF Compilation**: Sandboxed server-side `pdflatex` route in development, with Overleaf and `.tex` fallbacks | ||
|
|
||
| --- | ||
|
|
||
| ## 🔑 Setup & Installation | ||
|
|
||
| ### 1. Environment Variables | ||
|
|
||
| Create a `.env.local` inside the `kits/mou-drafter/apps` folder: | ||
|
|
||
| ```bash | ||
| MOU_DRAFTER_FLOW_ID = "YOUR_LAMATIC_FLOW_ID" | ||
| LAMATIC_API_URL = "YOUR_LAMATIC_API_ENDPOINT" | ||
| LAMATIC_PROJECT_ID = "YOUR_LAMATIC_PROJECT_ID" | ||
| LAMATIC_API_KEY = "YOUR_LAMATIC_API_KEY" | ||
| ``` | ||
|
|
||
| ### 2. Run Locally | ||
|
|
||
| ```bash | ||
| # Make sure Docker or a compatible container runtime is available to enable PDF preview | ||
| cd kits/mou-drafter/apps | ||
| npm install | ||
| npm run dev | ||
| # Open http://localhost:3000 in your browser | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🧠 Lamatic Studio Flow Setup | ||
|
|
||
| To support this kit, your Lamatic flow (`mou-drafter`) must contain the following node graph: | ||
|
|
||
| ```mermaid | ||
| graph TD | ||
| A[API Request Trigger] --> B[Code Node: Validate Input] | ||
| B --> C[LLM Node: Clause Generator] | ||
| C --> D[Code Node: Assemble LaTeX] | ||
| D --> E[API Response] | ||
| ``` | ||
|
|
||
| ### 1. Validate Input Node | ||
|
|
||
| - **Type**: Code Node | ||
| - **Script File**: Referenced at `@scripts/mou-drafter_validate-input.ts` | ||
| - **Input Variables**: Reads `triggerNode_1.output` fields. | ||
| - **Output**: Returns a normalized payload with derived defaults, deliverables formatted as a block string, and upstream warning arrays. | ||
|
|
||
| ### 2. Clause Generator Node | ||
|
|
||
| - **Type**: LLM Node | ||
| - **Model**: `gemini-3-flash-preview` (preview) or `claude-sonnet-4-6` (fallback) | ||
| - **System Prompt**: Referenced at `@prompts/mou-drafter_clause-generator_system.md` | ||
| - **User Prompt**: Referenced at `@prompts/mou-drafter_clause-generator_user.md` | ||
| - **Output**: A JSON string containing the recitals, definitions, and selected clauses keyed by risk pattern. | ||
|
|
||
| ### 3. Assemble LaTeX Node | ||
|
|
||
| - **Type**: Code Node | ||
| - **Script File**: Referenced at `@scripts/mou-drafter_assemble-latex.ts` | ||
| - **Input Variables**: Reads outputs from the validation code node and LLM node. | ||
| - **Output**: Assembles the final `.tex` string by substituting variables into the template, escaping LaTeX characters, and verifying the presence of pattern comments. | ||
|
|
||
| ### 4. Response Node | ||
|
|
||
| - **Type**: Response Node | ||
| - **Output Mapping**: | ||
|
|
||
| ```json | ||
| { | ||
| "latex": "{{codeNode_assemble_latex.output.latex}}", | ||
| "clauseJson": "{{codeNode_assemble_latex.output.clauseJson}}", | ||
| "warnings": "{{codeNode_assemble_latex.output.warnings}}", | ||
| "patternReport": "{{codeNode_assemble_latex.output.patternReport}}" | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 📜 21 Gated Protective Patterns | ||
|
|
||
| | Anchor | Protection | Gating / Trigger Condition | | ||
| | ---------------------------------- | ------------------------------------------------------- | --------------------------------------------- | | ||
| | `payment-milestones` | Ties fee payments to milestone completion | `paymentSchedule === "milestone-based"` | | ||
| | `acceptance-window` | Deemed acceptance window for deliverables | Mandatory | | ||
| | `liquidated-damages` | Daily late delivery credits | Gated on `jurisdictionFamily === "us-canada"` | | ||
| | `indemnity-mutual-cap` | Caps indemnity exposure at 1x total fee | Mandatory | | ||
| | `liability-cap` | Limit of liability aligned with indemnity | Mandatory | | ||
| | `ip-work-for-hire` | Standard work-for-hire ownership transfer | Gated on `ipOwnership !== "not-applicable"` | | ||
| | `termination-dual` | Convenience and for-cause termination rules | Mandatory | | ||
| | `force-majeure-carveouts` | cyberattacks / pandemics are force majeure | Mandatory | | ||
| | `confidentiality-survival` | Confidentiality obligations survive term | Gated on `confidentialityRequired === true` | | ||
| | `no-subcontract-consent` | Requires written consent to outsource | Gated on `subcontractingAllowed === false` | | ||
| | `insurance-named-insured` | named-additional-insured requirement | Gated on `insuranceRequired === true` | | ||
| | `data-protection-dpa-lite` | Deletion-on-termination / 72h breach notice | Gated on `dataProtectionRequired === true` | | ||
| | `modifications-in-writing` | Amendments require a written instrument | Mandatory | | ||
| | `governing-law-venue-severability` | Severability, venue, and governing law | Mandatory | | ||
| | `no-publicity` | Prevents vendor from using name in ads | Gated on `noPublicityRequired === true` | | ||
| | `taxes-and-fees` | Tax treatment and late-payment interest | Mandatory | | ||
| | `cancellation-charges` | Event cancellation charges | Gated on `cancellationPolicy !== "none"` | | ||
| | `guest-count-adjustments` | Final guest count and extra-guest charges | Gated on catering count/rate fields | | ||
| | `food-safety-compliance` | Food-safety and licensing compliance | Gated on `foodSafetyRequired === true` | | ||
| | `allergen-handling` | Allergen labelling and dietary handling | Gated on `allergyHandlingRequired === true` | | ||
| | `event-logistics` | Event dates, time window, venue, and setup expectations | Gated on event-type engagement details | | ||
|
|
||
| --- | ||
|
|
||
| ## ⚠️ Disclaimer | ||
|
|
||
| This tool generates a first-draft document based on software. It is **not** legal advice and does not substitute for review by a licensed attorney. Review the generated document and verify all terms in your jurisdiction before signature. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # MoU Drafter Agent | ||
|
|
||
| ## Overview | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| This project solves the problem of drafting first-version Memorandum of Understanding (MoU) and vendor agreements from structured form inputs, incorporating 21 legal risk-management patterns. It implements a **single-flow** AgentKit pipeline that validates inputs, calls a Gemini/Claude model to generate clause JSON using prompt-injection defenses, and then deterministically compiles the clauses into a clean LaTeX document. A Next.js web application invokes the flow via Lamatic's SDK, renders warnings and pattern reports, and compiles the LaTeX source to PDF through the development-only sandboxed compile route. | ||
|
|
||
| --- | ||
|
|
||
| ## Purpose | ||
|
|
||
| The goal of this agent system is to provide a reliable contract-drafting endpoint that can produce structured LaTeX documents and parsed clause JSON from user inputs. After execution, the user receives a fully compiled PDF document with visual drafting notes (warnings), a direct download of the LaTeX source, and a link to open the draft in Overleaf for further human negotiation. | ||
|
|
||
| This agent centralizes contract generation and validation logic inside a Lamatic flow, allowing prompt modifications, model adjustments, and LaTeX template changes to be deployed via Lamatic Studio without altering client-side application code. | ||
|
|
||
| --- | ||
|
|
||
| ## Flows | ||
|
|
||
| ### `mou-drafter` | ||
|
|
||
| - **Flow ID / Env key mapping:** `mou-drafter` (configured via `MOU_DRAFTER_FLOW_ID`) | ||
|
|
||
| #### Trigger | ||
|
|
||
| - **Invocation type:** API request via a GraphQL trigger node (`API Request`). | ||
| - **Expected input shape:** See the Input Schema section in the kit's README. Contains 55 structured form inputs, including party details, fees, event dates, catering fields, cancellation terms, and risk toggles. | ||
|
|
||
| #### What it does | ||
|
|
||
| Step-by-step walkthrough of the node chain: | ||
|
|
||
| 1. `API Request` | ||
| - Receives the GraphQL/API payload from the Next.js app. | ||
| - Exposes incoming fields to downstream nodes. | ||
|
|
||
| 2. `Validate Input (codeNode)` | ||
| - Normalizes input fields (e.g. trimming strings, uppercase currency). | ||
| - Validates ranges, date formats, and conditional requirements. | ||
| - Expands payment and termination presets. | ||
| - Derives the governing law's `jurisdictionFamily` (US/Canada vs English Common Law). | ||
| - Formats deliverables into a text-based block string. | ||
| - Generates warnings for risky choices (e.g. lump-sum payments). | ||
|
|
||
| 3. `Clause Generator (LLMNode)` | ||
| - Generates structured JSON representation of the MoU clauses. | ||
| - Employs system prompt instruction to ignore prompt injections wrapped in `<<<USER_INPUT>>>`. | ||
| - Embeds machine-readable `% PATTERN:<anchor>` comments in each clause block. | ||
| - System Prompt: `mou-drafter_clause-generator_system.md` | ||
| - User Prompt: `mou-drafter_clause-generator_user.md` | ||
|
|
||
| 4. `Assemble LaTeX (codeNode)` | ||
| - Parses the model-generated JSON. | ||
| - LaTeX-escapes all user-supplied variables. | ||
| - Scrubs dangerous LaTeX macros (e.g. `\write18`, `\input`). | ||
| - Asserts expected pattern anchors and flags missing/unexpected clauses. | ||
| - Injects definitions, recitals, clauses, and signature blocks into the LaTeX template. | ||
|
|
||
| 5. `API Response` | ||
| - Returns the assembled LaTeX string, clause JSON, warnings, and pattern report to the caller. | ||
|
|
||
| #### When to use this flow | ||
|
|
||
| - Use when you need to generate a Memorandum of Understanding or vendor contract from form input. | ||
| - Use when you want to enforce legal risk-management patterns (e.g. payment milestone gating, mutual indemnity caps). | ||
|
|
||
| #### Output | ||
|
|
||
| - **Success response:** A JSON payload containing: | ||
| - `latex` (string): The complete compilable LaTeX document. | ||
| - `clauseJson` (object): The raw clause JSON generated by the LLM. | ||
| - `warnings` (array of strings): High-level warnings and pattern gating issues. | ||
| - `patternReport` (object): Report of found, expected, missing, and unexpected patterns. | ||
|
|
||
| --- | ||
|
|
||
| ## Guardrails | ||
|
|
||
| - **Prohibited tasks** | ||
| - Refuses contracts facilitating illegal activities, weapons, controlled substances, or surveillance tools. | ||
| - Refuses to draft contracts where a principal party is explicitly declared as a minor. | ||
| - Refuses prompts asking to draft "enforceability guarantees" or "loophole-proof" claims. | ||
| - **Input constraints** | ||
| - All free-text inputs are wrapped in `<<<USER_INPUT>>>` delimiters to defend against prompt injection. | ||
| - **Output constraints** | ||
| - The model must always output a JSON schema block containing a required disclaimer. | ||
| - Dangerous LaTeX primitives are stripped to prevent filesystem access and infinite compiling loops. | ||
|
|
||
| --- | ||
|
|
||
| ## Integration Reference | ||
|
|
||
| | Integration Type | Purpose | Required Config Key | | ||
| | -------------------- | -------------------------------------------------- | ---------------------------------------------------------- | | ||
| | Lamatic Flow Runtime | Execute deployed flow and access project resources | `LAMATIC_API_URL`, `LAMATIC_PROJECT_ID`, `LAMATIC_API_KEY` | | ||
| | MoU Drafter Flow ID | Select the deployed flow instance | `MOU_DRAFTER_FLOW_ID` | | ||
| | LLM Provider | Generate clauses based on system/user prompts | Configured in Lamatic Studio | | ||
|
|
||
| --- | ||
|
|
||
| ## Environment Setup | ||
|
|
||
| - `MOU_DRAFTER_FLOW_ID` — Deployed flow ID for the MoU Drafter flow. | ||
| - `LAMATIC_API_URL` — Base endpoint URL for Lamatic APIs. | ||
| - `LAMATIC_PROJECT_ID` — Lamatic project identifier. | ||
| - `LAMATIC_API_KEY` — API key for authentication. | ||
|
|
||
| --- | ||
|
|
||
| ## Quickstart | ||
|
|
||
| 1. Set up the `mou-drafter` flow in your Lamatic Studio account. | ||
| 2. Clone the repository and configure `.env.local` inside `kits/mou-drafter/apps` with your Lamatic credentials. | ||
| 3. Install dependencies and run the Next.js development server: | ||
| ```bash | ||
| npm install | ||
| npm run dev | ||
| ``` | ||
| 4. Access the web interface at `http://localhost:3000` to fill out the form and generate contracts. | ||
|
|
||
| --- | ||
|
|
||
| ## Common Failure Modes | ||
|
|
||
| | Symptom | Likely Cause | Fix | | ||
| | ----------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | | ||
| | GraphQL error: "Variable ... got invalid value" | Deliverables sent as a raw array instead of a JSON string | Ensure the server action passes `JSON.stringify(deliverables)` as a flat string parameter. | | ||
| | PDF preview is blank or compile hangs | A LaTeX syntax error occurred or the sandboxed compiler timed out | The compile route times out after 45 seconds. Check the LaTeX source tab for syntax issues. | | ||
| | Missing expected warnings | Output mapping in Response Node is incorrect | Verify that `warnings` and `patternReport` are properly mapped from the LaTeX assembly code node in Lamatic Studio. | | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| MOU_DRAFTER_FLOW_ID="your-flow-id-here" | ||
| LAMATIC_API_URL="your-lamatic-api-url" | ||
| LAMATIC_PROJECT_ID="your-lamatic-project-id" | ||
| LAMATIC_API_KEY="your-lamatic-api-key" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # local env files | ||
| .env | ||
| .env.* | ||
| !.env.example | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.