-
Notifications
You must be signed in to change notification settings - Fork 1k
Python: Add Google AI package scaffolding #1938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eavanvalkenburg
merged 6 commits into
microsoft:python-google
from
Jeyaramjj:googlevertext
Nov 7, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f6f1012
feat(python): Add Google AI/Vertex AI package scaffolding (1/6)
aebb002
refactor: align with Anthropic pattern - use location, chat_model_id,…
4b0d0ec
Merge branch 'main' into googlevertext
Jeyaramjj d1cdc62
Address PR #1938 review comments: migrate to google-genai SDK, add Py…
0d7eaa7
fix: Address pre-commit hooks failures
abcec06
Merge branch 'python-google' into googlevertext
Jeyaramjj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) Microsoft Corporation. | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Get Started with Microsoft Agent Framework Google | ||
|
|
||
| > **Note**: This package is currently under active development. The chat client implementation for Google AI is coming soon. This initial release provides the foundational settings and configuration classes. | ||
|
|
||
| Please install this package via pip: | ||
|
|
||
| ```bash | ||
| pip install agent-framework-google --pre | ||
| ``` | ||
|
|
||
| ## Google AI (Gemini API) Integration | ||
|
|
||
| This package provides integration with Google's Gemini API for Agent Framework: | ||
|
|
||
| - **Google AI (Gemini API)**: Direct access to Google's Gemini models with API key authentication | ||
|
|
||
| > **Note**: This package uses the new `google-genai` SDK as recommended by Google. See the [migration guide](https://ai.google.dev/gemini-api/docs/migrate) for more information. | ||
|
|
||
| ### Current Status | ||
|
|
||
| **Available Now:** | ||
| - `GoogleAISettings`: Configuration class for Google AI (Gemini API) authentication and settings | ||
|
|
||
| **Coming Soon:** | ||
| - `GoogleAIChatClient`: Chat client for Google AI with streaming, function calling, and multi-modal support | ||
| - Integration tests and usage samples | ||
|
|
||
| ### Configuration | ||
|
|
||
| You can configure the settings class now, which will be used by the chat client in the next release: | ||
|
|
||
| #### Google AI Settings | ||
|
|
||
| ```python | ||
| from agent_framework_google import GoogleAISettings | ||
|
|
||
| # Configure via environment variables | ||
| # GOOGLE_AI_API_KEY=your_api_key | ||
| # GOOGLE_AI_CHAT_MODEL_ID=gemini-1.5-pro | ||
|
|
||
| settings = GoogleAISettings() | ||
|
|
||
| # Or pass parameters directly (pass SecretStr for type safety) | ||
| from pydantic import SecretStr | ||
|
|
||
| settings = GoogleAISettings( | ||
| api_key=SecretStr("your_api_key"), | ||
| chat_model_id="gemini-1.5-pro" | ||
| ) | ||
| ``` | ||
|
|
||
| ### Future Usage (Coming Soon) | ||
|
|
||
| Once the chat client is released, usage will look like this: | ||
|
|
||
| ```python | ||
| # from agent_framework.google import GoogleAIChatClient | ||
| # | ||
| # # Configure via environment variables | ||
| # # GOOGLE_AI_API_KEY=your_api_key | ||
| # # GOOGLE_AI_CHAT_MODEL_ID=gemini-1.5-pro | ||
| # | ||
| # client = GoogleAIChatClient() | ||
| # agent = client.create_agent( | ||
| # name="Assistant", | ||
| # instructions="You are a helpful assistant" | ||
| # ) | ||
| # | ||
| # response = await agent.run("Hello!") | ||
| # print(response.text) | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| **Google AI:** | ||
| - `GOOGLE_AI_API_KEY`: Your Google AI API key ([Get one here](https://ai.google.dev/)) | ||
| - `GOOGLE_AI_CHAT_MODEL_ID`: Model to use (e.g., `gemini-1.5-pro`, `gemini-1.5-flash`) | ||
|
|
||
| ### Supported Models | ||
|
|
||
| - `gemini-1.5-pro`: Most capable model | ||
| - `gemini-1.5-flash`: Faster, cost-effective model | ||
| - `gemini-2.0-flash-exp`: Experimental latest model | ||
|
|
||
| ## Features | ||
|
|
||
| ### Planned Features | ||
| - ✅ Chat completion (streaming and non-streaming) | ||
| - ✅ Function/tool calling | ||
| - ✅ Multi-modal support (text, images, video, audio) | ||
| - ✅ System instructions | ||
| - ✅ Conversation history management | ||
|
|
||
| ## Development Roadmap | ||
|
|
||
| This package is being developed incrementally: | ||
|
|
||
| - ✅ **Phase 1 (Current)**: Package structure and settings classes | ||
| - 🚧 **Phase 2 (Next)**: Google AI chat client with streaming and function calling | ||
| - 🚧 **Phase 3**: Google AI integration tests and samples | ||
| - 🚧 **Phase 4**: Advanced features (context caching, safety settings, structured output) | ||
|
|
||
| > **Note**: Vertex AI support may be added in a future iteration based on user demand. | ||
|
|
||
| ## Examples | ||
|
|
||
| Examples will be available once the chat client is implemented. Check back soon or watch the [repository](https://github.com/microsoft/agent-framework) for updates. | ||
|
|
||
| ## Documentation | ||
|
|
||
| For more information: | ||
| - [Google AI Documentation](https://ai.google.dev/docs) | ||
| - [Google Gemini API Migration Guide](https://ai.google.dev/gemini-api/docs/migrate) | ||
| - [Agent Framework Documentation](https://aka.ms/agent-framework) | ||
| - [Agent Framework Repository](https://github.com/microsoft/agent-framework) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| import importlib.metadata | ||
|
|
||
| from ._chat_client import GoogleAISettings | ||
|
|
||
| # NOTE: Client class will be imported here in a future PR | ||
|
|
||
| try: | ||
| __version__ = importlib.metadata.version(__name__) | ||
| except importlib.metadata.PackageNotFoundError: | ||
| __version__ = "0.0.0" # Fallback for development mode | ||
|
|
||
| __all__ = [ | ||
| "GoogleAISettings", | ||
| "__version__", | ||
| ] |
48 changes: 48 additions & 0 deletions
48
python/packages/google/agent_framework_google/_chat_client.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| from typing import ClassVar | ||
|
|
||
| from agent_framework._pydantic import AFBaseSettings | ||
| from pydantic import SecretStr | ||
|
|
||
|
|
||
| class GoogleAISettings(AFBaseSettings): | ||
| """Google AI settings for Gemini API access. | ||
|
|
||
| The settings are first loaded from environment variables with the prefix 'GOOGLE_AI_'. | ||
| If the environment variables are not found, the settings can be loaded from a .env file | ||
| with the encoding 'utf-8'. If the settings are not found in the .env file, the settings | ||
| are ignored; however, validation will fail alerting that the settings are missing. | ||
|
|
||
| Keyword Args: | ||
| api_key: The Google AI API key. | ||
| chat_model_id: The Google AI chat model ID (e.g., gemini-1.5-pro). | ||
| env_file_path: If provided, the .env settings are read from this file path location. | ||
| env_file_encoding: The encoding of the .env file, defaults to 'utf-8'. | ||
|
|
||
| Examples: | ||
| .. code-block:: python | ||
|
|
||
| from agent_framework.google import GoogleAISettings | ||
|
|
||
| # Using environment variables | ||
| # Set GOOGLE_AI_API_KEY=your_api_key | ||
| # GOOGLE_AI_CHAT_MODEL_ID=gemini-1.5-pro | ||
|
|
||
| settings = GoogleAISettings() | ||
|
|
||
| # Or passing parameters directly | ||
| settings = GoogleAISettings(api_key="your_api_key", chat_model_id="gemini-1.5-pro") | ||
|
|
||
| # Or loading from a .env file | ||
| settings = GoogleAISettings(env_file_path="path/to/.env") | ||
| """ | ||
|
|
||
| env_prefix: ClassVar[str] = "GOOGLE_AI_" | ||
|
|
||
| api_key: SecretStr | None = None | ||
| chat_model_id: str | None = None | ||
|
|
||
|
|
||
| # NOTE: Client implementations will be added in a future PR | ||
| # For now, we're only setting up the package structure and settings | ||
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| [project] | ||
| name = "agent-framework-google" | ||
| description = "Google AI (Gemini API) integration for Microsoft Agent Framework." | ||
| authors = [{ name = "Microsoft", email = "[email protected]"}] | ||
| readme = "README.md" | ||
| requires-python = ">=3.10" | ||
| version = "1.0.0b251104" | ||
| license-files = ["LICENSE"] | ||
| urls.homepage = "https://aka.ms/agent-framework" | ||
| urls.source = "https://github.com/microsoft/agent-framework/tree/main/python" | ||
| urls.release_notes = "https://github.com/microsoft/agent-framework/releases?q=tag%3Apython-1&expanded=true" | ||
| urls.issues = "https://github.com/microsoft/agent-framework/issues" | ||
| classifiers = [ | ||
| "License :: OSI Approved :: MIT License", | ||
| "Development Status :: 4 - Beta", | ||
| "Intended Audience :: Developers", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
Jeyaramjj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "Programming Language :: Python :: 3.14", | ||
| "Typing :: Typed", | ||
| ] | ||
| dependencies = [ | ||
| "agent-framework-core", | ||
| "google-genai>=0.2,<1", | ||
| ] | ||
|
|
||
| [tool.uv] | ||
| prerelease = "if-necessary-or-explicit" | ||
| environments = [ | ||
| "sys_platform == 'darwin'", | ||
| "sys_platform == 'linux'", | ||
| "sys_platform == 'win32'" | ||
| ] | ||
|
|
||
| [tool.uv-dynamic-versioning] | ||
| fallback-version = "0.0.0" | ||
|
|
||
| [tool.pytest.ini_options] | ||
| testpaths = 'tests' | ||
| addopts = "-ra -q -r fEX" | ||
| asyncio_mode = "auto" | ||
| asyncio_default_fixture_loop_scope = "function" | ||
| filterwarnings = [ | ||
| "ignore:Support for class-based `config` is deprecated:DeprecationWarning:pydantic.*" | ||
| ] | ||
| timeout = 120 | ||
|
|
||
| [tool.ruff] | ||
| extend = "../../pyproject.toml" | ||
|
|
||
| [tool.coverage.run] | ||
| omit = [ | ||
| "**/__init__.py" | ||
| ] | ||
|
|
||
| [tool.pyright] | ||
| extends = "../../pyproject.toml" | ||
| exclude = ['tests'] | ||
|
|
||
| [tool.mypy] | ||
| plugins = ['pydantic.mypy'] | ||
| strict = true | ||
| python_version = "3.10" | ||
| ignore_missing_imports = true | ||
| disallow_untyped_defs = true | ||
| no_implicit_optional = true | ||
| check_untyped_defs = true | ||
| warn_return_any = true | ||
| show_error_codes = true | ||
| warn_unused_ignores = false | ||
| disallow_incomplete_defs = true | ||
| disallow_untyped_decorators = true | ||
|
|
||
| [tool.bandit] | ||
| targets = ["agent_framework_google"] | ||
| exclude_dirs = ["tests"] | ||
|
|
||
| [tool.poe] | ||
| executor.type = "uv" | ||
| include = "../../shared_tasks.toml" | ||
| [tool.poe.tasks] | ||
| mypy = "mypy --config-file $POE_ROOT/pyproject.toml agent_framework_google" | ||
| test = "pytest --cov=agent_framework_google --cov-report=term-missing:skip-covered tests" | ||
|
|
||
| [build-system] | ||
| requires = ["flit-core >= 3.11,<4.0"] | ||
| build-backend = "flit_core.buildapi" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright (c) Microsoft. All rights reserved. | ||
| from typing import Any | ||
|
|
||
| from pytest import fixture | ||
|
|
||
|
|
||
| @fixture | ||
| def exclude_list(request: Any) -> list[str]: | ||
| """Fixture that returns a list of environment variables to exclude.""" | ||
| return request.param if hasattr(request, "param") else [] | ||
|
|
||
|
|
||
| @fixture | ||
| def override_env_param_dict(request: Any) -> dict[str, str]: | ||
| """Fixture that returns a dict of environment variables to override.""" | ||
| return request.param if hasattr(request, "param") else {} | ||
|
|
||
|
|
||
| @fixture | ||
| def google_ai_unit_test_env(monkeypatch, exclude_list, override_env_param_dict): # type: ignore | ||
| """Fixture to set environment variables for GoogleAISettings.""" | ||
| if exclude_list is None: | ||
| exclude_list = [] | ||
|
|
||
| if override_env_param_dict is None: | ||
| override_env_param_dict = {} | ||
|
|
||
| env_vars = { | ||
| "GOOGLE_AI_API_KEY": "test-api-key-12345", | ||
| "GOOGLE_AI_CHAT_MODEL_ID": "gemini-1.5-pro", | ||
| } | ||
|
|
||
| env_vars.update(override_env_param_dict) # type: ignore | ||
|
|
||
| for key, value in env_vars.items(): | ||
| if key in exclude_list: | ||
| monkeypatch.delenv(key, raising=False) # type: ignore | ||
| continue | ||
| monkeypatch.setenv(key, value) # type: ignore | ||
|
|
||
| return env_vars |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.