Files
agent-framework/python/packages/gemini
T
cooleryu d5335fbeae Python (fix:gemini): make Gemini honor declarative outputSchema, not just JSON mode (#5893)
* fix(gemini): preserve schema response_format

* fix(gemini): satisfy pyright strict in response schema extraction

Cast Any-narrowed mappings to Mapping[str, Any] in the structured-output
schema helpers so pyright strict no longer reports partially-unknown
member, argument, and variable types. Pass response_format["format"]
straight into the recursive extractor, which already guards non-mapping
inputs. No behavior change.

* fix(gemini): use Sequence[object] cast to satisfy both mypy and pyright

The Sequence[Any] cast pyright strict needs to know the loop element type
is reported as a redundant-cast by mypy, which already narrows the
isinstance branch to Sequence[Any]. Cast to Sequence[object] instead:
pyright gets a fully known element type and mypy no longer sees an
identical-type cast. No behavior change.

---------

Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
d5335fbeae ยท 2026-06-05 15:17:51 +00:00
History
..
2026-04-14 10:18:26 +00:00

Get Started with Microsoft Agent Framework Gemini

Install the provider package:

pip install agent-framework-gemini --pre

Gemini Integration

The Gemini integration enables Microsoft Agent Framework applications to call Google Gemini models with familiar chat abstractions, including streaming, tool/function calling, and structured output.

Structured Output

Gemini structured output can be configured with either a Pydantic model in response_format, a JSON schema mapping in response_format, or a Gemini-specific response_schema. Declarative agents that define outputSchema pass that schema through response_format.

Authentication

The connector supports both google-genai authentication modes.

Gemini Developer API

Obtain an API key from Google AI Studio and set either the package-prefixed or SDK-standard environment variable:

export GEMINI_API_KEY="your-api-key"
# or: export GOOGLE_API_KEY="your-api-key"
export GEMINI_MODEL="gemini-2.5-flash-lite"
# or: export GOOGLE_MODEL="gemini-2.5-flash-lite"

Vertex AI

Set the standard Vertex AI environment variables used by google-genai:

export GOOGLE_GENAI_USE_VERTEXAI=true
export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_LOCATION="global"
export GOOGLE_MODEL="gemini-2.5-flash-lite"

Examples

See the Google Gemini samples for runnable end-to-end scripts covering:

  • Basic agent with tool calling and streaming
  • Extended thinking with ThinkingConfig
  • Google Search grounding
  • Google Maps grounding
  • Built-in code execution