Python: Add Google AI (Gemini) connector#4492
Open
Jeyaramjj wants to merge 1 commit intomicrosoft:mainfrom
Open
Python: Add Google AI (Gemini) connector#4492Jeyaramjj wants to merge 1 commit intomicrosoft:mainfrom
Jeyaramjj wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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)
4 tasks
Author
|
@eavanvalkenburg Please help review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 viaload_settings()withGOOGLE_AI_env prefixGoogleAIChatOptions— chat options with Google-specific fields (top_k,candidate_count)GOOGLE_AI_API_KEY)Key design decisions
ChatMiddlewareLayer,FunctionInvocationLayer,ChatTelemetryLayer,BaseChatClient— matching the framework's class hierarchygoogle-genaiSDK (google.genai.Client) with async API (aio.models.generate_content)_function_name_mapsince Google requires function name (not call_id) infunction_responseparts_parse_parts_from_google()for both streaming and non-streaming response parsinggoogle.cached_content_token_count,google.thoughts_token_countgcp.geminiresponse_formatfrom options toChatResponsefor structured output supportFiles changed
python/packages/google/agent_framework_google/_chat_client.pypython/packages/google/agent_framework_google/__init__.pyGoogleAIChatClient,GoogleAIChatOptions)python/packages/google/pyproject.tomlagent-framework-core>=1.0.0rc3,google-genai>=0.2,<1python/packages/google/tests/test_google_chat_client.pypython/packages/google/tests/test_settings.pypython/packages/google/tests/conftest.pypython/pyproject.tomlTest plan
pytest --cov)🤖 Generated with Claude Code