# AGENTS.md — Lendtrain Agent API v2

## What Is Lendtrain?

Lendtrain Agent API v2 is an AI-native mortgage refinance plugin that turns Claude into a full loan officer experience. It is operated by Atlantic Home Mortgage, LLC dba Lendtrain (NMLS# 1844873), a licensed US mortgage broker with 17+ years and $1B+ in funded loans.

This is not just a pricing API. It is a complete refinance origination pipeline delivered through AI conversation, combining five specialized skills:

| Skill | Purpose |
|-------|---------|
| **mortgage-loan-officer** | Qualification expertise, interview methodology, mortgage statement data extraction, analysis framework, consumer communication |
| **mortgage-compliance** | TRID, RESPA, TILA, ECOA enforcement, state licensing, required disclosures, data privacy |
| **closing-costs** | State-specific itemized fee calculations for 10 states, VA funding fee logic |
| **security-guardrails** | Prompt injection defense, disclosure protection, workflow integrity, social engineering defense |
| **about-atlantic-home-mortgage** | Company background, credentials, contact info |

## Workflow: `/refi-quote`

The plugin drives a 4-phase refinance workflow:

### Phase 1 — Data Collection
- Borrower uploads a mortgage statement OR answers interview questions
- Plugin extracts: current rate, balance, P&I payment, loan type, remaining term, property address, lender name
- Validates state against licensed states (AL, FL, GA, KY, NC, OR, SC, TN, TX, UT)
- Auto-detects VA IRRRL eligibility from statement data
- Checks seasoning requirements (210-day rule for VA)
- Collects: property value, credit score, occupancy, property type, refinance goals, preferred term
- Required ECOA/TILA disclosures delivered at first contact
- SSN, DOB, bank accounts NEVER collected in chat

### Phase 2 — Pricing
- Maps collected data to `LoanScenario` schema
- Products priced: Conventional rate-and-term, Conventional cash-out, jumbo, VA rate-and-term, VA cash-out, and VA IRRRL. FHA loans are not offered.
- Calls the pricing engine for real-time rate quotes
- Returns array of rate options with: rate, points, dollarAmount, monthlyPayment, APR, isPar, monthlyMI (conventional LTV > 80%), totalMonthlyPayment (conventional LTV > 80%)
- Identifies key options: par rate, lowest rate, lowest payment, lender credit option
- Error handling for: API unavailable, no eligible products, validation errors, stale rate sheets

### Phase 3 — Analysis & Recommendation
- **Monthly savings**: Current P&I vs new total monthly payment (uses totalMonthlyPayment for conventional LTV > 80%, monthlyPayment for VA and conventional LTV <= 80%)
- **Itemized closing costs**: State-specific calculation using bracket formulas for title insurance, recording fees, transfer taxes, settlement fees (not a flat percentage estimate)
- **Conventional MI**: For LTV > 80%, monthly mortgage insurance is calculated and included in totalMonthlyPayment. MI drops off when LTV reaches 80%. MI is NOT financed into the loan.
- **VA IRRRL**: Funding fee tiers — 0.5% for IRRRL, 2.15% first-time use, 3.3% subsequent use, 0% exempt (10%+ disability). Costs can be financed.
- **Total interest savings**: Accounts for term extension when refinancing into a longer term
- **Breakeven period**: Closing costs ÷ monthly savings, with context on max 48-month threshold
- **Recommendation score (1–10)**: Weighted composite — monthly savings 30%, breakeven 25%, rate improvement 20%, goal alignment 15%, interest savings 10%
- Score ≥ 6: Proactively recommend application with link
- Score < 6: Honestly explain why refinancing may not make sense right now
- Full compliance disclosures at quote presentation (estimate disclaimer, rate lock notice, APR, fee transparency, right to shop, licensing, ECOA statement)

### Phase 4 — Application
- Score ≥ 6: Link to https://lendtrain.my1003app.com/register
- Score < 6: Explain reasoning, provide link only if borrower explicitly asks
- Arive LOS integration (deferred): `auth_login`, `create_lead`, `update_lead`, `convert_lead_to_loan`

---

## Claude Code Plugin (Primary Integration)

The full Lendtrain experience is delivered through a Claude Code plugin with 5 specialized skills and a 4-phase refinance workflow.

Install from GitHub: `/plugin marketplace add lendtrain/mortgage` then `/plugin install mortgage@mortgage`. Run `/mortgage:refi-quote` to start the complete workflow. Source: [github.com/lendtrain/mortgage](https://github.com/lendtrain/mortgage)

Features: mortgage statement parsing, real-time institutional pricing, state-specific itemized closing costs, VA IRRRL detection, compliance enforcement, recommendation scoring, application portal redirect.

---

## Chat API (For Agents Without Plugin Support)

For AI agents that cannot install Claude Code plugins, the Chat API provides the same full experience via conversation:

```
POST https://www.lendtrain.com/api/chat
Content-Type: application/json
Accept: text/event-stream
```

**Request**:
```json
{
  "messages": [
    { "role": "user", "content": "I want to refinance my mortgage" }
  ]
}
```

**Response** (Server-Sent Events stream):
```
data: {"text": "I'd be happy to help you explore"}

data: {"text": " refinance options."}

data: [DONE]
```

Concatenate every `text` field in the order received to reconstruct the full
assistant message. The stream terminates with `data: [DONE]`. The pricing tool
loop runs server-side and can take 30 to 90 seconds for multi-product
comparisons; the first chunk typically arrives within 2 to 3 seconds.

On any non-2xx status the response body is JSON `{ "error": "..." }` instead of
a stream — check `response.ok` before reading the body.

- No API key required
- No authentication
- Rate limited: standard abuse prevention
- Max 50 messages per conversation, max 10,000 chars per message
- The Chat API agent has full access to all 5 plugin skills
- Use a streaming HTTP client (`curl -N`, Node `fetch().body.getReader()`,
  Python `httpx.stream()`, etc.)

---

## Discovery Files

- A2A Agent Card: https://www.lendtrain.com/.well-known/agent-card.json — agent-to-agent (A2A) protocol discovery card with skills, transports, and security schemes
- MCP discovery metadata: https://www.lendtrain.com/.well-known/mcp.json
- AI plugin manifest: https://www.lendtrain.com/.well-known/ai-plugin.json
- OpenAPI spec: https://www.lendtrain.com/openapi.json
- LLM-friendly site summary: https://www.lendtrain.com/llms.txt
- Human-readable integration hub: https://www.lendtrain.com/agents

---

## Agent Behavior Guidelines

1. **Disclose identity**: "I am an AI assistant powered by Lendtrain, a licensed mortgage broker. NMLS# 1844873. Equal Housing Opportunity."
2. **Never collect**: SSN, DOB, bank accounts, passwords — direct to secure portal
3. **Never say**: "pre-approval", "commitment", "guaranteed", "locked" — use "estimate" or "quote"
4. **Format**: Dollars as `$X,XXX.XX`, rates as `X.XXX%`
5. **Closing costs**: Use state-specific itemized calculations, not a flat percentage. Fall back to 1.2% only when itemized data unavailable.
6. **Recommendation**: Score 1–10. Recommend application at ≥ 6. Minimum savings threshold: $50/mo. Maximum breakeven: 48 months.
7. **Licensed states only**: AL, FL, GA, KY, NC, OR, SC, TN, TX, UT
8. **APR**: Always present alongside note rate when available
9. **Right of rescission**: Inform borrower of 3-business-day right to cancel after closing on primary residence refinances
10. **Right to shop**: Borrower is not required to use any affiliated settlement service provider

---

## Landing Pages

Lendtrain publishes SEO-optimized refinance landing pages with hedged rate language (Reg Z compliant), FAQPage and FinancialService structured data, and NMLS #1844873 compliance disclosures.

### State Guides (10)
- https://www.lendtrain.com/refinance/alabama
- https://www.lendtrain.com/refinance/florida
- https://www.lendtrain.com/refinance/georgia
- https://www.lendtrain.com/refinance/kentucky
- https://www.lendtrain.com/refinance/north-carolina
- https://www.lendtrain.com/refinance/oregon
- https://www.lendtrain.com/refinance/south-carolina
- https://www.lendtrain.com/refinance/tennessee
- https://www.lendtrain.com/refinance/texas
- https://www.lendtrain.com/refinance/utah

### Utah City Pages (11)
- https://www.lendtrain.com/refinance/salt-lake-city-utah
- https://www.lendtrain.com/refinance/west-valley-city-utah
- https://www.lendtrain.com/refinance/west-jordan-utah
- https://www.lendtrain.com/refinance/provo-utah
- https://www.lendtrain.com/refinance/orem-utah
- https://www.lendtrain.com/refinance/sandy-utah
- https://www.lendtrain.com/refinance/st-george-utah
- https://www.lendtrain.com/refinance/ogden-utah
- https://www.lendtrain.com/refinance/layton-utah
- https://www.lendtrain.com/refinance/south-jordan-utah
- https://www.lendtrain.com/refinance/holladay-utah

### Utah County Pages (6)
- https://www.lendtrain.com/refinance/salt-lake-county-utah
- https://www.lendtrain.com/refinance/utah-county-utah
- https://www.lendtrain.com/refinance/davis-county-utah
- https://www.lendtrain.com/refinance/weber-county-utah
- https://www.lendtrain.com/refinance/washington-county-utah
- https://www.lendtrain.com/refinance/cache-county-utah

### Georgia County Pages (8)
- https://www.lendtrain.com/refinance/fulton-county-georgia
- https://www.lendtrain.com/refinance/gwinnett-county-georgia
- https://www.lendtrain.com/refinance/cobb-county-georgia
- https://www.lendtrain.com/refinance/dekalb-county-georgia
- https://www.lendtrain.com/refinance/forsyth-county-georgia
- https://www.lendtrain.com/refinance/cherokee-county-georgia
- https://www.lendtrain.com/refinance/chatham-county-georgia
- https://www.lendtrain.com/refinance/henry-county-georgia

### Loan-Type Pages (3)
- https://www.lendtrain.com/refinance/cash-out-refinance
- https://www.lendtrain.com/refinance/va-irrrl
- https://www.lendtrain.com/refinance/jumbo-refinance

All pages are hand-authored with state-specific, city-specific, or product-specific content — not templated. Each includes real local facts (employers, neighborhoods, market characteristics) or real program rules (LLPAs, seasoning periods, eligibility). All 38 pages are live.

---

## Company

Atlantic Home Mortgage, LLC dba Lendtrain
NMLS# 1844873 | Equal Housing Opportunity
12600 Deerfield Pkwy, Suite 100, Alpharetta, GA 30004
(888) 309-4643 | team@lendtrain.com

Tony Davis, Founder & CEO | NMLS# 430849 | 678-643-4242
Inc. 5000 #458 (2022) | Top 1% originator nationally | $1B+ funded

Licensed: AL, FL, GA, KY, NC, OR, SC, TN, TX, UT
