Munich Hacking Legal Challenge — an AI agent platform for the BMW Group legal department. Lex coordinates specialized AI agents (contract review, compliance, research, risk) and returns structured, traceable, source-cited deliverables to human lawyers.
Built on the Pi coding-agent runtime and adapted for BMW legal workflows.
# One-line install (clones into ~/.local/share/lex)
curl -fsSL https://raw.githubusercontent.com/itsamirkhon/lex/main/install.sh | bash
# OR via npm
npm install -g bmw-lexlex auth # paste your OpenRouter API key (sk-or-v1-...)Get a key at openrouter.ai/keys. Lex uses Claude Sonnet 4.5 by default.
lex # interactive REPL
lex contract-review samples/acme-supplier-nda-draft.md --jurisdiction de
lex compliance-check "Acme GmbH" --check-type sanctions,lksg
lex legal-research "force majeure pandemic" --jurisdiction de,uk
lex-web # web UI on http://localhost:3000Name conflict on Linux? A system tool
/usr/bin/lex(a lexer generator) may shadow ours. Fix withexport PATH="$HOME/.local/bin:$PATH"or use thebmw-lexalias.
A corporate legal department handles thousands of recurring tasks: reviewing supplier contracts, checking entities against sanctions lists, researching jurisdictional differences, drafting from templates. Lex automates the decomposable parts while keeping a human lawyer in the loop for judgment calls.
Every workflow:
- Classifies the request (contract type, jurisdiction, urgency)
- Plans the approach in
outputs/.plans/<slug>.md - Delegates subtasks to specialist agents in parallel
- Synthesizes findings into a single deliverable
- QA-checks all citations and jurisdiction coverage
- Gates on human review before final delivery
- Returns the artifact + a
.provenance.mdsidecar with full audit trail
┌─────────────────────────────────────────────────────────────┐
│ CLI / Web UI │
│ bin/lex.js • bin/lex-web.js (Next.js on :3000) │
└────────────────────────────┬────────────────────────────────┘
│
┌──────────────▼───────────────┐
│ Lex Orchestrator │
│ .lex/SYSTEM.md │
│ Pi runtime + extensions │
└──────────────┬───────────────┘
│
┌─────────────────────┼─────────────────────┐
│ │ │
┌───▼────┐ ┌──────▼──────┐ ┌──────▼─────┐
│Workflow│ │ Subagents │ │ Tools │
│Prompts │ │ .lex/agents│ │ extensions/│
└────────┘ └─────────────┘ └────────────┘
File-based handoff via outputs/.plans, outputs/.drafts
| Agent | Role | Output |
|---|---|---|
contract-agent |
Clause-by-clause review, redlines, BMW-template comparison | contract-analysis.md |
compliance-agent |
OFAC/EU sanctions, LkSG, ESG, GDPR checks | compliance-report.md |
research-agent |
Statute & case law (DE / US / UK / FR / EU) | legal-research.md |
risk-agent |
Risk register with CRITICAL/HIGH/MEDIUM/LOW grading | risk-assessment.md |
negotiation-agent |
BATNA, position tiers (preferred → walk-away), redlines | negotiation-brief.md |
knowledge-agent |
Internal precedent / template / memo search | kb-results.md |
qa-agent |
Citation verification, jurisdiction completeness | qa-report.md |
| Command | Description |
|---|---|
/contract-review <file> [--jurisdiction <de|us|uk|fr>] |
Risk-grade a contract clause-by-clause |
/compliance-check <topic> [--check-type sanctions|lksg|esg|gdpr|all] |
Multi-framework compliance assessment |
/legal-research <question> [--jurisdiction <de|us|uk|fr|all>] |
Cross-jurisdiction statutory + case law research |
/risk-assessment <file-or-topic> |
Comprehensive legal risk register |
/contract-draft <nda|supply|service> [--jurisdiction <de>] |
Draft from BMW standard templates |
Registered as Pi tools, available to all agents:
legal_web_search— pre-filtered forgesetze-im-internet.de,eur-lex.europa.eu,bailii.org, etc.sanctions_check— searches OFAC SDN, EU Consolidated, UN Security Council listseurlex_search— EU regulations, directives, decisionsdocument_parse— PDF/DOCX → plaintext for contract analysisdocument_upload— copies files into a matter workspace
.
├── bin/ # CLI entry points (lex, lex-web)
├── dist/ # Compiled TypeScript (cli, paths, runtime, setup)
├── extensions/
│ ├── legal-tools.ts # Pi extension entry
│ └── legal-tools/ # Sub-modules (search, document, matter, header)
├── prompts/ # Workflow templates (slash commands)
│ ├── contract-review.md
│ ├── compliance-check.md
│ ├── legal-research.md
│ ├── risk-assessment.md
│ └── contract-draft.md
├── .lex/
│ ├── SYSTEM.md # Orchestrator system prompt
│ ├── settings.json # Pi packages config
│ └── agents/ # 7 specialized subagent definitions
├── knowledge-base/ # BMW internal legal corpus (mock)
│ ├── policies/ # Primary BMW policy sources (Code of Conduct)
│ ├── templates/ # Standard NDA, supply, service agreements
│ ├── precedents/ # Approved clause language
│ └── memos/ # LkSG checklist, sanctions procedure
├── samples/ # Demo contracts for testing
├── web/ # Next.js 15 web UI
│ └── app/
│ ├── page.tsx # Main UI (slash-command input + artifact viewer)
│ └── api/ # task / status / upload / artifacts routes
├── scripts/
│ └── patch-embedded-pi.mjs # Runtime patches to embedded Pi (tool name filter, etc.)
├── outputs/ # Generated at runtime
│ ├── .plans/<slug>.md # Matter plans (orchestrator scratch)
│ ├── .drafts/<slug>-*.md # Subagent intermediate artifacts
│ └── matters/<id>/ # Final deliverables + provenance
├── install.sh # One-line installer
└── package.json
Every final deliverable is paired with a .provenance.md sidecar:
- Matter ID: bmw-acme-nda-review
- Date: 2026-04-25
- Jurisdiction(s): DE
- Governing Law: BGB / GeschGehG
- Task Type: contract-review
- Agents used: contract-agent, risk-agent, knowledge-agent, qa-agent
- Sources consulted: 14 | Sources verified: 12
- QA result: PASS WITH NOTES
- QA MAJOR findings: Liability cap §8.2 references unverified market norm
- Human review gate: APPROVED
- Privilege status: PRIVILEGEDThis enables full audit trails for regulatory inquiries, BAFA reporting, and internal governance.
lex contract-review samples/acme-supplier-nda-draft.md --jurisdiction deThe sample NDA contains 5 intentional defects. Expected output:
- Clause-by-clause risk table
- 2 HIGH risks flagged (unlimited liability, wrong governing law)
- Negotiation positions per contested clause
- Comparison against
knowledge-base/templates/bmw-nda-standard.md
lex compliance-check "supply chain partnership XYZ Corp China" --check-type sanctions,lksg- OFAC SDN / EU / UN sanctions screening
- LkSG due-diligence checklist (10+ items)
- PASS / FAIL / REQUIRES_REVIEW per framework
lex legal-research "force majeure pandemic clause enforceability" --jurisdiction de,ukComparative table with BGH and English High Court citations. All URLs verified by qa-agent.
lex-web
# open http://localhost:3000Drag-and-drop contract upload, live agent activity log, artifact viewer with markdown rendering, provenance panel.
- Runtime: Pi coding-agent (
@mariozechner/pi-coding-agent) on Node.js 20+ - LLM: Claude Sonnet 4.5 via OpenRouter (configurable to other providers)
- Extension language: TypeScript (loaded via
tsxat runtime) - Web UI: Next.js 15, React 19, react-markdown
- Storage: File-based (no database) —
outputs/,~/.lex/agent/ - Tool framework: TypeBox JSON Schema for tool parameters
For legal work, the audit trail of intermediate artifacts is a feature, not a workaround. Plans, drafts, QA reports, and provenance sidecars all sit on disk in human-readable Markdown — making the system fully auditable, resumable across sessions, and easy to inspect without a database.
git clone https://github.com/itsamirkhon/lex.git
cd lex
npm install
lex --version
# Run from source
node bin/lex.js --help- Create
.lex/agents/your-agent.mdwith YAML frontmatter (name,description,tools,output) - Reference it in workflow prompts under
prompts/ - Restart Lex — it auto-discovers agents at startup
Edit extensions/legal-tools/your-tool.ts, register via pi.registerTool(), and re-export from
extensions/legal-tools.ts.
- Real Otto-Schmidt / Beck-Online integration — currently uses targeted web search as fallback
- Vector DB for KB search —
knowledge-agentcurrently uses grep, fine for MVP - MCP wrapping — tools are inline Pi extensions; MCP server form would enable cross-agent reuse
- Authentication — web UI runs on localhost only; production needs SSO + role-based access
- DOCX redline output — currently emits Markdown; lawyers paste into Word
MIT — built for the Munich Hacking Legal Challenge by BMW Group.
- Repository: https://github.com/itsamirkhon/lex
- Pi framework: https://github.com/mariozechner/pi
- Munich Hacking Legal: https://munich-hacking-legal.bmw.com (challenge brief)