Skip to content

Fix Google Adapter#4

Merged
nirvanatikku merged 1 commit intomainfrom
fix/gemini-adapter
Mar 6, 2026
Merged

Fix Google Adapter#4
nirvanatikku merged 1 commit intomainfrom
fix/gemini-adapter

Conversation

@nirvanatikku
Copy link
Contributor

Gemini Adapter Rebuild — google-genai SDK v1.0+ Migration

Summary

Migrates the Gemini LLM adapter from the deprecated google-generativeai SDK to the modern google-genai (v1.0+) SDK, achieving full protocol parity with the OpenAI and Anthropic adapters. Fixes the broken LLMEngine Gemini integration that was dropping system prompts, tools, and conversation history.

Changes

Adapter (gemini_adapter.py)

  • Rebuilt GeminiAdapter for the genai.Client pattern (client.models.generate_content / client.models.generate_content_stream) replacing legacy genai.configure() + GenerativeModel()
  • Token counts (prompt, completion, total) from usage_metadata
  • Finish reason mapping from candidates
  • Function call tracking with provider-native IDs
  • Streaming usage metadata recovery from final chunks
  • Multi-turn GeminiChatSession with proper history management, including during streaming via _chat_stream_wrapper

LLM Engine (llm.py)

  • Added _messages_to_gemini_contents() — converts OpenIntent messages to Gemini format (system → system_instruction, assistant → model role)
  • Added _tools_to_gemini_format() — converts tool schemas to Gemini function declarations; returns [] for empty input
  • Added raw provider fallback for Gemini in _call_raw_provider and _stream_raw_provider
  • Updated _format_tools_for_provider for Gemini

Dependencies (pyproject.toml)

  • google-generativeai>=0.4.0google-genai>=1.0.0 in gemini and all-adapters extras
  • mypy overrides updated to google.genai

Docs & Frontend

  • Default model names updated from gemini-1.5-pro / gemini-2.0-flash to gemini-3-flash
  • Code examples updated to new SDK patterns across adapters.tsx, adapters.md, llm-adapters.md, llm-quickstart.md

Tests

  • Added TestGeminiConversions (system extraction, no-system, multi-system, empty messages, tool format, empty tools)
  • Added TestGeminiToolFormatConversion (protocol tool conversion, _format_tools_for_provider Gemini path)
  • Updated model resolution tests for new model names
  • All 105 tests pass

Version

  • Bumped to 0.15.1 across pyproject.toml, __init__.py, MCP server package.json/index.ts, mkdocs.yml, home.html, changelogs, and frontend

CI

  • ruff check . — pass
  • ruff format --check . — pass
  • mypy openintent --ignore-missing-imports — pass
  • pytest -v — 105 passed

@nirvanatikku nirvanatikku merged commit ea81048 into main Mar 6, 2026
3 checks passed
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.

1 participant