• About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
AimactGrow
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing
No Result
View All Result
AimactGrow
No Result
View All Result

Tips on how to Mix Google Search, Google Maps, and Customized Features in a Single Gemini API Name With Context Circulation, Parallel Instrument IDs, and Multi-Step Agentic Chains

Admin by Admin
April 8, 2026
Home AI
Share on FacebookShare on Twitter


import subprocess, sys


subprocess.check_call(
   [sys.executable, "-m", "pip", "install", "-qU", "google-genai"],
   stdout=subprocess.DEVNULL,
   stderr=subprocess.DEVNULL,
)


import getpass, json, textwrap, os, time
from google import genai
from google.genai import varieties


if "GOOGLE_API_KEY" not in os.environ:
   os.environ["GOOGLE_API_KEY"] = getpass.getpass("Enter your Gemini API key: ")


consumer = genai.Consumer(api_key=os.environ["GOOGLE_API_KEY"])


TOOL_COMBO_MODEL = "gemini-3-flash-preview"
MAPS_MODEL       = "gemini-2.5-flash"


DIVIDER = "=" * 72


def heading(title: str):
   print(f"n{DIVIDER}")
   print(f"  {title}")
   print(DIVIDER)


def wrap(textual content: str, width: int = 80):
   for line in textual content.splitlines():
       print(textwrap.fill(line, width=width) if line.strip() else "")


def describe_parts(response):
   components = response.candidates[0].content material.components
   fc_ids = {}
   for i, half in enumerate(components):
       prefix = f"   Half {i:2nd}:"
       if hasattr(half, "tool_call") and half.tool_call:
           tc = half.tool_call
           print(f"{prefix} [toolCall]        kind={tc.tool_type}  id={tc.id}")
       if hasattr(half, "tool_response") and half.tool_response:
           tr = half.tool_response
           print(f"{prefix} [toolResponse]    kind={tr.tool_type}  id={tr.id}")
       if hasattr(half, "executable_code") and half.executable_code:
           code = half.executable_code.code[:90].change("n", " ↵ ")
           print(f"{prefix} [executableCode]  {code}...")
       if hasattr(half, "code_execution_result") and half.code_execution_result:
           out = (half.code_execution_result.output or "")[:90]
           print(f"{prefix} [codeExecResult]  {out}")
       if hasattr(half, "function_call") and half.function_call:
           fc = half.function_call
           fc_ids[fc.name] = fc.id
           print(f"{prefix} [functionCall]    title={fc.title}  id={fc.id}")
           print(f"              └─ args: {dict(fc.args)}")
       if hasattr(half, "textual content") and half.textual content:
           snippet = half.textual content[:110].change("n", " ")
           print(f"{prefix} [text]            {snippet}...")
       if hasattr(half, "thought_signature") and half.thought_signature:
           print(f"              └─ thought_signature current ✓")
   return fc_ids




heading("DEMO 1: Mix Google Search + Customized Perform in One Request")


print("""
This demo reveals the flagship new characteristic: passing BOTH a built-in instrument
(Google Search) and a customized perform declaration in a single API name.


Gemini will:
 Flip 1 → Search the net for real-time information, then request our customized
          perform to get climate information.
 Flip 2 → We provide the perform response; Gemini synthesizes every part.


Key factors:
 • google_search and function_declarations go within the SAME Instrument object
 • include_server_side_tool_invocations should be True (on ToolConfig)
 • Return ALL components (incl. thought_signatures) in subsequent turns
""")


get_weather_func = varieties.FunctionDeclaration(
   title="getWeather",
   description="Will get the present climate for a requested metropolis.",
   parameters=varieties.Schema(
       kind="OBJECT",
       properties={
           "metropolis": varieties.Schema(
               kind="STRING",
               description="The town and state, e.g. Utqiagvik, Alaska",
           ),
       },
       required=["city"],
   ),
)


print("▶  Flip 1: Sending immediate with Google Search + getWeather instruments...n")


response_1 = consumer.fashions.generate_content(
   mannequin=TOOL_COMBO_MODEL,
   contents=(
       "What's the northernmost metropolis in the USA? "
       "What is the climate like there at this time?"
   ),
   config=varieties.GenerateContentConfig(
       instruments=[
           types.Tool(
               google_search=types.GoogleSearch(),
               function_declarations=[get_weather_func],
           ),
       ],
       tool_config=varieties.ToolConfig(
           include_server_side_tool_invocations=True,
       ),
   ),
)


print("   Components returned by the mannequin:n")
fc_ids = describe_parts(response_1)


function_call_id = fc_ids.get("getWeather")
print(f"n   ✅ Captured function_call id for getWeather: {function_call_id}")


print("n▶  Flip 2: Returning perform outcome & requesting last synthesis...n")


historical past = [
   types.Content(
       role="user",
       parts=[
           types.Part(
               text=(
                   "What is the northernmost city in the United States? "
                   "What's the weather like there today?"
               )
           )
       ],
   ),
   response_1.candidates[0].content material,
   varieties.Content material(
       position="person",
       components=[
           types.Part(
               function_response=types.FunctionResponse(
                   name="getWeather",
                   response={"response": "Very cold. 22°F / -5.5°C with strong Arctic winds."},
                   id=function_call_id,
               )
           )
       ],
   ),
]


response_2 = consumer.fashions.generate_content(
   mannequin=TOOL_COMBO_MODEL,
   contents=historical past,
   config=varieties.GenerateContentConfig(
       instruments=[
           types.Tool(
               google_search=types.GoogleSearch(),
               function_declarations=[get_weather_func],
           ),
       ],
       tool_config=varieties.ToolConfig(
           include_server_side_tool_invocations=True,
       ),
   ),
)


print("   ✅ Ultimate synthesized response:n")
for half in response_2.candidates[0].content material.components:
   if hasattr(half, "textual content") and half.textual content:
       wrap(half.textual content)
Tags: AgenticAPICallChainsCirculationCombineContextCustomfunctionsGeminiGoogleIDsMapsmultistepParallelSearchSingletool
Admin

Admin

Next Post
How AI brokers will determine which manufacturers get discovered

How AI brokers will determine which manufacturers get discovered

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recommended.

AI Avatars and the New Afterlife

AI Avatars and the New Afterlife

July 2, 2025
Sensible Sci-Fi Manga Planetes Is Getting New Deluxe Version Omnibuses

Sensible Sci-Fi Manga Planetes Is Getting New Deluxe Version Omnibuses

May 9, 2025

Trending.

Mistral AI Releases Voxtral TTS: A 4B Open-Weight Streaming Speech Mannequin for Low-Latency Multilingual Voice Era

Mistral AI Releases Voxtral TTS: A 4B Open-Weight Streaming Speech Mannequin for Low-Latency Multilingual Voice Era

March 29, 2026
The way to Clear up the Wall Puzzle in The place Winds Meet

The way to Clear up the Wall Puzzle in The place Winds Meet

November 16, 2025
Moonshot AI Releases 𝑨𝒕𝒕𝒆𝒏𝒕𝒊𝒐𝒏 𝑹𝒆𝒔𝒊𝒅𝒖𝒂𝒍𝒔 to Exchange Mounted Residual Mixing with Depth-Sensible Consideration for Higher Scaling in Transformers

Moonshot AI Releases 𝑨𝒕𝒕𝒆𝒏𝒕𝒊𝒐𝒏 𝑹𝒆𝒔𝒊𝒅𝒖𝒂𝒍𝒔 to Exchange Mounted Residual Mixing with Depth-Sensible Consideration for Higher Scaling in Transformers

March 16, 2026
Exporting a Material Simulation from Blender to an Interactive Three.js Scene

Exporting a Material Simulation from Blender to an Interactive Three.js Scene

August 20, 2025
Efecto: Constructing Actual-Time ASCII and Dithering Results with WebGL Shaders

Efecto: Constructing Actual-Time ASCII and Dithering Results with WebGL Shaders

January 5, 2026

AimactGrow

Welcome to AimactGrow, your ultimate source for all things technology! Our mission is to provide insightful, up-to-date content on the latest advancements in technology, coding, gaming, digital marketing, SEO, cybersecurity, and artificial intelligence (AI).

Categories

  • AI
  • Coding
  • Cybersecurity
  • Digital marketing
  • Gaming
  • SEO
  • Technology

Recent News

Tips on how to detect a deepfake with visible clues and AI instruments

Agentic AI’s function in amplifying and creating insider dangers

April 8, 2026
How AI brokers will determine which manufacturers get discovered

How AI brokers will determine which manufacturers get discovered

April 8, 2026
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved

No Result
View All Result
  • Home
  • Technology
  • AI
  • SEO
  • Coding
  • Gaming
  • Cybersecurity
  • Digital marketing

© 2025 https://blog.aimactgrow.com/ - All Rights Reserved