@carto/agentic-deckgl

@carto/agentic-deckgl is a framework-agnostic TypeScript library that provides tool definitions, system prompt generation, and SDK converters for building AI-powered CARTO + deck.glarrow-up-right map applications. For an introduction to the concepts, see AI-powered map interaction.

Installation

npm install @carto/agentic-deckgl

Peer dependencies: @deck.gl/json (^9.2.0) and zod (^4.3.6).

buildSystemPrompt

Generates a system prompt for the AI agent, including tool-specific instructions, current map state, and optional user context.

Usage

import { buildSystemPrompt, TOOL_NAMES } from '@carto/agentic-deckgl';

const systemPrompt = buildSystemPrompt({
  toolNames: [TOOL_NAMES.SET_DECK_STATE, TOOL_NAMES.SET_MARKER, TOOL_NAMES.SET_MASK_LAYER],
  initialState: {
    viewState: { latitude: 40.7128, longitude: -74.006, zoom: 12 },
    layers: [{ id: 'my-layer', type: 'VectorTileLayer', visible: true }],
    activeLayerId: 'my-layer',
  },
});

Options

  • toolNames: The tools the agent is allowed to use. Use the TOOL_NAMES constant for type safety: TOOL_NAMES.SET_DECK_STATE, TOOL_NAMES.SET_MARKER, TOOL_NAMES.SET_MASK_LAYER.

  • initialState (optional): The current map state, so the AI has context about what the user is viewing. Includes viewState (lat/lng/zoom/pitch/bearing), layers (array of layer state), and activeLayerId.

  • userContext (optional): Business context such as country, business type, demographics, and proximity priorities. This shapes the AI's analytical responses.

  • semanticContext (optional): A pre-rendered markdown string describing the available data tables and their columns. This is typically generated from a YAML-based data catalog.

  • mcpToolNames (optional): When provided, the prompt includes MCP-specific instructions for the listed tool names.

  • additionalPrompt (optional): Custom text appended to the end of the system prompt.

Supporting types

Helper functions

Tool definitions

The library defines 3 tools, each with a Zod validation schema. These tools are what the AI calls to manipulate the map.

set-deck-state

Full deck.gl state control: navigation, basemap, layers, widgets, and effects.

set-marker

Places, removes, or clears location marker pins on the map.

set-mask-layer

Manages an editable mask layer for spatial filtering.

Accessing tool definitions

SDK converters

Convert tool definitions into the format expected by each AI SDK. All converters return tool definitions with built-in Zod validation and a frontend tool marker, so the backend knows the tool should be executed on the client.

getToolsForOpenAIAgents

getToolsForVercelAI

getToolsForGoogleADK

All converters accept an optional toolNames parameter to convert only specific tools:

Custom tool executors

The SDK converters provide default execute functions that validate parameters and return a frontend tool marker. On the frontend, you need a tool executor — a function that receives the tool name and validated parameters and applies them to your deck.gl map state.

The reference frontends in the repository each include a tool-executor that you can use as a starting point and customize for your application. The pattern is a factory function that maps each tool name to your own execution logic:

This is where you control exactly how each tool call affects your application — for example, how layers are merged, how markers are rendered, or how mask geometries are fetched from CARTO tables. See the frontend examplesarrow-up-right for complete implementations in React, Vue, Angular, and Vanilla JS.

Last updated

Was this helpful?