Building and Deploying a Google Maps API Agent with Agent Engine
Source notebook
Repo path:
gemini/agent-engine/tutorial_google_maps_agent.ipynb· Open on GitHub · intermediate
Builds, tests, deploys, and queries a Gemini Google Maps agent on Vertex AI Agent Engine.
Summary
This notebook teaches how to build an Agent Engine agent with Gemini, LangChain, and Python functions used as tools. It defines Google Maps API tools for geocoding, place search, satellite maps, and solar potential maps, tests them locally, deploys the agent to Vertex AI Agent Engine, grants Cloud Storage permissions, queries the remote agent, and cleans up resources.
Key code patterns
Initialize Vertex AI
PROJECT_ID = "[your-project-id]"
LOCATION = "us-central1"
STAGING_BUCKET = f"gs://{PROJECT_ID}-agent-engine-staging"
import vertexai
vertexai.init(project=PROJECT_ID, location=LOCATION)Sets the project and region used by the Vertex AI SDK and Agent Engine.
Define model
model = "gemini-2.5-flash"Selects the Gemini model used by the agent.
Create Maps tools
def geocode_address(query: str):
import googlemaps
gmaps = googlemaps.Client(key=MAPS_API_KEY)
response = gmaps.geocode(query)
return response[0]["geometry"]["location"]Shows how Python functions become tools that call external Google Maps APIs.
Upload generated maps
storage_client = storage.Client()
bucket = storage_client.bucket(STAGING_BUCKET.replace("gs://", ""))
blob = bucket.blob("agent_engine/satellite_map.png")
blob.upload_from_filename("satellite_map.png")Stores generated map files in the staging bucket so the local or remote agent workflow can retrieve them.
Create LangChain agent
agent = LangchainAgent(
model=model,
model_kwargs={"temperature": 0},
tools=[
geocode_address,
search_places,
create_satellite_map,
create_solar_potential_map,
],
)Combines the Gemini model, deterministic settings, and tool functions into an Agent Engine-compatible LangChain agent.
Deploy to Agent Engine
client = vertexai.Client(project=PROJECT_ID, location=LOCATION)
remote_agent = client.agent_engines.create(
agent=agent,
config={"staging_bucket": STAGING_BUCKET, "requirements": [...]},
)Deploys the locally tested agent as a remotely accessible Vertex AI Agent Engine resource.
Grant bucket access
policy = bucket.get_iam_policy(requested_policy_version=3)
policy.bindings.append({
"role": "roles/storage.objectUser",
"members": [f"serviceAccount:service-{project_number}@gcp-sa-aiplatform-re.iam.gserviceaccount.com"],
})
bucket.set_iam_policy(policy)Gives the Agent Engine service account permission to read and write tutorial image files in Cloud Storage.
Query remote agent
response = remote_agent.query(
input="""I'd like to start a community effort to build a solar panel project
near the Tokyo Big Sight Exhibition Center. What are some nearby government
offices that might help me?"""
)Demonstrates invoking the deployed agent from Python after deployment.
Models & APIs used
- Models: gemini-2.5-flash
- APIs / services: Vertex AI API, Maps Geocoding API, Maps Places API, Maps Static API, Maps Solar API, Resource Manager API, Cloud Storage
- SDKs / libraries:
google-cloud-aiplatform,vertexai,googlemaps,google-cloud-storage,google-cloud-resource-manager,LangChain,requests,rasterio,matplotlib
When to use this
Use this pattern to deploy a Gemini agent that calls Google Maps APIs and persists generated map artifacts in Cloud Storage.
Gotchas & caveats
- The notebook requires a Google Cloud project with Vertex AI API enabled.
- Maps Geocoding, Places, Static, and Solar APIs must be enabled and require a Maps API key.
- The configured location is us-central1.
- The Agent Engine deployment needs a staging bucket.
- The Agent Engine service account needs roles/storage.objectUser on the staging bucket before remote image writes work.
- The deployment config must include runtime requirements such as googlemaps, google-cloud-storage, rasterio, and requests.
- Colab users must authenticate with google.colab.auth.authenticate_user().
- The cleanup section deletes the deployed agent and optionally deletes the staging bucket to avoid unexpected charges.
Best practices
- Test individual tool functions before wiring them into the agent.
- Test the agent locally before deploying it to Agent Engine.
- Use temperature 0 for deterministic agent behavior in this workflow.
- Declare deployment requirements explicitly in the Agent Engine create config.
- Grant only the needed Storage Object User role to the Agent Engine service account for bucket access.
- Clean up the deployed agent after experimentation.
Related
- Concepts: Function Calling & Tools · Agent Engine · Applied Use Cases
- Entities: Vertex AI · Vertex AI SDK · LangChain · Cloud Storage · Function Calling · Gemini
- Area: Gemini Notebooks
- Best practices: Function Calling & Tools - Best Practices · Agent Engine - Best Practices · Applied Use Cases - Best Practices