/adk-tools:vertex-ai-sdkfrom adk-tools
Vertex AI SDK patterns for configuring Gemini models including generation parameters, safety settings, streaming responses, and function calling. PROACTIVELY activate for: (1) model configuration and temperature settings, (2) safety controls and streaming implementation, (3) Vertex AI endpoint selection and function calling. Triggers: "gemini config", "model parameters", "streaming response"
Ships in adk-tools. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The Vertex AI SDK provides Python interfaces for Gemini models with fine-grained control over generation behavior, safety, and response characteristics. Proper configuration is critical for production-grade agents.
from google import genai
from google.genai import types
import os
# Initialize Vertex AI client
client = genai.Client(
vertexai=True,
project=os.getenv("GOOGLE_CLOUD_PROJECT"),
location=os.getenv("GOOGLE_CLOUD_LOCATION", "us-central1")
)
# Reuse client instance across requests
MODEL_ID = "gemini-2.0-flash-exp"
Best Practice: Initialize client once and reuse. Creating new clients for every request adds unnecessary overhead.
| Model | Use Case | Speed | Cost | Context Window |
|---|---|---|---|---|
gemini-2.0-flash-exp | Fast responses, production agents | Fastest | Lowest | 1M tokens |
gemini-1.5-pro | Complex reasoning, analysis | Medium | Medium | 2M tokens |
gemini-1.5-flash | Balanced performance | Fast | Low | 1M tokens |
from google.genai import types
# Create generation configuration
config = types.GenerateContentConfig(
temperature=0.7, # Randomness (0.0 = deterministic, 2.0 = creative)
top_p=0.95, # Nucleus sampling threshold
top_k=40, # Top-k sampling (limits token pool)
max_output_tokens=2048, # Maximum response length
candidate_count=1, # Number of responses to generate
stop_sequences=["END"] # Optional: Stop generation at these tokens
)
# Use config with model
response = await client.aio.models.generate_content(
model=MODEL_ID,
contents="Explain quantum computing",
config=config
)
Temperature (Controls randomness):
0.0-0.3: Deterministic, factual responses (documentation, data extraction)0.4-0.7: Balanced creativity (general conversation, analysis)0.8-1.2: Creative writing (stories, brainstorming)1.3-2.0: Maximum creativity (experimental, art)Top-P (Nucleus sampling):
0.9-0.95: Recommended for most use cases0.8-0.89: More focused, less diverse outputs0.96-1.0: Maximum diversityTop-K (Token pool size):
1-10: Very focused (not recommended)20-50: Balanced (recommended)100+: Very diverseMax Output Tokens:
512: Short responses (summaries, answers)2048: Medium responses (explanations, code)8192: Long responses (essays, documentation)from google.genai.types import (
HarmCategory,
HarmBlockThreshold,
SafetySetting
)
# Define safety settings
safety_settings = [
SafetySetting(
category=HarmCategory.HARM_CATEGORY_HATE_SPEECH,
threshold=HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
),
SafetySetting(
category=HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
threshold=HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
),
SafetySetting(
category=HarmCategory.HARM_CATEGORY_HARASSMENT,
threshold=HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
),
SafetySetting(
category=HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT,
threshold=HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
)
]
# Apply to generation config
config = types.GenerateContentConfig(
temperature=0.7,
safety_settings=safety_settings
)
| Category | Description | When to Block |
|---|---|---|
HATE_SPEECH | Content promoting hate based on protected characteristics | Always |
DANGEROUS_CONTENT | Instructions for harmful activities | Always |
HARASSMENT | Content intended to bully, intimidate, or threaten | Always |
SEXUALLY_EXPLICIT | Sexual content | Application-dependent |
| Threshold | Effect | Use Case |
|---|---|---|
BLOCK_NONE | No blocking | Internal testing only |
BLOCK_ONLY_HIGH | Block high-confidence harmful content | Liberal applications |
BLOCK_MEDIUM_AND_ABOVE | Block medium+ confidence (RECOMMENDED) | Production |
BLOCK_LOW_AND_ABOVE | Block low+ confidence | Conservative applications |
async def stream_response(prompt: str) -> None:
"""
Generate streaming response with real-time output.
Args:
prompt: User prompt for the model
"""
client = genai.Client(vertexai=True)
# Use generate_content_stream for streaming
async for chunk in client.aio.models.generate_content_stream(
model=MODEL_ID,
contents=prompt,
config=types.GenerateContentConfig(temperature=0.7)
):
# Process each chunk as it arrives
if chunk.text:
print(chunk.text, end="", flush=True)
print() # Newline after complete response
import asyncio
from typing import AsyncIterator
async def safe_stream_response(
prompt: str,
timeout: float = 30.0
) -> AsyncIterator[str]:
"""
Stream response with timeout and error handling.
Args:
prompt: User prompt
timeout: Maximum time to wait for complete response
Yields:
Text chunks from the model
"""
client = genai.Client(vertexai=True)
try:
stream = client.aio.models.generate_content_stream(
model=MODEL_ID,
contents=prompt
)
# Apply timeout to entire stream
async for chunk in asyncio.wait_for(stream, timeout=timeout):
if chunk.text:
yield chunk.text
except asyncio.TimeoutError:
yield "\n[Response timed out]"
except Exception as e:
yield f"\n[Error: {str(e)}]"
# Usage
async for text in safe_stream_response("Explain AI"):
print(text, end="", flush=True)
Why Streaming?
from pydantic import BaseModel, ConfigDict, Field
# Define tool schema
class CalculatorInput(BaseModel):
"""Calculator tool input."""
model_config = ConfigDict(strict=True)
operation: str = Field(description="Math operation: add, subtract, multiply, divide")
a: float = Field(description="First number")
b: float = Field(description="Second number")
# Create function declaration
calculator_function = types.FunctionDeclaration(
name="calculator",
description="Perform basic math operations",
parameters=CalculatorInput.model_json_schema()
)
# Create tool
calculator_tool = types.Tool(
function_declarations=[calculator_function]
)
# Use with model
response = await client.aio.models.generate_content(
model=MODEL_ID,
contents="What is 15 multiplied by 23?",
config=types.GenerateContentConfig(
tools=[calculator_tool]
)
)
# Check for function call
if response.candidates[0].content.parts:
for part in response.candidates[0].content.parts:
if part.function_call:
print(f"Function: {part.function_call.name}")
print(f"Args: {part.function_call.args}")
async def run_agent_with_tools(
user_message: str,
tools: list[types.Tool],
max_iterations: int = 5
) -> str:
"""
Run agent with automatic function execution.
Args:
user_message: Initial user message
tools: List of available tools
max_iterations: Max tool call iterations
Returns:
Final text response
"""
client = genai.Client(vertexai=True)
chat = client.aio.chats.create(
model=MODEL_ID,
config=types.GenerateContentConfig(tools=tools)
)
response = await chat.send_message(user_message)
for _ in range(max_iterations):
# Check if model wants to call a function
if not response.candidates[0].content.parts:
break
function_calls = [
part.function_call
for part in response.candidates[0].content.parts
if part.function_call
]
if not function_calls:
break # No more function calls
# Execute all function calls
function_responses = []
for fc in function_calls:
# Execute function (implement your tool execution logic)
result = await execute_tool(fc.name, fc.args)
function_responses.append(
types.Part(
function_response=types.FunctionResponse(
name=fc.name,
response=result
)
)
)
# Send function results back to model
response = await chat.send_message(
types.Content(parts=function_responses)
)
return response.text
# US regional endpoint
client = genai.Client(
vertexai=True,
project="my-project",
location="us-central1" # Regional endpoint
)
Advantages:
Use When:
# Global endpoint
client = genai.Client(
vertexai=True,
project="my-project",
location="us" # Global endpoint
)
Advantages:
Use When:
For Claude models on Vertex AI, endpoint selection affects both performance and cost:
# Regional endpoint required for Claude
client = genai.Client(
vertexai=True,
project="my-project",
location="us-east5" # Claude available in specific regions
)
model = "claude-3-5-sonnet@20241022"
Note: Check Vertex AI documentation for current regional availability of specific models.
# BAD: Creates unnecessary overhead
async def bad_generate(prompt: str):
client = genai.Client(vertexai=True) # New client every time!
return await client.aio.models.generate_content(...)
# GOOD: Reuse client
CLIENT = genai.Client(vertexai=True) # Module-level singleton
async def good_generate(prompt: str):
return await CLIENT.aio.models.generate_content(...)
# BAD: No safety configuration
config = types.GenerateContentConfig(temperature=0.7)
# GOOD: Explicit safety settings
config = types.GenerateContentConfig(
temperature=0.7,
safety_settings=[...] # Always configure
)
# BAD: No error handling
async for chunk in stream:
print(chunk.text)
# GOOD: Comprehensive error handling
try:
async for chunk in asyncio.wait_for(stream, timeout=30):
if chunk.text:
print(chunk.text)
except asyncio.TimeoutError:
handle_timeout()
except Exception as e:
handle_error(e)
# BAD: Generic, unhelpful description
function = types.FunctionDeclaration(
name="get_data",
description="Gets data", # Not helpful!
...
)
# GOOD: Specific, actionable description
function = types.FunctionDeclaration(
name="get_weather",
description="Get current weather conditions for a specific city including temperature, humidity, and forecast",
...
)
Activate this skill when:
This skill is a required dependency for:
adk-fundamentals: Model configuration is part of agent setupprompt-engineering: Model parameters affect prompt effectivenessrag-patterns: RAG requires proper model configurationFor deeper understanding:
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub agentient/vibekit --plugin adk-tools5 skills in this plugin
/adk-fundamentalsFoundational knowledge for creating ADK (Agent Development Kit) agents including environment setup, project structure, and basic agent scaffolding. PROACTIVELY activate for: (1) new ADK agent creation, (2) ADK project setup and environment configuration, (3) AdkApp initialization and understanding core ADK architecture. Triggers: "create adk agent", "new agent", "setup adk"
/agent-orchestrationMulti-agent orchestration patterns including coordinator agents, LlmAgent vs WorkflowAgent selection, agent-as-tool pattern, and inter-agent communication via session state. PROACTIVELY activate for: (1) multi-agent systems and agent coordination, (2) sub-agent delegation and agent-as-tool implementation, (3) workflow orchestration with LlmAgent and WorkflowAgent. Triggers: "multi-agent", "orchestration", "agent team"
/prompt-engineeringBest practices for engineering high-quality system prompts for AI agents with emphasis on XML structure, clarity, few-shot examples, and token efficiency. PROACTIVELY activate for: (1) system prompt creation and optimization, (2) instruction clarity improvement and few-shot example design, (3) XML tag structure implementation and prompt templates. Triggers: "system prompt", "optimize prompt", "prompt engineering"
/rag-patternsVertex AI RAG Engine integration patterns for grounding agent responses in private data sources including corpus management, retrieval tool creation, and citation extraction. PROACTIVELY activate for: (1) RAG pipeline integration and Vertex AI RAG Engine setup, (2) corpus creation and document ingestion, (3) retrieval tool configuration and grounding metadata parsing. Triggers: "add rag", "rag pipeline", "vertex ai search"
Other plugins' skills for the same job