> For the complete documentation index, see [llms.txt](https://docs.karini.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.karini.ai/agentic-ai-workshops/ai-foundation-labs/agentic-rag-building-inspector.md).

# Agentic RAG \[Building Inspector]

**Lab time:** about 45 to 60 minutes

## The Problem

A city plans reviewer receives a floor plan for a new townhouse. Before it can be approved, someone has to read every room dimension, ceiling height, wall rating, and door size off the drawing, then check each one against hundreds of pages of building code: minimum ceiling heights, fire-resistance ratings between units, wind-load standards, termite clearances. It's slow, it depends on knowing exactly where in the code each rule lives, and a missed requirement can mean an unsafe building or a costly redesign after construction starts.

## What You Will Build

A Building Inspector Assistant: a copilot that knows the City of Miami building codes and can review floor plans against them. It will:

1. Answer building code questions with citations to the code sections it used
2. Read an uploaded floor plan image with a vision model and extract its rooms, dimensions, and specifications
3. Check the plan against the code and list potential violations with corrective recommendations
4. Suggest follow-up questions so reviewers can keep exploring

## What You Will Learn

* Build an agent that retrieves from a vector knowledge base, with query expansion to find code sections phrased differently from the question
* Extract structured data from drawings with a vision language model (VLM) in the Processing node
* Compare models side by side and pick a primary and fallback model
* Deploy the agent as a copilot with citations, follow-up questions, feedback, and traces

## Build Order

Build the agent prompt first, then the recipe, and the copilot last. A recipe can only use prompts that are already published.

| Step | You create                                | Contains                                        |
| ---- | ----------------------------------------- | ----------------------------------------------- |
| 1    | Agent: Building Inspector prompt          | 1 tool: Building code knowledgebase             |
| 2    | Workflow recipe: Building Inspector Agent | Chat/Draft, Processing (VLM), Start, Agent, End |
| 3    | Copilot: Building Inspector Assistant     | Chat page for end users                         |
| 4    | End-to-end test                           | Code Q\&A and floor plan analysis               |

## Before You Start

* Access to the Karini AI platform
* The **Building code dataset**, pre-created by your administrator
* The **Building Inspector** prompt template, available in Prompt Playground
* The floor plan images for the analysis test, downloadable from the [shared folder](https://app.box.com/s/di135bh4vdqhmgzniuxpb99xo07zylmc)

## Words You Will See

* **Agentic RAG:** retrieval-augmented generation where an agent decides what to search for and how to use the results, rather than running one fixed search
* **Prompt template:** a ready-made prompt stored in Karini. You load it instead of typing it.
* **Tool:** something an agent can call, such as a knowledge base
* **Query expansion:** rewriting a question into several related searches so the knowledge base finds relevant passages even when the wording differs
* **VLM:** vision language model, a model that reads images such as floor plans and describes what it sees
* **Recipe:** the workflow that connects everything on a canvas
* **Copilot:** the chat assistant end users open to use the recipe
* **Publish:** saves a version that recipes can use. Saved but unpublished changes are not used.

## Step 1: Create the Building Inspector Agent Prompt

### 1.1 Create the prompt

1. Navigate to Prompt Playground.
2. Click **Add New** in the top corner and select Task as **Agent**.
3. Click **Prompt templates** and select the **Building Inspector** template.
4. Once the template is added, scroll up and increase **Max State Updates** from **3** to **20** for complex reasoning.
5. In the **Agent Input** box, add this test query:

```
What is the minimum ceiling height for basement?
```

6. Scroll up and rename your prompt with your initials.
7. Save the prompt. You'll return to Prompt Playground; select your working prompt.

Save your changes before you navigate away to add tools, or they are lost.

### 1.2 Add the tool: Building code knowledgebase

1. Open the **Tools** tab, click **Add New**, and fill in:

| Field                         | Value                       |
| ----------------------------- | --------------------------- |
| Name                          | Building code knowledgebase |
| Description                   | Copy the text below exactly |
| Type                          | Dataset                     |
| Dataset                       | Building code dataset       |
| Prompt context                | Use Embedding chunks        |
| Top-K                         | 4                           |
| Advanced query reconstruction | On, Query expansion         |

Description text:

```
This tool provides access to comprehensive information about the city of Miami building codes including codes, descriptions, measurements, dimensions, rules, regulations, causes, exemptions for the building plans. It requires the agent to input the natural language question to obtain relevant information.
```

2. Save the tool.

### 1.3 Test & Compare

1. In the **Test & Compare** tab, select different models from the dropdown to test the prompt. Compare Claude Sonnet 3.7, Claude Sonnet 3.5 v2, and Anthropic Claude Sonnet 4.
2. Test and compare the agent responses with the selected models.
3. Click **Select as best answer** on **Claude Sonnet 3.5 v2** to set it as the Primary Model.
4. Optional: click **Select as best answer** on another output to assign a Fallback Model.
5. Click **Save prompt run** in the right corner.
6. **Save** and **publish** the prompt.

Only published prompts are visible in the recipe.

Refer to the following video to create and test the agent prompt.

{% embed url="<https://www.loom.com/share/6ca5ff7dd2cf4a9dbc10d7517f026190?sid=99ec3bef-9e11-4c9a-8f5d-c032d5d2d82a>" %}

## Step 2: Create a Workflow Recipe

### 2.1 Create the recipe

1. Navigate to **Recipes** on the left side.
2. Click **Add New** in the top right corner and configure:

| Field   | Value                    |
| ------- | ------------------------ |
| Name    | Building Inspector Agent |
| Type    | Workflow                 |
| Runtime | Karini                   |

### 2.2 Add and connect the nodes

Drag each element onto the recipe canvas, then click it to configure it.

| # | Element    | Settings                                                                                                                                            |
| - | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| 1 | Chat/Draft | Retain 2 messages of conversation history. Generate follow-up questions on. Citations on                                                            |
| 2 | Processing | OCR on, VLM. VLM Prompt: paste the prompt below                                                                                                     |
| 3 | Start      | None                                                                                                                                                |
| 4 | Agent      | Prompt = the Building Inspector prompt you saved in Step 1. State settings: Document Cache on (Type Retrieve Documents), Messages on (All Messages) |
| 5 | End        | None                                                                                                                                                |

Connect them in a straight line: Chat/Draft → Processing → Start → Agent → End.

VLM Prompt for the Processing node:

```
# Optimized Floor Plan Data Extraction Prompt

## Instruction: 
Analyze this floor plan image systematically and extract all visible information. Follow this exact sequence:

### 1. Text Extraction (Read Everything Visible):
**A. Title Block & Project Information:**
Project name, drawing title, sheet numbers
Scale information, revision dates
Professional stamps and signatures

**B. Area Calculations & Measurements:**
All room dimensions (length x width)
Square footage/square meter values
Total building area calculations
Coverage percentages and ratios

**C. Room Labels & Designations:**
Every room name exactly as written
Room codes or numbers
Functional designations (bedroom, bathroom, kitchen, etc.)

**D. Technical Specifications:**
Door sizes and types
Window dimensions and quantities
Wall thicknesses
Structural notes and building codes
Material specifications

### 2. Visual Description (Describe What You See):
**A. Overall Layout:**
Number of floors shown
General building shape and orientation
Relationship between different views (plan, elevation, section)

**B. Room-by-Room Description:**
Start from main entrance
Describe each room's location, size, and adjacent spaces
Note built-in features, fixtures, appliances
Identify circulation paths and connections

**C. Architectural Elements:**
Wall types and configurations
Door locations and swing directions
Window placements and orientations
Stairs, if present
Utility connections (plumbing, electrical symbols)

**D. Legend and Symbols:**
Explain any hatching patterns, line types
Describe symbols used for fixtures, appliances
Note any color coding or special markings

### 3. Data Organization & Analysis:
**A. Building Summary:**
Building type and function
Total number of rooms
Total floor area
Number of bedrooms, bathrooms, etc.

**B. Compliance & Technical Notes:**
Building codes referenced
Setback requirements
Coverage ratios
Professional certifications noted

**C. Design Assessment:**
Functional layout efficiency
Space relationships and flow
Any apparent design issues or missing information

## Extraction Guidelines:
**Read text exactly as written** - don't interpret or correct spelling
**Include all numbers** with their units (sq ft, sq m, feet, meters)
**List dimensions systematically** - room by room
**Note incomplete information** - mark anything unclear or missing
**Separate facts from interpretation** - what you see vs. what you infer
**Use consistent formatting** - bullet points for lists, tables for dimensions
**Check all corners** of the image for text or details

## Output Format:
Use clear headings, bullet points, and tables. Present numerical data in organized lists. Flag any text that's unclear or partially visible.
```

### 2.3 Recipe settings, publish, and test

1. On the right side, set **Number of state updates** to a higher value, such as **75**.
2. Save and Publish the recipe. By default, the V1 version is deployed once it is published.
3. For later versions, click **Actions** and select **Deploy**.
4. Test the recipe with these questions:

```
What is the minimum ceiling height for basement?
```

```
For townhouses, what fire-resistance rating is required for the wall assembly separating units?
```

Refer to the following video to create and test the recipe.

{% embed url="<https://www.loom.com/share/ae04865ab45b429ca586f49b9d9718b6?sid=a20fca70-9727-451a-b360-3957b29629c8>" %}

## Step 3: Create Your Building Inspector Copilot

Make sure you have **published** the recipe before you start this step.

1. On the recipe page, click **Actions** in the top right corner and select **Create Copilot**.
2. On the Copilots page, click **Add new** and fill in:

| Field          | Value                                                                                                                                                                                                                                                                                                                                     |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Copilot name   | Building Inspector Assistant                                                                                                                                                                                                                                                                                                              |
| Description    | Agentic Building Inspector is an intelligent virtual assistant designed to help city officials, architects, and builders ensure compliance with the city of Miami's building codes. It reviews floor plans and blueprints to identify potential violations, ensuring that all construction projects meet safety and regulatory standards. |
| Seed questions | See the list below                                                                                                                                                                                                                                                                                                                        |
| Error message  | Apologies for the error, please try again                                                                                                                                                                                                                                                                                                 |
| Feedback       | Thumbs up and thumbs down on, custom feedback on                                                                                                                                                                                                                                                                                          |
| Show traces    | On                                                                                                                                                                                                                                                                                                                                        |

Seed questions:

* For townhouses, what fire-resistance rating is required for the wall assembly separating units?
* What are the five types of loads that buildings must be constructed to safely support according to R301.1?
* What is the minimum clearance required between exterior wall coverings and final earth grade for termite inspection purposes?
* A contractor is building a house in an area with a 120 mph ultimate design wind speed. What specific design standards must they follow?

3. Click **Save**.

Open the copilot in one of two ways:

* **From the saved copilot:** click the **<** icon on the right panel, then click **Visit Copilot**
* **From the left menu:** open **Copilots** in the vertical menu

## Step 4: Test Your Building Inspector Assistant

Open **Building Inspector Assistant** from Copilots.

### 4.1 Building code Q\&A

Ask any of the seed questions. Each answer should cite the code sections it used.

### 4.2 Floor plan analysis

1. Download the floor plan images from the [shared folder](https://app.box.com/s/di135bh4vdqhmgzniuxpb99xo07zylmc).
2. Click upload and select one of the downloaded images.
3. Ask: **Analyze the floor plan.**
4. Then ask: **What are potential violations in the plan against city codes?**

Wait a few moments while the system processes the query. Response times vary with the complexity of the question.

Once the response is generated, you'll see:

| Element             | What it does                                                        |
| ------------------- | ------------------------------------------------------------------- |
| Answer              | The system's response, as text or a table                           |
| Citations           | The code sources referenced, so you can open the original documents |
| Follow-up questions | Suggested related questions to keep exploring                       |
| Trace               | The tools invoked, with their inputs and outputs                    |
| Prompt Lens         | The underlying prompt and response details                          |
| Copy                | Copies the answer for reuse                                         |
| Feedback            | Thumbs up or thumbs down on the response                            |

Refer to the following video for copilot functionality.

{% embed url="<https://www.loom.com/share/7e43dc18e1654e34809c7385adf1a935?sid=7f57e9a5-a316-4f3c-a55c-fce55603de37>" %}
