0

Gemini Provider

Gemini Provider explains the cloud layer of MTPX with practical guidance for building inspectable, tool-using agents.

Ge
Gemini Provider
Chapter 032ProvidersCloudIndex
01Orientation

Gemini Provider belongs to the providers track. The page breaks the idea into responsibilities, implementation rules, failure modes, and the signals you should expose in a product UI.

Use this when

Use this when you need to understand how gemini provider affects a real MTPX agent before you wire it into an application.

  • What gemini provider owns in the runtime.
  • How it connects to planning, tool execution, events, providers, or storage.
  • What to log, test, and expose to users when this layer is active.
  • Common mistakes that make agent systems hard to inspect.
02 / syntax starter
from mtp import Agent
from mtp.providers import Groq

agent = Agent.MTPAgent(
    provider=Groq(model="llama-3.3-70b-versatile"),
    tools=tools,
)
03 / manual

Read the system

The complete source manual—syntax, examples, linked references, edge cases, and implementation notes.

Documentation index ↗

Google Gemini models with native function calling and full multimodal support (text, image, audio, video, file).

Install

bashpip install "mtpx[gemini]"

Or install the SDK directly:

bashpip install google-genai

API Key Setup

  1. Install dotenv support:
bash   pip install python-dotenv

Or with the MTP extra:

bash   pip install "mtpx[dotenv]"
  1. Create a .env file in your project root:
text   GEMINI_API_KEY=AIzaSyour_key_here
  1. Load it in your code before creating the provider:
python   from mtp import Agent

   Agent.load_dotenv_if_available()  # reads .env file

Get a free API key at aistudio.google.com.

Option 2: System environment variable

bash# Linux/macOS
export GEMINI_API_KEY="AIza..."

# Windows PowerShell
$env:GEMINI_API_KEY="AIza..."

Quick Start

pythonfrom mtp import Agent
from mtp.providers import Gemini

Agent.load_dotenv_if_available()  # loads GEMINI_API_KEY from .env

provider = Gemini(model="gemini-2.0-flash")
tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools)

reply = agent.run_loop("What is 25 * 4 + 10?")
print(reply)

Parameters

ParameterTypeDefaultDescription
modelstr"gemini-2.0-flash"Gemini model ID
api_keystr | NoneNoneAPI key (falls back to GEMINI_API_KEY env var)
temperaturefloat0.0Sampling temperature
clientAny | NoneNonePre-configured google.genai.Client instance

Capabilities

CapabilityValue
Tool callingYes
Parallel tool callsNo
Input modalitiestext, image, audio, video, file
StreamingFallback
Usage metricsRich
Reasoning metadataNo
Native asyncNo (uses thread fallback)
  • gemini-2.0-flash — Fast, good tool calling (default)
  • gemini-2.5-pro — Most capable, best reasoning
  • gemini-2.0-flash-lite — Cheapest option

Multimodal Support

Gemini supports all modalities natively:

pythonfrom mtp.media import Image, Audio, Video, File

# With image
reply = agent.run_loop({
    "content": "Describe this image",
    "images": [Image(filepath="photo.jpg")],
})

# With audio
reply = agent.run_loop({
    "content": "Transcribe this audio",
    "audios": [Audio(filepath="speech.mp3")],
})

# With video
reply = agent.run_loop({
    "content": "What happens in this video?",
    "videos": [Video(filepath="clip.mp4")],
})

Full Example

pythonfrom mtp import Agent
from mtp.providers import Gemini

Agent.load_dotenv_if_available()

provider = Gemini(
    model="gemini-2.0-flash",
    temperature=0.0,
)

tools = Agent.ToolRegistry()
agent = Agent(provider=provider, tools=tools, debug_mode=True)

reply = agent.run_loop(
    "Calculate (25 * 4) + 10 and list files in the current directory.",
    max_rounds=4,
)
print(reply)

Notes

  • Gemini uses function_declarations in tools (not the OpenAI function wrapper format). MTP handles the translation automatically.
  • Tool schemas are sanitized to remove unsupported JSON Schema keys before sending to Gemini.
  • Parallel tool calls are not supported by Gemini's API as of now.

Source

src/mtp/providers/gemini_provider.py

01

Read

Understand where Gemini Provider sits in the agent loop before adding abstractions.

02

Wire

Connect the smallest useful provider, registry, store, or event stream first.

03

Observe

Expose events, logs, results, and failure states while the runtime is still moving.

04

Harden

Add policy, tests, retries, and audit traces after the behavior is visible.

Next docGroq Provider