Frontend tool events
When the agent calls a backend @frontend_tool (e.g. zoom_to,
draw_geometry, show_toast), the step arrives with
state: "frontend_tool" plus the event name and payload. Wire it to your
map with onFrontendEvent:
<AgentChat
apiBaseUrl="http://localhost:8000/api/v1"
onFrontendEvent={(ev) => {
switch (ev.event_name) {
case "zoom_to":
map.flyTo([ev.payload.lat, ev.payload.lon], ev.payload.zoom);
break;
case "draw_geometry":
addGeoJSON(JSON.parse(ev.payload.geojson));
break;
case "show_toast":
toast[ev.payload.level](ev.payload.message);
break;
}
}}
/>;
type FrontendToolEvent = {
event_name: string;
payload: object;
tool_name?: string;
};
Built-in GIS events
These six are pre-registered by the backend package (import
stacgis_ai):
| Event | Purpose | Typical payload |
|---|---|---|
zoom_to | Navigate the map viewport to a coordinate | { lat, lon, zoom } |
highlight_feature | Highlight a feature by id | { feature_id, layer_id } |
show_toast | Display a toast notification | { message, level } — level: info | success | warn | error |
open_panel | Open a named side panel / drawer | { panel_id } |
draw_geometry | Draw a GeoJSON overlay | { geojson, layer_id } — geojson is a JSON string |
set_layer_visibility | Show / hide a map layer | { layer_id, visible } |
:::tip App-defined events
The built-in set is a starting point — register anything else with
@frontend_tool(event="…") on the backend. The frontend needs no changes to
deliver new events, as long as you handle them in onFrontendEvent. The demo
app defines two of its own: select_location (opens the map location picker,
with an optional query prefill) and reset (resets the chat).
:::
Define your own on the backend with the
@frontend_tool decorator
— the frontend needs no changes to render new events, as long as you handle
them in onFrontendEvent.