# Analyzing areas of influence with AI Agents through user-driven isoline generation

Understanding the true reach and impact of a location is fundamental to spatial analysis. Whether you're assessing school safety zones, retail catchment areas, or service accessibility, the ability to define precise areas of influence—based on real-world travel conditions—is essential.

In this tutorial, we'll create an AI Agent that generates custom isolines and analyzes spatial data within those zones through natural conversation. Using Workflows, we’ll build an MCP Tool that dynamically generates isolines based on user input, enabling end-users to quickly answer questions like *“What’s within 10 minutes walking distance?”* or *“Which incidents fall within our service area?”*

{% stepper %}
{% step %}

#### **Create an MCP Tool (Workflow)**

The first step is to create a Workflow that acts as an MCP Tool for our Agent, giving it the ability to automatically generate isolines based on parameters users provide in natural language.

**Create the Workflow**

1. Open CARTO and click on <\<Create Workflow>> inside the Workflows section.
2. Select **CARTO Data Warehouse** as the connection.
3. Name the workflow: `Dynamic Isoline Generation`

**Add custom variables**

We will configure the variables that the Agent will be able to pass to this Workflow. The values for these variables will come from the user’s request. To do this, click on ***Variables*** in the top-right corner and add the following:

* **`lat`** (Number): Latitude coordinate of the center point for the isoline. Default value: `51.4529913`
* **`lng`** (Number): Longitude coordinate of the center point for the isoline. Default value: `-2.579476`
* **`mode`** (String): Travel mode for the isoline generation. Options: `walk`, `car`, `bike`, `public_transport`. Default value: `walk`
* **`range_value`** (Number): Time in seconds or distance in kilometers for the isoline. Default value: `500`
* **`range_type`** (String): Type of range measurement. Options: `time`, `distance`. Default value: `time`

Make sure each variable is enabled for **MCP Tool** scope so that the Agent can set them.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FOuEH1mFkAlS8msjChSMQ%2FScreenshot%202025-11-18%20at%2012.30.41.png?alt=media&#x26;token=80b527ce-e64c-4524-988b-154d72138202" alt=""><figcaption></figcaption></figure>

**Build the Workflow components**

Our workflow is simple and consists of three components:

1. **Retrieve user input location**: Add a ***Custom SQL Select*** component with the following query to create a point geometry from the user-provided coordinates:

```sql
SELECT ST_GEOGPOINT(@lng, @lat) as geom
```

> **Note:** `ST_GEOGPOINT` always takes input as `longitude, latitude`.

2. **Create isoline based on user input**: Add a second ***Custom SQL Select*** component and connect it to the previous component. Use the following query to generate the isoline replacing the api\_base\_url and the lds\_token that can be obtained in the Developers section of the CARTO Workspace:

```sql
  
SELECT `carto-un`.carto.ISOLINE(
    'api_base_url',
     'lds_token',
     geom,
     @mode,
     CAST(ROUND(@range_value) AS INT64),
     @range_type,
     NULL
     ) as geom
FROM `$a`;
```

This component uses [CARTO's ISOLINE function](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/lds#isoline) from our [Analytics Toolbox for BigQuery](https://docs.carto.com/data-and-analysis/analytics-toolbox-for-bigquery/sql-reference/lds) to generate the travel-time or distance polygon based on the center point and user-defined parameters (mode, range value, and range type).&#x20;

3. **Define MCP Tool Output**: Add an ***MCP Tool Output*** component and connect it to the isoline generation component. Set the *Type* to `Sync` since isoline generation is typically fast enough to return results immediately.

Your workflow should look like the screenshot below, with three connected components flowing from left to right:

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2F3ZoCAe3CCaDWvwa6RaQu%2FScreenshot%202025-11-18%20at%2018.09.18.png?alt=media&#x26;token=598c3647-5f04-4d75-8221-abf0f9fbade5" alt=""><figcaption></figcaption></figure>

**Enable the Workflow as MCP Tool**

The last step is to enable the Workflow as an [MCP Tool](https://academy.carto.com/agentic-gis/carto-mcp-server/workflows-as-mcp-tools). Click the three dots in the top-right section and select ***MCP Tool***. Then, fill in the context the Agents will have when this tool is available to them: this includes a description of what the tool does, and what are its inputs and output.

{% tabs %}
{% tab title="Tool description" %}
{% code overflow="wrap" %}

```
Creates an isoline polygon around a given point (lat/lng) and returns its geometry.
```

{% endcode %}
{% endtab %}

{% tab title="Inputs" %}

* `lat`

```
Latitude coordinate of the center point in decimal degrees.
```

* `lng`

```
Longitude coordinate of the center point in decimal degrees.
```

* `mode`

```
Travel mode for isoline calculation. Valid values: 'walk', 'car', 'bike', 'public_transport'.
```

* `range_value`

```
Numeric value representing time in seconds (when range_type='time') or distance in kilometers (when range_type='distance').
```

* `range_type`

```
Type of range measurement. Valid values: 'time' or 'distance'.
```

{% endtab %}

{% tab title="Output" %}
{% code overflow="wrap" %}

```
Polygon geometry representing the isoline area reachable from the center point within the specified constraints.
```

{% endcode %}
{% endtab %}
{% endtabs %}

Once you configure the tool description, inputs and output, you can click on the bottom <<**Enable as MCP Tool>>** to expose your Workflows as part of [CARTO MCP Server](https://docs.carto.com/carto-mcp-server/carto-mcp-server).&#x20;

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2Fn94T7iPZkraxLR4b7E32%2FScreenshot%202025-11-18%20at%2018.33.20.png?alt=media&#x26;token=b770f289-3ecd-42ff-a8f3-96e0803f7378" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Create your interactive analysis map

Now, we're looking to create an AI Agent in CARTO. To start this process, we'll begin by creating an interactive map. To do so, go the Maps section and click on <\<Create Map>>.&#x20;

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FwrSCEX0QIIjhq8qdlQ2t%2FScreenshot%202025-11-20%20at%2020.23.51.png?alt=media&#x26;token=ac4288d6-6b8b-402f-8b81-a0856762a5e7" alt=""><figcaption></figcaption></figure>

Once you're inside your new Builder map, do the following:&#x20;

* **Give your map a title:**  `Area of Influence Analysis`     &#x20;
* **Add traffic crash data**: Create a new source using `bristol_traffic_accidents` dataset available in *CARTO Data Warehouse > demo data> demo\_tables*.&#x20;
* **Change the basemap**: Click on the *Basemap* selector in the bottom-left corner and select `CARTO Dark Matter` for better contrast with the data visualization.
* **Style your crash layer**:&#x20;
  * Set *Radius* to `6` pixels
  * Set *Fill color* to `#ffbccd` with `80%` opacity
  * Set *Stroke color* to `#ef5299` with `10%` opacity and *Stroke Weight* of `8` pixels
  * These colors will provide good contrast with a dark basemap, which we'll configure later
  * Name this layer `Traffic Crashes`
* **Add click tooltips**: Click on the *Interactions* tab and enable *Hover interactions* for the Traffic Crashes layer. Add relevant columns (such as accident type, severity, date) and customize the tooltip column names for clarity.
* **Add widgets**: Open the *Widgets* panel and add the following widgets to enable data exploration:
  * A **Formula Widget** using COUNT, named `Total Crashes`
  * A **Category Widget** to display `accident_type`, named `Crash Types`
  * A **Pie Widget** to display `severity_description`, named `Crash Severity`

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FWUUbZrpI6OzRJ1PYSoYc%2FScreenshot%202025-11-18%20at%2012.03.15.png?alt=media&#x26;token=6145b988-394f-4da2-9915-bae785fc06c8" alt=""><figcaption></figcaption></figure>

Your map is ready! It should display the Bristol traffic crash data clearly with interactive widgets for analysis. Our next step is to add an AI agent that will generate isolines and perform spatial analysis on this data.
{% endstep %}

{% step %}

### Add an AI Agent to the map

To add the Agent, open the *AI Agents* tab in the top-left menu and click <\<Create Agent>>.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FV41CUaeeNklyGzWY4aLD%2FScreenshot%202025-11-18%20at%2012.05.13.png?alt=media&#x26;token=8a6d2830-7387-4a5d-b9b5-9451dcc084ef" alt=""><figcaption></figcaption></figure>

**Provide your Agent with clear use case**

A menu will appear where you can configure your AI Agent. Our next step is to **give our agent a clear mission.** To do that, copy and paste this into the *Use Case section.*

{% code overflow="wrap" %}

```
Help city planners and safety officials optimize traffic safety in Bristol by analyzing accident data. This involves identifying high-risk areas for targeted interventions, enhancing emergency response planning, and supporting data-driven decisions to reduce accidents and improve public safety.
```

{% endcode %}

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FVa5EBoYfTUkwqhkt8PY0%2FScreenshot%202025-11-18%20at%2012.07.47.png?alt=media&#x26;token=c0cef880-2beb-43e8-8159-6f3e2c8890f2" alt=""><figcaption></figcaption></figure>

Click on <\<Create Agent>> to save your changes. You’ll see it listed in the left panel and you can chat with your new agent in Testing mode.

{% hint style="warning" %}
At this point our agent is incomplete, until we provide it with further instructions, and add the MCP tools (workflows) for generating the isoline boundary.
{% endhint %}

**Adding tools to your AI Agent**

AI Agents can access [Core Tools](https://docs.carto.com/carto-user-manual/ai-agents/working-with-tools#core-tools), which are available automatically based on your map configuration and the capabilities you enabled for your Agent, as well as [MCP Tools](https://docs.carto.com/carto-user-manual/ai-agents/working-with-tools#mcp-tools), which you explicitly add. Core Tools include capabilities such as geocoding, spatial filters, marker placement, and widget queries. MCP Tools extend the Agent’s abilities with custom logic—such as the isoline generation workflow we just built.

To add your new MCP Tool:

* Open the Agent Configuration dialog
* Click on <\<Add tools>> — You'll see all the MCP tools you have access to.
* Find your MCP Tool, it should be named like your workflows "dynamic\_isoline\_generation" or similar), and click on Add.&#x20;
* Verify that your workflow now appears under MCP Tools. You can expand the tool to review the description, inputs, and output metadata.&#x20;

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FccVRekivDoQRwAgmMF7q%2FScreenshot%202026-01-26%20at%2010.27.00.png?alt=media&#x26;token=176b669e-a7e0-402e-b73a-4c00c1506997" alt=""><figcaption></figcaption></figure>

**Give instructions to the Agent**

To finish configuring your Agent, open the **Instructions** panel and paste the following prompt. These instructions guide the Agent workflow and ensure tools are used correctly.

```
### Analysis Flow

1. **Location Input**: Prompt the user to provide a specific location or address in Bristol.
2. **Geocoding**: Use the `/lds_geocode` tool to convert the input location into geographic coordinates.
3. **Marker Addition**: Add a marker on the map at the geocoded location using `/add_marker`.
4. **Isoline Generation**: Generate an isoline around the location using `/dynamic_isoline_generation` to understand accessibility or impact zones.
5. **Spatial Filter Application**: Apply the isoline geometry as a spatial filter using `/set_spatial_filter` to focus the map data on the area of interest.

### Data Analysis
After applying any spatial or attribute filter, query the relevant widgets to retrieve updated data. Present only the final analysis and insights, ensuring accuracy and relevance to the filtered map view.

### Presentation
Use markdown for clarity: bullet points, bold values, and tables. Avoid conversational filler; focus on concise and direct insights.

### Final Insights
Summarize key findings and actionable recommendations based on the analysis.
```

Your agent instructions reference Core Tools such as:

* `/lds_geocode`
* `/add_marker`
* `/set_spatial_filter`

These **Core Tools** are automatically available — you do not have to create or configure them.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FRb8IV4p1TOF3dQI2aq7J%2FScreenshot%202025-11-20%20at%2011.44.00.png?alt=media&#x26;token=0c01853b-797a-49a2-898d-bd1f13619eb3" alt=""><figcaption></figcaption></figure>

**Choosing the model**

In the same dialog, choose the model your Agent will use. For this tutorial, select `gemini-2.5-pro`, which provides a strong balance between reasoning and efficiency for spatial analysis. However, you are free to select any available model configured in your organization.&#x20;

### Test your Agent (editor mode)

Before enabling the Agent for end-users, make sure everything is working correctly. You can test it directly from the *Agent Configuration* panel by clicking <\<Test your agent>> in the lower-left corner, or you can interact with it through the AI Agent button located at the bottom center of the map. Both options allow you to preview the full flow end-to-end and confirm that the Agent behaves as expected.

A good example prompt is:&#x20;

“*Analyze traffic accidents around Cotham Brow School BS6 6DT, considering 10 minutes walking distance*”

You should see the full flow: geocoding the address, placing a marker, generating the isoline, applying it as a spatial filter, and finally retrieving updated widget information.

Here's what the analysis should look like:

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FAEuAWU5k5swcw0t0BuHp%2FScreenshot%202025-11-20%20at%2019.11.12.png?alt=media&#x26;token=5299ab3c-46d3-4750-86a7-9eafe80d15c8" alt=""><figcaption></figcaption></figure>

### Enable your Agent to end-users

Looks like we're ready! Let's now make sure that our agent is prepared and available for viewers of our map.

* Go to *Map settings for viewers* and toggle **AI Agent = ON.**
* Use the *Preview* mode if you want to test the end-user experience.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2F59Dxc0Z5FNjQdZ6OXTaH%2FScreenshot%202025-11-20%20at%2019.15.20.png?alt=media&#x26;token=3fb9d857-6079-4f6d-836f-2d762bf23407" alt=""><figcaption></figcaption></figure>

### Share your AI Agent with your organization

* Click on ***Share*** and share your map with others. Make sure to click on ***Publish*** if you make any changes. The published map includes your Agent so end-users can interact with it!
* If you want, copy the link and confirm the Agent can be accessible in Viewer mode.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FzQfNhllH9VRPHNe1MPeO%2FScreenshot%202025-11-20%20at%2019.13.21.png?alt=media&#x26;token=fa561085-ba8d-4133-828c-11842bdecf55" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
**🎉 Congrats!** Your AI agent is now ready to be shared with your organization.

City planners, transport analysts, and public safety teams can use this Agent to explore traffic accident patterns around schools, evaluate accessibility, and understand areas of influence within Bristol.

The Agent will handle geocoding, isoline generation, parameter validation, and applying spatial filters automatically — so end-users can focus entirely on insights and decision-making
{% endhint %}
{% endstep %}
{% endstepper %}
