### Install and Run Development Server Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_strands_typescript/README.md Navigate to the example directory, install dependencies, and start the development server. ```bash cd examples/browser_maplibre_strands_typescript npm ci npm run dev ``` -------------------------------- ### Install Dependencies Source: https://github.com/opengeos/geoagent/blob/main/examples/node_maplibre_strands_typescript/README.md Navigate to the example directory and install project dependencies using npm. ```bash cd examples/node_maplibre_strands_typescript npm install ``` -------------------------------- ### Run TypeScript Client Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_typescript/README.md Navigate to the example directory, install Node.js dependencies, and run the development server for the TypeScript client. ```bash cd examples/browser_maplibre_typescript npm ci npm run dev ``` -------------------------------- ### Install GeoAgent for Development Source: https://github.com/opengeos/geoagent/blob/main/qgis_geoagent/README.md Execute the install script for development setup. This is typically done from the project's root directory. ```bash python install.py ``` ```bash ./install.sh ``` -------------------------------- ### Start GeoAgent Browser Backend Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_typescript/README.md Install dependencies and start the geoagent browser backend. Ensure you have the necessary packages installed and log in to your codex account. ```bash python -m pip install -e ".[browser]" geoagent codex login geoagent browser --host 127.0.0.1 --port 8765 --model gpt-5.5 ``` -------------------------------- ### Install and Login Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/README.md Install the browser backend and log in with the default OAuth provider. ```bash python -m pip install -e ".[browser]" geoagent codex login ``` -------------------------------- ### Example Prompt: Change Basemap and Get State Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/README.md Example prompt to change the map's basemap to dark and retrieve the current map state. ```text Change the basemap to dark, then get the current map state. ``` -------------------------------- ### Start Production Server Source: https://github.com/opengeos/geoagent/blob/main/examples/node_maplibre_strands_typescript/README.md Starts the production-ready server after the project has been built. ```bash npm start ``` -------------------------------- ### Serve Example Directory Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/README.md Serve the browser_maplibre example directory using Python's http.server. ```bash cd examples/browser_maplibre python -m http.server 8000 ``` -------------------------------- ### Example Prompt: Get Visible Features Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_strands_typescript/README.md Use this prompt to query and identify features currently visible at the map's center. ```text What features are visible at the center of the current map? ``` -------------------------------- ### Example Prompt: Add Marker and Zoom Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/README.md Example prompt to add a red marker for a location and zoom to it. ```text Add a red marker for Knoxville and zoom to it. ``` -------------------------------- ### Start Development Server Source: https://github.com/opengeos/geoagent/blob/main/examples/node_maplibre_strands_typescript/README.md Starts the development server. Ensure you are logged in for OpenAI Codex or have the necessary environment variables set for other providers. ```bash npm run dev ``` -------------------------------- ### Example Prompt: Add Tile Layer and List Layers Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/README.md Example prompt to add an OpenStreetMap tile layer and list all current layers. ```text Add an OpenStreetMap tile layer and list the layers. ``` -------------------------------- ### Install UI Dependency with Anymap Source: https://github.com/opengeos/geoagent/blob/main/docs/ui.md Install the GeoAgent UI dependency along with the Anymap web map backend. This is the preferred installation method. ```bash pip install "GeoAgent[ui,anymap,openai]" ``` -------------------------------- ### Install GeoAgent with NASA OPERA and OpenAI extras Source: https://github.com/opengeos/geoagent/blob/main/examples/README.md Install GeoAgent with the necessary extras for the NASA OPERA example, including OpenAI support. This command should be run within the QGIS Python environment. ```bash pip install "GeoAgent[nasa-opera,openai]" ``` -------------------------------- ### Start GeoAgent Browser Backend Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/README.md Start the GeoAgent browser backend with specified host, port, and model. ```bash geoagent browser --host 127.0.0.1 --port 8765 --model gpt-5.5 ``` -------------------------------- ### Install GeoAgent Source: https://github.com/opengeos/geoagent/blob/main/docs/installation.md Install the core GeoAgent library using pip. ```bash pip install GeoAgent ``` -------------------------------- ### GeoAgent Browser App Setup Source: https://github.com/opengeos/geoagent/blob/main/README.md Install GeoAgent with browser support and launch the browser backend. This allows integration with custom browser MapLibre applications. ```bash pip install "GeoAgent[browser]" geoagent codex login geoagent browser --host 127.0.0.1 --port 8765 --model gpt-5.5 ``` -------------------------------- ### Install UI Dependency with Leafmap Source: https://github.com/opengeos/geoagent/blob/main/docs/ui.md Install the GeoAgent UI dependency with the Leafmap web map backend. Use this if Anymap is not installed or preferred. ```bash pip install "GeoAgent[ui,leafmap,openai]" ``` -------------------------------- ### Install GeoAgent with Optional Integrations Source: https://github.com/opengeos/geoagent/blob/main/docs/index.md Install GeoAgent with specific optional integrations for enhanced functionality. ```bash pip install "GeoAgent[leafmap,openai]" ``` ```bash pip install "GeoAgent[anymap,anthropic]" ``` ```bash pip install "GeoAgent[stac,earthdata,openai]" ``` -------------------------------- ### Sample Prompts for OpenGeoAgent Source: https://github.com/opengeos/geoagent/blob/main/qgis_geoagent/README.md These are example prompts demonstrating how to interact with OpenGeoAgent to perform various QGIS operations and data analysis tasks. ```text Summarize the current QGIS project layers, CRS, extents, and feature counts. Zoom to the active layer and describe what it contains. List visible layers and identify any layers with no features or invalid data sources. Add an OpenStreetMap basemap and zoom to the project extent. Inspect the active vector layer fields and suggest useful styling or labeling options. Select features in the active layer where population is greater than 100000, then zoom to the selected features. Run a buffer around the active layer by 1000 meters and add the output to the project. Create a concise map QA checklist for this project before I export it. ``` -------------------------------- ### Manual Dependency Installation Source: https://github.com/opengeos/geoagent/blob/main/qgis_geoagent/README.md Install GeoAgent core and optional dependencies using pip. Ensure you have Python 3.11 or newer. Each command installs a specific set of features. ```bash pip install "GeoAgent[providers]>=1.8.0" ``` ```bash pip install "GeoAgent[stac]>=1.8.0" ``` ```bash pip install "GeoAgent[whitebox]>=1.8.0" ``` ```bash pip install "GeoAgent[earthdata,nasa-opera]>=1.8.0" ``` ```bash pip install "GeoAgent[earthengine]>=1.8.0" ``` -------------------------------- ### Tool Module Example Source: https://github.com/opengeos/geoagent/blob/main/docs/contributing.md Use a tool module for packages exposing reusable functions that do not require a long-lived object. This file structure is an example. ```text geoagent/tools/my_package.py ``` -------------------------------- ### Development Installation of GeoAgent Source: https://github.com/opengeos/geoagent/blob/main/docs/installation.md Clone the repository and install GeoAgent in development mode for local contributions. ```bash git clone https://github.com/opengeos/GeoAgent.git cd GeoAgent pip install -e ".[dev]" ``` -------------------------------- ### Install Optional Integration Extras Source: https://github.com/opengeos/geoagent/blob/main/docs/contributing.md Install additional dependencies for specific integrations like leafmap, openai, anymap, anthropic, stac, or earthdata. ```bash pip install -e ".[leafmap,openai,dev]" pip install -e ".[anymap,anthropic,dev]" pip install -e ".[stac,earthdata,dev]" ``` -------------------------------- ### Example Prompt: Fly to Location with Zoom Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_strands_typescript/README.md Use this prompt to navigate the map to a specified location with a particular zoom level. ```text Fly to Seattle at zoom level 11. ``` -------------------------------- ### Launch UI with Command Line Source: https://github.com/opengeos/geoagent/blob/main/docs/ui.md Launch the GeoAgent web UI using the command-line interface. This is a quick way to start the application. ```bash geoagent ui ``` -------------------------------- ### Start Backend with Code Execution Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/README.md Start the GeoAgent browser backend with the --allow-browser-code flag to enable PyQGIS-style fallback code execution via run_maplibre_script. ```bash geoagent browser --host 127.0.0.1 --port 8765 --model gpt-5.5 --allow-browser-code ``` -------------------------------- ### Start Backend with Auto-Approve Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/README.md Start the GeoAgent browser backend with the --auto-approve-browser-tools flag to allow destructive tools like remove_layer and clear_layers. ```bash geoagent browser --host 127.0.0.1 --port 8765 --model gpt-5.5 --auto-approve-browser-tools ``` -------------------------------- ### Install Pillow for Image Manipulation Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/openai_codex.ipynb Installs the Pillow library, which is required for image manipulation tasks within the notebook. ```bash # %pip install -q pillow ``` -------------------------------- ### Install GeoAgent with OpenAI Support Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/openai_codex.ipynb Install the GeoAgent library with the necessary OpenAI dependencies using pip. This command should be run once before using the OAuth login. ```bash # %pip install -q "GeoAgent[openai]" ``` -------------------------------- ### Install GeoAgent with Optional Stacks Source: https://github.com/opengeos/geoagent/blob/main/docs/installation.md Install GeoAgent with additional features like leafmap and openai, or qgis support. ```bash pip install "GeoAgent[leafmap,openai]" ``` ```bash pip install "GeoAgent[qgis]" ``` -------------------------------- ### Install GeoAgent with OpenAI support Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/stream_chat_openai_codex.ipynb Installs the GeoAgent library with the necessary OpenAI dependencies using pip. ```python %pip install -q "GeoAgent[openai]" ``` -------------------------------- ### Install GeoAgent with Anthropic support Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/intro.ipynb Install the GeoAgent library with the necessary dependencies for Anthropic integration. This command should be run in your environment. ```python %pip install -q "GeoAgent[anthropic]" ``` -------------------------------- ### Example Prompt: Toggle Layer Visibility Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_strands_typescript/README.md Use this prompt to hide and then re-show the 'US counties' layer. Requires the 'Layer removal' toggle to be enabled for removal. ```text Hide the US counties layer, then show it again. ``` -------------------------------- ### Example Prompt: Tilt and Rotate Map Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_strands_typescript/README.md Use this prompt to tilt the map to a 75-degree pitch and apply a slight rotation. This utilizes the `run_maplibre_script` tool and requires the 'MapLibre JS' toggle to be enabled. ```text Tilt the map to pitch 75 and rotate it slightly. ``` -------------------------------- ### Example Prompt: Change Projection Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_strands_typescript/README.md Use this prompt to alter the map's projection to a globe view. ```text Change to globe projection. ``` -------------------------------- ### Example Prompt: Add GeoJSON Layer Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_strands_typescript/README.md Use this prompt to load and display GeoJSON data from a URL as a layer named 'US counties'. ```text Add the GeoJSON URL https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json as US counties. ``` -------------------------------- ### Factory Pattern Example Source: https://github.com/opengeos/geoagent/blob/main/docs/contributing.md Use a factory pattern when tools require a live object, session, widget, client, or QGIS interface. Factories should bind live objects through closures. ```python def my_package_tools(obj: Any) -> list[Any]: ... def for_my_package(obj: Any, ...) -> GeoAgent: ... ``` -------------------------------- ### Tool Function Design Example Source: https://github.com/opengeos/geoagent/blob/main/docs/contributing.md Design tool functions to be small, explicit, and typed for LLM use. This example shows building tools bound to a live map-like object. ```python from typing import Any from geoagent.core.decorators import geo_tool def my_map_tools(m: Any) -> list[Any]: """Build tools bound to a live map-like object.""" @geo_tool(category="map") def add_geojson(path_or_url: str, name: str) -> str: """Add a GeoJSON dataset to the active map.""" m.add_geojson(path_or_url, layer_name=name) return f"Added GeoJSON layer {name!r}." return [add_geojson] ``` -------------------------------- ### Install Leafmap and GeoAgent for Leafmap Integration Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/openai_codex.ipynb Installs the necessary libraries, leafmap and GeoAgent with leafmap support, for integrating GeoAgent functionalities with interactive maps. ```bash # %pip install -q "GeoAgent[leafmap]" leafmap ``` -------------------------------- ### Launch UI with Solara Directly Source: https://github.com/opengeos/geoagent/blob/main/docs/ui.md Run the Solara application directly using the UI's pages directory. This method resolves the directory dynamically from the installed package. ```bash solara run "$(python -c 'from geoagent.ui import PAGES_DIR; print(PAGES_DIR)')" ``` -------------------------------- ### Install GeoAgent with Anthropic and Leafmap Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/live_mapping.ipynb Install the necessary libraries for GeoAgent, Anthropic, and Leafmap using pip. This command ensures all required dependencies are available for the integration. ```python %pip install -q "GeoAgent[anthropic,leafmap]" leafmap ``` -------------------------------- ### Configure GeoAgent with OpenRouter for Qwen Models Source: https://github.com/opengeos/geoagent/blob/main/README.md Instantiate a GeoAgent to utilize OpenRouter for Qwen models. This example demonstrates configuring the provider and a specific Qwen model ID. ```python qwen_agent = GeoAgent( config=GeoAgentConfig( provider="openrouter", model="qwen/qwen3-32b", ) ) ``` -------------------------------- ### Launch GeoAgent UI Source: https://github.com/opengeos/geoagent/blob/main/README.md Install and launch the GeoAgent UI for a browser-based map chat workspace. This includes provider/model controls and other interactive features. ```bash pip install "GeoAgent[ui,anymap,openai]" geoagent ui ``` -------------------------------- ### Install GeoAgent with STAC support Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/stac_workflow.ipynb Install the GeoAgent library with STAC extras using pip. This command ensures all necessary dependencies for STAC operations are included. ```python %pip install -q "GeoAgent[stac]" ``` -------------------------------- ### Launch UI Programmatically Source: https://github.com/opengeos/geoagent/blob/main/docs/ui.md Launch the GeoAgent web UI from within a Python script. Ensure the necessary UI dependencies are installed. ```python from geoagent.ui import launch_ui launch_ui() ``` -------------------------------- ### Perform a Chat Request Source: https://github.com/opengeos/geoagent/blob/main/docs/usage.md Example of sending a prompt to the GeoAgent and printing the text response. ```python resp = agent.chat("Your prompt") print(resp.answer_text) ``` -------------------------------- ### Example Prompt: Remove Layer Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_strands_typescript/README.md Use this prompt to remove the 'US counties' layer. This requires the 'Layer removal' toggle to be enabled. ```text Remove the US counties layer. ``` -------------------------------- ### Set Environment Variables for OpenAI, Anthropic, or Gemini Source: https://github.com/opengeos/geoagent/blob/main/examples/node_maplibre_strands_typescript/README.md Configure API keys for OpenAI, Anthropic, or Gemini providers by exporting them as environment variables before starting the development server. ```bash export OPENAI_API_KEY=sk-... export ANTHROPIC_API_KEY=sk-ant-... export GEMINI_API_KEY=... ``` -------------------------------- ### Clone and Set Up Development Environment Source: https://github.com/opengeos/geoagent/blob/main/docs/contributing.md Clone the GeoAgent repository and set up a Python virtual environment with development dependencies. ```bash git clone https://github.com/opengeos/GeoAgent.git cd GeoAgent python -m venv .venv source .venv/bin/activate pip install -e ".[dev]" pre-commit install ``` -------------------------------- ### Initialize GeoAgent Source: https://github.com/opengeos/geoagent/blob/main/docs/usage.md Demonstrates different ways to initialize the GeoAgent, from minimal configuration using environment variables to explicit configuration and binding to a live map. ```python from geoagent import GeoAgent, for_leafmap, GeoAgentConfig # Minimal (provider from environment) agent = GeoAgent() # Explicit config agent = GeoAgent(config=GeoAgentConfig(provider="openai", model="gpt-5.5")) # Bound to a live map agent = for_leafmap(m) ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/opengeos/geoagent/blob/main/docs/contributing.md Build the project documentation locally to preview changes if documentation has been modified. ```bash mkdocs build ``` -------------------------------- ### Initialize GeoAgent with Mock QGIS Interface Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/qgis_agent.ipynb Initializes the GeoAgent using mock QGIS objects for testing without a live QGIS instance. Sets up a mock project and interface. ```python from geoagent import for_qgis from geoagent.testing import MockQGISIface, MockQGISLayer, MockQGISProject project = MockQGISProject() project.addMapLayer(MockQGISLayer("StudyArea", "/tmp/a.shp")) iface = MockQGISIface(project=project) agent = for_qgis( iface, project, provider="anthropic", model_id=MODEL, fast=True, ) ``` -------------------------------- ### Configure GeoAgent using Provider and Model ID Shortcuts Source: https://github.com/opengeos/geoagent/blob/main/README.md Create a GeoAgent instance using convenient shortcuts for provider and model ID. This simplifies the configuration process for common providers like Gemini. ```python agent = for_leafmap(m, provider="gemini", model_id="gemini-3.1-pro-preview") ``` -------------------------------- ### General Agent Chat Source: https://github.com/opengeos/geoagent/blob/main/docs/index.md Initialize GeoAgent and use it to chat with a model. This is a general-purpose example. ```python from geoagent import GeoAgent agent = GeoAgent() resp = agent.chat("Explain what STAC is in two sentences.") print(resp.answer_text) ``` -------------------------------- ### Prompt: Clear All Layers Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_typescript/README.md Removes all layers that were added by the user. This requires the backend to be started with `--auto-approve-browser-tools`. ```text Clear all user-added layers. ``` -------------------------------- ### Prompt: Remove Layer Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_typescript/README.md Removes a specific layer, 'OpenStreetMap', from the map. This requires the backend to be started with `--auto-approve-browser-tools`. ```text Remove the OpenStreetMap layer. ``` -------------------------------- ### Login to OpenAI/Codex via Jupyter Source: https://github.com/opengeos/geoagent/blob/main/docs/usage.md Use this Python function within a Jupyter environment to start the login process. ```python from geoagent import login_openai_codex login_openai_codex() ``` -------------------------------- ### Initialize Leafmap and GeoAgent Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/live_mapping.ipynb Create a Leafmap instance with specified center and zoom, and initialize the GeoAgent with Anthropic configuration. The agent is set to 'fast' mode for quicker responses. ```python import leafmap.maplibregl as leafmap from geoagent import for_leafmap from geoagent.core.config import GeoAgentConfig from geoagent.tools.leafmap import leafmap_tools m = leafmap.Map(center=[-83.92, 35.96], zoom=9, height="520px") m ``` -------------------------------- ### Build and Typecheck Scripts Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_strands_typescript/README.md Commands to build the project and check TypeScript types. ```bash npm run build ``` ```bash npm run typecheck ``` -------------------------------- ### Tool Metadata for Safety Source: https://github.com/opengeos/geoagent/blob/main/docs/contributing.md Use @geo_tool metadata to mark tools that require confirmation or are long-running. This example marks an expensive job. ```python @geo_tool( category="processing", requires_confirmation=True, long_running=True, ) def run_expensive_job(parameters: dict[str, Any]) -> dict[str, Any]: """Run an expensive external processing job.""" ... ``` -------------------------------- ### Set Environment Variables for LiteLLM Source: https://github.com/opengeos/geoagent/blob/main/examples/node_maplibre_strands_typescript/README.md Configure LiteLLM to point to an OpenAI-compatible proxy by setting the base URL and API key environment variables. ```bash export LITELLM_BASE_URL=http://127.0.0.1:4000/v1 export LITELLM_API_KEY=... ``` -------------------------------- ### Login for OpenAI Codex Source: https://github.com/opengeos/geoagent/blob/main/examples/node_maplibre_strands_typescript/README.md Perform an initial login for OpenAI Codex access. ```bash npm run codex:login ``` -------------------------------- ### Layer Control Management Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/index.html Manages the addition and removal of a custom LayerControl, which can optionally display a basemap style URL. The control is installed once the map is loaded. ```javascript let layerControl = null; function basemapStyleUrl(style) { return typeof style === "string" && /^https?:\/\//.test(style) ? style : null; } function removeLayerControl() { if (layerControl) { map.removeControl(layerControl); layerControl = null; } } function installLayerControl(style) { removeLayerControl(); const styleUrl = basemapStyleUrl(style); layerControl = new LayerControl({ collapsed: true, ...(styleUrl ? { basemapStyleUrl: styleUrl } : {}), panelWidth: 320, panelMinWidth: 240, panelMaxWidth: 420, }); map.addControl(layerControl, "top-right"); } map.once("load", () => installLayerControl(DEFAULT_BASEMAP)); ``` -------------------------------- ### Build Project Source: https://github.com/opengeos/geoagent/blob/main/examples/node_maplibre_strands_typescript/README.md Compiles the TypeScript project into JavaScript. ```bash npm run build ``` -------------------------------- ### Configure Ollama Source: https://github.com/opengeos/geoagent/blob/main/examples/node_maplibre_strands_typescript/README.md Ensure Ollama is running locally and set the OLLAMA_HOST environment variable if it differs from the default. ```bash ollama pull qwen3.5:4b ``` -------------------------------- ### Prompt: Draw Circle Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_typescript/README.md Generates MapLibre JavaScript to draw a translucent circle around a specified location with a given radius. This requires the backend to be started with `--allow-browser-code`. ```text Draw a translucent circle around Knoxville with about a 25 kilometer radius. ``` -------------------------------- ### Prompt: Add Scale Control Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_typescript/README.md Generates MapLibre JavaScript to add a scale control to the map, positioned in the lower-left corner. This requires the backend to be started with `--allow-browser-code`. ```text Add a scale control to the lower-left corner. ``` -------------------------------- ### Initialize Leafmap and Display Map Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/openai_codex.ipynb Creates and displays an interactive leafmap.Map object with a specified center and zoom level. This map will be used for further GeoAgent integration. ```python import leafmap.maplibregl as leafmap from geoagent import for_leafmap m = leafmap.Map(center=[-83.92, 35.96], zoom=9, height="520px") m ``` -------------------------------- ### Prompt: List User-Added Layers Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_typescript/README.md Retrieves a list of all layers that have been added by the user. ```text List all user-added layers. ``` -------------------------------- ### Initialize GeoAgent and Chat with OpenAI Codex Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/openai_codex.ipynb Initializes the GeoAgent with an OpenAI Codex provider and model configuration. It then sends a chat query to the agent and prints the response, including success status, answer text, and executed tools. ```python from geoagent import GeoAgent, GeoAgentConfig agent = GeoAgent( config=GeoAgentConfig( provider="openai-codex", model=MODEL, temperature=0.0, max_tokens=2048, ), ) resp = agent.chat("In one sentence, what is GeoAgent useful for?") print("success:", resp.success) print(resp.answer_text) print("executed_tools:", resp.executed_tools) ``` -------------------------------- ### Execute Map Command: Get Map State Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/index.html Retrieves the current state of the map, including center coordinates, zoom level, bearing, pitch, bounds, and user-added layers. ```javascript if (command === "get_map_state") { const center = map.getCenter(); const bounds = map.getBounds(); return { center: [center.lng, center.lat], zoom: map.getZoom(), bearing: map.getBearing(), pitch: map.getPitch(), bounds: { west: bounds.getWest(), south: bounds.getSouth(), east: bounds.getEast(), north: bounds.getNorth(), }, user_layers: Array.from(overlays.keys()), }; } ``` -------------------------------- ### Initialize GeoAgent with OpenAI Codex Configuration Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/stream_chat_openai_codex.ipynb Initializes the GeoAgent with a specific configuration for the OpenAI Codex provider, including model, temperature, and max tokens. ```python from geoagent import GeoAgent, GeoAgentConfig agent = GeoAgent( config=GeoAgentConfig( provider="openai-codex", model=MODEL, temperature=0.0, max_tokens=2048, ), ) ``` -------------------------------- ### Lazy Imports for Optional Dependencies Source: https://github.com/opengeos/geoagent/blob/main/docs/contributing.md Import heavy optional packages lazily inside tool bodies to keep the core GeoAgent importable in environments without all dependencies. This example uses rasterio. ```python @geo_tool(category="raster") def inspect_raster(path: str) -> dict: """Inspect a raster dataset.""" import rasterio with rasterio.open(path) as src: return {"width": src.width, "height": src.height} ``` -------------------------------- ### Get STAC Item Assets Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/stac_workflow.ipynb Retrieves the available assets for a given STAC item. It prioritizes common visual or raster asset keys and falls back to the first available asset if none of the preferred keys are found. ```python if not search["items"]: raise RuntimeError("No STAC items found. Try a wider date range or bbox.") first = search["items"][0] assets = tool_payload( agent.tool.get_stac_item_assets( catalog_url=catalog_url, collection=first["collection"], item_id=first["id"], ) ) asset_candidates = assets["assets"] asset = next( ( item for item in asset_candidates if item["key"] in {"visual", "rendered_preview", "B04", "red"} or "tiff" in str(item.get("type", "")).lower() ), asset_candidates[0], ) asset ``` -------------------------------- ### Configure GeoAgent with Explicit Provider Settings Source: https://github.com/opengeos/geoagent/blob/main/README.md Instantiate a GeoAgent with specific configuration parameters, including provider, model, temperature, and max tokens. This is useful for fine-tuning agent behavior. ```python from geoagent import GeoAgentConfig, for_leafmap agent = for_leafmap( m, config=GeoAgentConfig( provider="openai", model="gpt-5.5", temperature=0, max_tokens=4096, ), ) ``` -------------------------------- ### Ensure OpenAI Codex Environment and Login Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/stream_chat_openai_codex.ipynb Checks for an existing OpenAI Codex environment and logs in if necessary. This should be run once to establish authentication. ```python from geoagent import ensure_openai_codex_environment from geoagent import login_openai_codex try: ensure_openai_codex_environment() print("Using stored ChatGPT/Codex login.") except RuntimeError: login_openai_codex() print("Logged in with ChatGPT/Codex OAuth.") ``` -------------------------------- ### Initialize GeoAgent in Fast Mode Source: https://github.com/opengeos/geoagent/blob/main/README.md Use `fast=True` to initialize GeoAgent with a reduced toolset and capped response tokens for lower latency. ```python agent = for_leafmap(m, fast=True) ``` -------------------------------- ### Initialize GeoAgent for QGIS with Anthropic and Fast Mode Source: https://github.com/opengeos/geoagent/blob/main/docs/examples/qgis_agent.ipynb Initializes the GeoAgent for QGIS, specifying the Anthropic provider, model, and enabling fast mode. Assumes API key and model are set. ```python from geoagent import for_qgis import os if not os.environ.get("ANTHROPIC_API_KEY"): raise RuntimeError("Set ANTHROPIC_API_KEY") MODEL = os.environ.get("ANTHROPIC_MODEL", "claude-sonnet-4-6") agent = for_qgis( iface, provider="anthropic", model_id=MODEL, fast=True, ) ``` -------------------------------- ### Execute Map Command: List Layers Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre/index.html Fetches a list of all layers on the map, including their ID, type, source, visibility, and whether they are user-added overlays. ```javascript if (command === "list_layers") { const styleLayers = (map.getStyle().layers || []).map((layer) => ({ id: layer.id, type: layer.type, source: layer.source || null, visible: (layer.layout || {}).visibility !== "none", user_added: isOverlayLayerId(layer.id), })); const markerLayers = Array.from(overlays.values()) .filter((overlay) => overlay.kind === "marker") .map((overlay) => ({ id: overlay.name, type: "marker", source: null, visible: true, user_added: true, })); return [...styleLayers, ...markerLayers]; } ``` -------------------------------- ### Connect to WebSocket Source: https://github.com/opengeos/geoagent/blob/main/examples/browser_maplibre_typescript/README.md Open the Vite development server URL in your browser and connect to the specified WebSocket endpoint for real-time communication with the backend. ```text ws://127.0.0.1:8765/geoagent/ws ```