Skip to content

Python: Add Google AI (Gemini) connector#4492

Open
Jeyaramjj wants to merge 1 commit intomicrosoft:mainfrom
Jeyaramjj:google-chat-client
Open

Python: Add Google AI (Gemini) connector#4492
Jeyaramjj wants to merge 1 commit intomicrosoft:mainfrom
Jeyaramjj:google-chat-client

Conversation

@Jeyaramjj
Copy link

@Jeyaramjj Jeyaramjj commented Mar 5, 2026

Summary

Adds a new Google AI connector (agent-framework-google) for the Gemini API, following the same patterns established by the Anthropic connector.

  • GoogleAIChatClient — full-featured chat client supporting text, streaming, function calling, images (base64 + URI), and Google-hosted tools (Google Search, Code Execution)
  • GoogleAISettings — TypedDict-based settings via load_settings() with GOOGLE_AI_ env prefix
  • GoogleAIChatOptions — chat options with Google-specific fields (top_k, candidate_count)
  • 59 unit tests covering settings, client init, message conversion, tool preparation, config creation, response/stream processing, and async API
  • 5 integration tests (marker-gated, require GOOGLE_AI_API_KEY)

Key design decisions

  • Inherits from ChatMiddlewareLayer, FunctionInvocationLayer, ChatTelemetryLayer, BaseChatClient — matching the framework's class hierarchy
  • Uses google-genai SDK (google.genai.Client) with async API (aio.models.generate_content)
  • Tracks function names via _function_name_map since Google requires function name (not call_id) in function_response parts
  • Shared _parse_parts_from_google() for both streaming and non-streaming response parsing
  • Google-specific usage metadata: google.cached_content_token_count, google.thoughts_token_count
  • OTEL provider set to gcp.gemini
  • Passes through response_format from options to ChatResponse for structured output support

Files changed

File Description
python/packages/google/agent_framework_google/_chat_client.py Main connector implementation (868 lines)
python/packages/google/agent_framework_google/__init__.py Public exports (GoogleAIChatClient, GoogleAIChatOptions)
python/packages/google/pyproject.toml Package metadata, deps: agent-framework-core>=1.0.0rc3, google-genai>=0.2,<1
python/packages/google/tests/test_google_chat_client.py 54 unit tests + 5 integration tests
python/packages/google/tests/test_settings.py 5 settings unit tests
python/packages/google/tests/conftest.py Test fixtures (env setup, mock Google client)
python/pyproject.toml Workspace source entries for new packages

Test plan

  • All 59 unit tests pass (pytest --cov)
  • 5 integration tests skipped without API key (marker-gated)
  • Ruff lint clean
  • Follows Anthropic connector patterns for consistency
  • Reviewed against Google GenAI SDK docs and best practices

🤖 Generated with Claude Code

Implements GoogleAIChatClient for the agent-framework, providing full
integration with Google's Gemini models via the google-genai SDK.

Features:
- Async chat completion and streaming via unified _inner_get_response
- Function calling with FunctionTool and @tool decorator
- Multi-turn tool use with function name tracking (_function_name_map)
- System instructions via config.system_instruction
- Multimodal support: inline image data and image URIs
- Hosted tools: Google Search and Code Execution via static factory methods
- Tool choice support: auto/required/none mapped to AUTO/ANY/NONE
- Google-specific ChatOptions: top_k, candidate_count
- Google-specific usage fields: cached_content_token_count, thoughts_token_count
- OpenTelemetry observability (gcp.gemini provider)
- Structured output via response_format passthrough
- Middleware, function invocation, and telemetry layer support

Architecture:
- Class hierarchy: ChatMiddlewareLayer -> FunctionInvocationLayer ->
  ChatTelemetryLayer -> BaseChatClient with Generic[GoogleOptionsT]
- TypedDict settings via load_settings() with GOOGLE_AI_ env prefix
- GoogleAIChatOptions extending ChatOptions with unsupported options typed as None
- Consistent naming: _prepare_*_for_google, _parse_*_from_google

Tests: 59 passed, 5 integration tests (skipped without API key)
@Jeyaramjj
Copy link
Author

@eavanvalkenburg Please help review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants