Setting the file. One moment.
Skill 06 · Agent Observability Experiment Bootstrap
Subchapter 6.8
references/python/providers/gemini.mdMarkdown2 KBView on GitHub
Triggered by introspection (Workflow step 2.5) when the call-site function imports google.generativeai and calls:
google.generativeai.GenerativeModel(...).generate_content(...)genai.GenerativeModel(...).generate_content(...) (aliased import)Either GEMINI_API_KEY or GOOGLE_API_KEY works — both are valid env names per google-generativeai‘s SDK conventions. Emit a single combined assert:
assert os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY"), (
"GEMINI_API_KEY or GOOGLE_API_KEY is required for the wired task_fn."
)If the call-site uses vertexai.generative_models.GenerativeModel (not google.generativeai), the auth path is Google Cloud Application Default Credentials, not an API key. Emit:
# Vertex AI uses Google Cloud ADC, not an API key.
# Run `gcloud auth application-default login` before running this file, or set
# GOOGLE_APPLICATION_CREDENTIALS to point at a service account JSON.
assert os.getenv("GOOGLE_APPLICATION_CREDENTIALS"), (
"GOOGLE_APPLICATION_CREDENTIALS path is required for the wired task_fn (Vertex AI), "
"or run `gcloud auth application-default login` before invoking."
)GenerativeModel("gemini-pro").generate_content("prompt") returns a GenerateContentResponse. Extract via .text (single-candidate) or .candidates[0].content.parts[0].text.model.start_chat(history=[]).send_message("prompt") returns the same response shape.generate_content_async(...) — wrap with asyncio.run(...)..text raises ValueError in that case. If the user’s function doesn’t handle this, surface a WARNING:.google.generativeai. Be aware of which path the user’s function uses.