Agent Toolkit plugin

The Agent Toolkit lets your users talk to a TomTom map. Add an LLM and a chat box, and they can plan routes, search for places, inspect traffic and reshape the map with sentences instead of clicks.

What you can build with it

  • Conversational route planning, such as “Drive me from Berlin to Munich avoiding tolls, and stop for coffee halfway.” The agent chains geocoding, routing, place search and route edits, and renders the result.
  • Operational dashboards, such as “Show me where congestion is worst right now, and chart how many of our vehicles are in it.” The traffic tools work next to custom tools that read your own fleet data.
  • Self-explaining field tools, such as “Outline every neighbourhood unreachable from the hospital in 20 minutes.” Isochrones plus generated code produce and render a derived polygon.
  • Exploring your own data. Load a GeoJSON file and ask “keep only the points inside the congested tiles”. The agent registers it as a BYOD layer and filters it.

What’s in the box

@tomtom-org/maps-sdk-plugin-agent-toolkit is a headless plugin built on Vercel AI SDK v6. createMapAgent returns a ToolLoopAgent wired to a TomTomMap and the TomTom services.

You bring:

  • A model from any Vercel AI SDK provider (OpenAI, Anthropic, Azure, Google, …).
  • A chat UI, or programmatic agent.generate() / agent.stream() calls.

The plugin provides:

Quickstart

All plugins use @tomtom-org/maps-sdk as a peer dependency, so install the SDK first. See the Project Setup guide if needed.

Install

npm install @tomtom-org/maps-sdk-plugin-agent-toolkit ai zod
npm install @ai-sdk/react @ai-sdk/openai # or @ai-sdk/anthropic, @ai-sdk/azure, …

The plugin’s other peer dependencies are @tomtom-org/maps-sdk-plugin-map-theme, maplibre-gl, @turf/turf, chart.js and h3-js. npm 7+ and pnpm 8+ install them automatically. With other package managers, add them yourself.

Wire it up

import { TomTomConfig } from '@tomtom-org/maps-sdk/core';
import { TomTomMap } from '@tomtom-org/maps-sdk/map';
import { createMapAgent } from '@tomtom-org/maps-sdk-plugin-agent-toolkit';
import { openai } from '@ai-sdk/openai';
import { useChat } from '@ai-sdk/react';
import { DirectChatTransport } from 'ai';
TomTomConfig.instance.put({ apiKey: 'YOUR_API_KEY' });
const map = new TomTomMap({ mapLibre: { container: 'map' } });
const agent = createMapAgent(map, {
model: openai('gpt-4o'),
dataEntries: {
routes: { entryMode: 'single' }, // one route on the map at a time
byod: { enabled: false }, // no bring-your-own-data tools in this deployment
},
});
const { messages, sendMessage } = useChat({
transport: new DirectChatTransport({ agent }),
});

Without a chat UI, call the agent directly:

const { text } = await agent.generate({
messages: [{ role: 'user', content: 'Find coffee shops near Dam Square' }],
});

To stream the reply into a chat box of your own, call agent.stream() instead and keep the conversation in a messages array. The demo below does that in plain TypeScript, with no framework:

Try it out

  • “Route from Berlin to Munich avoiding tolls.”
  • “Show coffee shops near the map centre.”
  • “What traffic incidents are on this route?”
  • “Switch to dark mode.”
  • “How far is the second stop?”
  • “Chart the incidents along the route by category.”

Clean up

agent.destroy(); // resets every built-in and custom state slice that implements reset()

Options

createMapAgent(map, options) takes one required option, model. The pages in the table explain the other options.

OptionWhat it controlsRead
tools, includeDefaultToolsAdd, remove, replace or hand-pick toolsCustomizing tools
systemPrompt, systemPromptPrefix, systemPromptSuffixThe system promptCustomizing the system prompt
classifier, onClassifyPer-turn tool selectionHow it works
prepareStep, maxSteps, stepProviderOptions, providerOptions, outputSchemasThe tool loopHow it works
onToolExecutePer-tool timing and errorsHow it works
state, dataEntriesCustom state slices; which data kinds exist and their entry modeState
byodWhich URLs the agent may fetchBring your own data
codeExecutionSandbox timeout and worker librariesCode generation

Building with an AI coding assistant

The tomtom-maps-sdk-js skill covers this plugin. Name a public API such as createMapAgent or analyseData in your question. AI coding with the SDK explains how to install and use it.

Where to next

Read them in this order to learn enough to ship something:

API reference

Agent Toolkit Plugin API Reference