Gemini Enterprise custom agent with Vertex AI session
Source notebook
Repo path:
search/gemini-enterprise/gemini_enterprise_session.ipynb· Open on GitHub · advanced
Builds a Gemini Enterprise travel agent using ADK sub-agents and persistent Vertex AI sessions.
Summary
This notebook demonstrates a custom travel-planning agent integrated with Gemini Enterprise. It creates ADK sub-agents for query completeness checking and itinerary generation, runs them locally with VertexAiSessionService, updates an Agent Engine instance with an AdkApp, tests remote session-aware queries, and registers the agent through Discovery Engine API calls.
Key code patterns
Initialize Vertex AI
vertexai.init(
project=PROJECT_ID,
location=LOCATION,
staging_bucket=STAGING_BUCKET,
)Sets project, region, and staging bucket before creating Agent Engine resources.
Create ADK sub-agents
travel_query_validator = Agent(
model="gemini-2.5-flash",
name="travel_query_validator",
instruction=QUERY_CHECK_PROMPT,
)
planner_agent = Agent(
model="gemini-2.5-flash",
name="planner_agent",
instruction=ITINERARY_PROMPT,
)Separates query validation and itinerary generation into focused agents.
Wrap sub-agents as tools
root_agent = Agent(
name="root",
model="gemini-2.5-flash",
generate_content_config=types.GenerateContentConfig(temperature=0.01),
tools=[AgentTool(agent=travel_query_validator), AgentTool(agent=planner_agent)],
)Lets the root agent call specialist ADK agents through AgentTool.
Use persistent Vertex AI sessions
session_service = VertexAiSessionService(
project=PROJECT_ID, location=LOCATION, agent_engine_id=app_name
)
runner = adk.Runner(
agent=root_agent, app_name=app_name, session_service=session_service
)Connects local ADK execution to Vertex AI session state so follow-up queries can use prior context.
Deploy AdkApp to Agent Engine
adk_app = reasoning_engines.AdkApp(
agent=root_agent,
enable_tracing=True,
session_service_builder=session_service_builder,
)
remote_app = agent_engines.update(
resource_name=agent_engine.name,
agent_engine=adk_app,
)Packages the ADK agent with a session service builder and updates an Agent Engine resource.
Models & APIs used
- Models: gemini-2.5-flash
- APIs / services: Vertex AI, Agent Engine, Discovery Engine
- SDKs / libraries:
google-adk,google-genai,google-cloud-aiplatform,vertexai
When to use this
Use this pattern when a Gemini Enterprise custom agent needs persistent conversation context across multi-turn workflows.
Gotchas & caveats
- Project ID, project number, location, staging bucket, user ID, display name, app ID, client ID, client secret, and reasoning engine ID must be filled in.
- The notebook writes a local .env file and sets GOOGLE_GENAI_USE_VERTEXAI=1 for Vertex AI backend use.
- VertexAiSessionService requires an Agent Engine ID derived from a created Agent Engine resource.
- The remote deployment pins google-adk to version 1.5.0 in requirements.
- Gemini Enterprise registration uses gcloud access tokens and Discovery Engine v1alpha endpoints.
- The registration example display name and description mention SQL generation even though the notebook builds a travel agent.
Best practices
- Use VertexAiSessionService when an agent needs persistent session state.
- Split agent responsibilities into query completeness checking and itinerary generation.
- Use a low temperature of 0.01 for the root agent configuration.
- Use a session_service_builder when creating reasoning_engines.AdkApp.
- Test the same multi-turn queries locally and through the remote Agent Engine app.
Related
- Concepts: Agents & ADK · Agent Engine · Vertex AI Search
- Entities: Vertex AI · Google GenAI SDK · Agent Development Kit · Gemini
- Area: Vertex AI Search Notebooks
- Best practices: Agents & ADK - Best Practices · Agent Engine - Best Practices · Vertex AI Search - Best Practices