Skip to content

feat: Add Google Gemini plugin for Flyte#632

Open
andreahlert wants to merge 2 commits intoflyteorg:mainfrom
andreahlert:feat/gemini-plugin
Open

feat: Add Google Gemini plugin for Flyte#632
andreahlert wants to merge 2 commits intoflyteorg:mainfrom
andreahlert:feat/gemini-plugin

Conversation

@andreahlert
Copy link
Contributor

Summary

This PR adds a new plugin for integrating Google's Gemini API with Flyte, following the same patterns as the existing OpenAI and Anthropic plugins.

Features

  • function_tool decorator: Convert Flyte tasks to Gemini function declarations automatically
  • Automatic type conversion: Python type hints to JSON schema for tool input validation
  • Agent class: Configure Gemini agents with model, instructions, and tools
  • run_agent function: Execute agent loops that handle function calling and responses
  • Support for sync and async tasks
  • Manual function calling control: Uses AFC (Automatic Function Calling) disabled mode for explicit tool execution management

Usage Example

import flyte
from flyteplugins.gemini import function_tool, run_agent

env = flyte.TaskEnvironment("gemini-agent")

@env.task
async def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Weather in {city}: sunny, 72F"

@env.task
async def agent_task(prompt: str) -> str:
    tools = [function_tool(get_weather)]
    return await run_agent(
        prompt=prompt,
        tools=tools,
        model="gemini-2.5-flash",
    )

Files Added

  • plugins/gemini/ - Plugin package
    • pyproject.toml - Package configuration
    • README.md - Documentation
    • src/flyteplugins/gemini/agents/_function_tools.py - Core implementation
    • tests/test_agents.py - Test suite (19 tests)
  • examples/genai/gemini_agent.py - Example workflow

Test Plan

  • All 19 unit tests pass
  • Type conversion tests (string, int, float, bool, list, dict, Optional)
  • Function schema extraction tests
  • FunctionTool creation tests (regular functions, Flyte tasks, async)
  • Agent configuration tests
  • Tool execution tests (sync and async)
  • run_agent tests (tool calls, errors, max iterations, finish reasons)

Why Gemini?

Google Gemini is one of the leading LLM providers alongside OpenAI and Anthropic. Having first-class support enables users to:

  • Choose the best model for their use case
  • Easily switch between providers
  • Use Gemini's unique capabilities (multimodal, large context windows, cost efficiency)

This plugin mirrors the Anthropic plugin's API design, making it easy to switch between providers.

@kumare3
Copy link
Contributor

kumare3 commented Feb 8, 2026

I dont think this is right, i have not looked at the anthropic plugin, but this will result in bugs and instability

@kumare3
Copy link
Contributor

kumare3 commented Mar 3, 2026

@andreahlert here is the updated anthropic plugin - do you want to update your google gemini plugin using this model - https://github.com/flyteorg/flyte-sdk/tree/main/plugins/anthropic

Add a new plugin that integrates Google's Gemini API with Flyte,
enabling Flyte tasks to be used as tools for Gemini agents.

The plugin provides:
- FunctionTool: wraps Flyte tasks or regular callables as Gemini
  function declarations with automatic JSON schema generation
- function_tool: decorator/converter for creating tools from
  functions and Flyte tasks
- Agent: configuration dataclass for Gemini agent settings
- run_agent: async agent loop that handles function calling,
  error handling, and conversation state management

Includes comprehensive test coverage (19 tests) and a sandwich-making
example that demonstrates multi-tool orchestration.

Signed-off-by: André Ahlert <andre@aex.partners>
@andreahlert andreahlert force-pushed the feat/gemini-plugin branch 2 times, most recently from 0e6ac00 to 36d1d03 Compare March 6, 2026 09:16
- Use Flyte type engine for schema: func.json_schema for tasks,
  NativeInterface.from_callable().json_schema for callables
- Remove custom TYPE_MAP and _get_function_schema helpers
- Execute: use task.aio() for async tasks, to_thread(self.func) for sync
- Fix GenerateContentConfig: use automatic_function_calling (not _config)
- Replace schema unit tests with NativeInterface/type-engine tests
- Add docstring note on type engine for input_schema

Signed-off-by: André Ahlert <andre@aex.partners>
@andreahlert
Copy link
Contributor Author

Hi @kumare3! LGTM

I’ve aligned the Gemini plugin with the Anthropic one. Let me know if you’d like any other changes.

@andreahlert andreahlert requested a review from kumare3 March 6, 2026 09:21
thread executor to avoid blocking the event loop.
"""
if self.task is not None:
if self.is_async:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not async?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.aio is available on non async tasks too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We updated the anthropic plugin, sorry for the confusion, can you change like that and we can merge this

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants