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?”

1

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.

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:

SELECT ST_GEOGPOINT(@lng, @lat) as geom

Note: ST_GEOGPOINT always takes input as longitude, latitude.

  1. 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:

  
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 from our Analytics Toolbox for BigQuery to generate the travel-time or distance polygon based on the center point and user-defined parameters (mode, range value, and range type).

  1. 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:

Enable the Workflow as MCP Tool

The last step is to enable the Workflow as an MCP Tool. 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.

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.

2

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>>.

Once you're inside your new Builder map, do the following:

  • Give your map a title: Area of Influence Analysis

  • Add traffic crash data: Create a new source using bristol_traffic_accidents dataset available in CARTO Data Warehouse > demo data> demo_tables.

  • 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:

    • 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, named Crash Severity

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.

3

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>>.

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.

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.

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.

Adding tools to your AI Agent

AI Agents can access Core Tools, which are available automatically based on your map configuration and the capabilities you enabled for your Agent, as well as 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.

  • Verify that your workflow now appears under MCP Tools. You can expand the tool to review the description, inputs, and output metadata.

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

  • /get_widget

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

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.

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:

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:

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.

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.

Last updated

Was this helpful?