google agentic deploying with gateway agent
We can use the following python to perform deployment. Also notice that this is more configurable compare to glcoud command line.
So we will be deploying an agent to google agent runtime and it will use an gateway. This gateway is an ingress (client-to-agent) and it is called my-first-gateway. If you have another setup client-to-everywhere else (egress) setup would be slightly different.
import asyncio
from urllib import response
from google.adk.agents import Agent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.genai import types
from google.adk.agents.callback_context import CallbackContext
from google.adk.models.llm_request import LlmRequest
from vertexai import types as vertex_types
from google.genai import types
import vertexai
# Ensure this matches your actual GCP Project ID, not a placeholder
vertexai.init(project="project-project-id", location="us-central1")
# 1. Define the callback function
def inspect_llm_input(callback_context: CallbackContext, llm_request: LlmRequest):
"""Callback triggered directly before ADK sends payload to the LLM."""
print("=" * 60)
print("INSPECTING INPUT PASSED TO LLM BY ADK")
print("=" * 60)
print(llm_request)
print("=" * 60 + "\n")
# Return None to continue execution normally
return None
# -------------------------------------------------------------
# 1. DEFINE THE TOOL FUNCTION
# ADK inspects docstrings and type hints to auto-generate
# the FunctionDeclaration for Gemini.
# -------------------------------------------------------------
def get_user_account_balance(user_id: str, include_pending: bool = False) -> dict:
"""Retrieves the current bank balance for a specific user ID.
Args:
user_id: The unique account identifier for the customer.
include_pending: Whether to include pending uncleared transactions.
"""
return {
"user_id": user_id,
"balance": "$4,250.00",
"pending": "$120.00" if include_pending else "$0.00"
}
# -------------------------------------------------------------
# 2. CREATE THE ADK AGENT
# -------------------------------------------------------------
banking_agent = Agent(
name="account_assistant",
model="gemini-2.5-flash",
instruction="You are a helpful customer support agent. Answer questions concisely.",
tools=[get_user_account_balance],
before_model_callback=inspect_llm_input
)
# -------------------------------------------------------------
# 3. RUNNER & SESSION ORCHESTRATION
# -------------------------------------------------------------
async def main():
# Initialize client
client = vertexai.Client(project="project-project-id", location="us-central1")
# Define resource ID of your gateway
gateway_resource_id = (
"projects/project-poroject-id/locations/us-central1/agentGateways/my-first-gateway"
)
# Deploy agent with gateway configurations attached
remote_agent = client.agent_engines.create(
agent=banking_agent,
config={
"display_name": "Governed Production Agent",
"requirements": ["google-cloud-aiplatform[agent_engines,adk]"],
"staging_bucket": "gs://my-vertex-bucket-ai",
"identity_type": vertex_types.IdentityType.AGENT_IDENTITY,
# Attach the Agent Gateway configuration block
"agent_gateway_config": {
"client_to_agent_config": {
"agent_gateway": gateway_resource_id
}
},
},
)
print(remote_agent.api_resource.spec.deployment_spec.agent_gateway_config)
asyncio.run(main())
You can check your agent gateway configuration by running the following code :-
client = vertexai.Client(project="project-project-id", location="us-central1")
agent = client.agent_engines.get(
name="projects/projectid/locations/us-central1/reasoningEngines/reasoning-engine-id"
)
print(agent.api_resource.spec.deployment_spec.agent_gateway_config)
Or if you have access to the console then you can check here. Under deployment, select your agent and the under "Service Configuration" -> "Deployment Details" and under spec


Comments