How opengeos/geoagent works
1. What this repo is
GeoAgent is a shared agent layer for geospatial workflows. The core idea is: a user prompt enters a GeoAgent surface, the agent selects tools, tools act on a live map/QGIS/dataset object, and the result is returned to the model and then to the user. It is designed to sit between LLM providers and geospatial libraries rather than replace those libraries.
2. Core engine boundary
The geoagent/core package is the central runtime. It wraps a Strands Agent and owns provider/model configuration, prompt setup, result formatting, tool registration, safety checks, and context handling. GeoAgent is the main facade, while GeoAgentConfig and GeoAgentContext define how the agent is configured and what live objects it can touch.
3. Tool system
Tools are first-class and metadata-driven. The @geo_tool decorator turns normal Python functions into agent-visible tools with categories and safety flags, and GeoToolRegistry keeps track of tool definitions, filtering, and fast-mode selection. This layer is what makes the same agent framework reusable across many geospatial packages.
4. Factory-based integrations
The package avoids a one-size-fits-all object model by using factories such as for_leafmap, for_anymap, for_qgis, for_nasa_opera, and for_stac. These factories bind live runtime objects through closures so the model sees only safe tool arguments, not the underlying widget or plugin internals. create_agent is the escape hatch for custom tool sets.
5. Geospatial tool adapters
geoagent/tools contains the domain adapters: map controls, vector/raster/XYZ/STAC layer actions, NASA Earthdata and OPERA workflows, Earth Engine, geoai, Vantor, Whitebox, timelapse, images, and others. Some tools are thin wrappers around external geospatial libraries; others perform service calls or UI actions. Shared helpers like _map_state and _qt_marshal support consistent state reporting and safe Qt execution.
6. QGIS is a major execution boundary
QGIS support is not just another tool set; it is a separate runtime boundary. geoagent.tools.qgis is import-safe outside QGIS and only imports QGIS classes inside tool bodies. QGIS tools use GUI-thread marshalling and sequential execution so layer-tree and canvas operations happen safely in the desktop app. The fallback run_pyqgis_script path exists for operations that require direct PyQGIS access beyond predefined tools.
7. QGIS plugin subsystem
qgis_geoagent/open_geoagent is the packaged QGIS plugin. It provides dockable chat/settings UI, OAuth and provider controls, dependency management, update checks, and plugin installation packaging. The plugin consumes GeoAgent tool metadata rather than duplicating tool logic, so the same underlying tool definitions drive both the Python API and the desktop plugin.
8. Browser runtime
geoagent/browser provides a FastAPI/WebSocket backend for browser-based MapLibre apps. The data flow here is bidirectional: the browser UI sends chat and map commands over WebSockets, the backend runs the agent and returns tool results, and map mutations are reflected back to the client. The repo’s browser examples show both a Python-backed flow and TypeScript/Node variants.
9. UI workspace
geoagent/ui is a Solara-based workspace for interactive chat with live maps. It exposes a higher-level application shell with chat history, model controls, fast mode, compact tool-call output, and confirmation policy handling. This UI sits on top of the same core agent and tool factories, so it is a presentation layer rather than a separate agent implementation.
10. Provider and auth layer
Model access is abstracted behind provider configuration, with support for OpenAI, ChatGPT/Codex OAuth, Anthropic, Gemini, Bedrock, Ollama, LiteLLM, OpenRouter, and vLLM. Provider selection can come from explicit config or environment variables, and Codex login is handled as a separate auth flow that stores and reuses tokens. This keeps model/provider concerns isolated from geospatial tool code.
11. Safety and confirmation
Destructive, expensive, or irreversible tool actions are marked with metadata and gated by confirmation hooks before execution. The same mechanism is used across map edits, QGIS project changes, file writes, and long-running tasks. This is a core architectural boundary: the agent may propose an action, but tool execution can still be denied or approved by the host UI/plugin.
12. Packaging and integration surfaces
Optional extras control which subsystems are available in a given environment: core agent only, geospatial integrations, UI, browser backend, or provider clients. That split matters because the repo targets multiple runtimes: plain Python scripts, Jupyter notebooks, desktop QGIS, browser-based map apps, and a packaged QGIS plugin. The examples and docs are not just demos; they illustrate the supported deployment shapes.
13. Testing and support code
The tests and qgis_geoagent/tests directories indicate that the architecture is heavily interface-driven and mocked around optional dependencies. Tests cover tool behavior, provider selection, browser server/session logic, QGIS import safety, Qt marshalling, and plugin startup constraints. That reflects the repo’s main constraint: many integrations must remain optional and import-safe across environments.
Main entry points: factory.py Factories · agent.py GeoAgent · open_geoagent.py Open GeoAgent · server.py Browser server
Components 32
Core runtime
Agent facade, configuration, context, provider selection, prompts, safety, and tool registration.
- GeoAgent · Main entry point that runs prompts, selects tools, and formats results.
geoagent/core/agent.py - Config · Provider, model, tool, and runtime configuration.
geoagent/core/config.py - Context · Carries live objects and state the agent can operate on.
geoagent/core/context.py - Registry · Stores tool metadata, filtering, and fast-mode selection.
geoagent/core/registry.py - Decorators · Turns Python callables into agent-visible tools with safety metadata.
geoagent/core/decorators.py - Providers · Provider abstraction and model configuration across LLM backends.
geoagent/core/model.py - Safety · Gates destructive or expensive actions before tool execution.
geoagent/core/safety.py - Results · Normalizes tool outputs and agent responses.
geoagent/core/result.py - Factories · Builds configured agents for specific geospatial runtimes.
geoagent/core/factory.py
Tool adapters
Geospatial tool layers and runtime-specific adapters exposed to the agent.
- Leafmap · Map and layer actions for Leafmap-style workflows.
geoagent/tools/leafmap.py - Anymap · Generic map controls and stateful map operations.
geoagent/tools/anymap.py - QGIS tools · Import-safe QGIS adapters with GUI-thread marshalling and sequential execution.
geoagent/tools/qgis.py - Browser tools · Tools for browser MapLibre workflows and bidirectional map updates.
geoagent/tools/browser_maplibre.py - STAC · STAC catalog and item interactions.
geoagent/tools/stac.py - NASA data · NASA Earthdata and related workflow adapters.
geoagent/tools/nasa_earthdata.py - OPERA · NASA OPERA workflow tools.
geoagent/tools/nasa_opera.py - Earth Engine · Google Earth Engine actions and workflows.
geoagent/tools/earthengine.py - GeoAI · Geospatial AI helpers and inference-oriented tools.
geoagent/tools/geoai.py - Whitebox · Terrain and raster analysis adapters.
geoagent/tools/whitebox.py - Timelapse · Time-series and animation-oriented map tools.
geoagent/tools/timelapse.py - HyperCoast · Domain-specific geospatial workflows and helpers.
geoagent/tools/hypercoast.py
Runtime surfaces
Presentation and execution surfaces that host the shared agent layer.
- Browser server · FastAPI/WebSocket backend for browser-based map agents.
geoagent/browser/server.py - Browser session · Maintains bidirectional browser map/chat session state.
geoagent/browser/session.py - UI app · Interactive workspace shell for chat and live maps.
geoagent/ui/app.py - Workspace · Shared UI state, chat flow, and confirmation handling.
geoagent/ui/workspace.py
QGIS plugin
Packaged desktop plugin boundary for QGIS.
- Open GeoAgent · Packaged QGIS plugin entrypoint and desktop integration.
qgis_geoagent/open_geoagent/open_geoagent.py - Chat dock · Dockable chat interface inside QGIS.
qgis_geoagent/open_geoagent/dialogs/chat_dock.py - Settings dock · Provider, OAuth, and dependency controls in QGIS.
qgis_geoagent/open_geoagent/dialogs/settings_dock.py - Deps manager · Dependency and environment management for the plugin.
qgis_geoagent/open_geoagent/deps_manager.py
Support
Examples, tests, and scripts that exercise integration points.
- Browser demos · Python and TypeScript MapLibre browser examples.
examples/browser_maplibre - Node demo · TypeScript browser/server example with Codex auth and map sessions.
examples/node_maplibre_strands_typescript - Tests · Interface-driven tests for providers, tools, browser, QGIS, UI, and safety.
tests
Connections 35
- GeoAgent → Config: uses · Agent is assembled from configuration.
- GeoAgent → Context: reads live state · Agent operates on live objects in context.
- GeoAgent → Registry: selects tools · Agent consults the registry for available tools.
- GeoAgent → Providers: calls model · Agent delegates to configured LLM providers.
- GeoAgent → Safety: gates actions · Confirmation and safety checks can block execution.
- GeoAgent → Results: formats output · Agent normalizes final results for the host surface.
- Decorators → Registry: registers · Tool decorators create registry entries and metadata.
- Factories → GeoAgent: builds · Factories construct ready-to-use agent instances.
- Factories → Leafmap: binds · Factories close over runtime objects and expose safe tools.
- Factories → Anymap: binds · Factories wire generic map runtimes into tools.
- Factories → QGIS tools: binds · Factories assemble QGIS-capable tool sets.
- Factories → Browser tools: binds · Factories assemble browser map runtimes.
- Factories → STAC: binds · Factories include catalog-oriented tools.
- Factories → NASA data: binds · Factories include Earthdata workflows.
- Factories → OPERA: binds · Factories include OPERA workflows.
- Factories → Earth Engine: binds · Factories include Earth Engine adapters.
- Factories → GeoAI: binds · Factories include GeoAI tools.
- Factories → Whitebox: binds · Factories include analysis tools.
- Factories → Timelapse: binds · Factories include temporal visualization tools.
- Factories → HyperCoast: binds · Factories include domain-specific workflows.
- Browser server → Browser session: manages · Server owns browser chat/map sessions.
- Browser server → GeoAgent: runs · Backend invokes the shared agent runtime.
- Browser session → Browser tools: drives · Session sends map commands through browser tools.
- UI app → Workspace: hosts · App renders the workspace shell.
- Workspace → GeoAgent: invokes · UI workspace uses the shared agent and factories.
- Open GeoAgent → Chat dock: provides · Plugin exposes the chat dock UI.
- Open GeoAgent → Settings dock: provides · Plugin exposes settings and OAuth controls.
- Open GeoAgent → Deps manager: manages · Plugin manages dependency installation and checks.
- Open GeoAgent → Factories: consumes · Plugin consumes shared tool metadata and factories.
- Browser demos → Browser server: demonstrates · Examples show browser-backed map workflows.
- Node demo → Browser server: demonstrates · Node example shows browser server/client composition.
- Tests → GeoAgent: covers · Tests validate core agent behavior.
- Tests → QGIS tools: covers · Tests validate QGIS import safety and threading.
- Tests → Browser server: covers · Tests validate browser server/session behavior.
- Tests → Open GeoAgent: covers · Tests validate plugin startup and integration constraints.