langchain-google-genai

LangChain's official Python integration for Google's Gemini chat, embedding, and multimodal models.

SDK
PyPI
v4.4.0
402stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
90/100Excellent
Development Activity96
Maintenance100
Community76
Maturity48
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
69/100Good
Architecture78
Code Quality88
Innovation65
Learning Curve45

langchain-google-genai is the officially maintained bridge between LangChain and Google’s unified google-genai SDK, giving Python applications a drop-in LangChain interface to Gemini models. It ships three primary classes — ChatGoogleGenerativeAI, GoogleGenerativeAIEmbeddings, and GoogleGenerativeAI — that translate LangChain’s message, tool-call, and structured-output conventions into Gemini’s request/response schema and back, so a Gemini-backed chain looks and behaves like any other LangChain chat model.

Beyond basic chat completion, the package handles the harder integration surface: multimodal input (images, audio, video, PDFs) converted into Gemini’s Part/Blob types, function calling translated to and from Gemini’s FunctionDeclaration format including Pydantic-schema-based structured output, safety-setting and generation-config passthrough, code execution and thinking-config support, and context caching helpers. It lives inside the langchain-ai/langchain-google monorepo alongside the community and vertexai integration packages, and is the recommended path for developers using the Gemini Developer API (as opposed to the Vertex AI-specific package).

What You Get

  • ChatGoogleGenerativeAI — a LangChain BaseChatModel implementation for Gemini’s chat/completion API, with streaming, async, and tool-calling support
  • GoogleGenerativeAIEmbeddings — LangChain-compatible embeddings backed by Gemini’s embedding models
  • GoogleGenerativeAI — a simpler LLM-interface wrapper for non-chat text generation use cases
  • Multimodal input handling — automatic conversion of images, audio, video, and PDF bytes/URIs into Gemini’s Part and Blob types
  • Function calling and structured output — Pydantic models, dicts, and callables converted to Gemini FunctionDeclarations, with parsed structured responses returned as typed objects
  • Context caching helper (create_context_cache) for reusing large prompt prefixes across requests

Common Use Cases

  • Swapping Gemini into an existing LangChain chain or LangGraph agent without changing surrounding orchestration code
  • Building multimodal chat applications that mix text, images, and audio in a single Gemini conversation
  • Using Gemini’s function calling for tool-using agents with Pydantic-defined tool schemas
  • Generating embeddings with Gemini’s embedding models for retrieval-augmented generation pipelines
  • Requesting structured (schema-validated) JSON output from Gemini via LangChain’s with_structured_output pattern

Under The Hood

Architecture The package centers on chat_models.py, a single large module implementing ChatGoogleGenerativeAI by extending LangChain’s BaseChatModel and overriding its generation, streaming, and async hooks; nearly all Gemini-specific translation logic — message history parsing, tool-call conversion, safety settings, generation config — is concentrated there, with embeddings.py and llms.py as thinner sibling wrappers for the embedding and plain-LLM interfaces respectively. Supporting internal modules (prefixed with an underscore: _function_utils.py for tool/schema conversion, _image_utils.py for multimodal Part construction, _enums.py mirroring Gemini’s HarmCategory/Modality enums, _common.py and _compat.py for shared helpers and version-compat shims) keep the public surface small while isolating Gemini API quirks. The package sits alongside langchain-google-community and langchain-google-vertexai in the same monorepo, sharing conventions but each independently versioned and published.

Tech Stack Built for Python 3.10+ using hatchling as the build backend and uv for dependency locking. Core runtime dependencies are langchain-core (the LangChain abstraction layer being implemented against), google-genai (Google’s unified SDK covering both the Gemini Developer API and Vertex AI), pydantic v2 for schema validation and structured-output parsing, and filetype for MIME-type sniffing of multimodal inputs. Dev tooling includes ruff configured against a near-complete rule set with narrowly scoped, explained ignores, and mypy in strict mode.

Code Quality Test coverage is extensive relative to the package’s size: unit tests cover chat models, embeddings, LLMs, function-utils conversion, image-utils conversion, content conversion, and import surface, plus a standard-interface conformance suite (test_standard.py) built on LangChain’s shared langchain-tests harness — the same compliance suite other LangChain model integrations are tested against. Snapshot testing (syrupy) covers serialization-shape regressions, pytest-socket blocks accidental live network calls in unit tests, and a separate integration_tests/ directory holds tests that hit the real Gemini API. mypy strict mode with disallow_untyped_defs is enabled, and CI in the parent monorepo runs dedicated lint/test/integration-test workflows per package.

API Design The integration’s value is almost entirely in fidelity and ergonomics rather than novel mechanics: it normalizes Gemini’s request/response shapes (Content/Part/FunctionDeclaration/GenerateContentConfig) into LangChain’s common message and tool-call conventions closely enough that Gemini-backed chains are largely interchangeable with other LangChain chat models, while still exposing Gemini-specific capabilities — code execution, thinking/reasoning config, context caching, safety settings — as opt-in parameters rather than hiding them. Getting started requires only an API key and the standard LangChain chat-model constructor pattern, with no Gemini-specific boilerplate for common flows.

Used by 6 apps in this directory

Python
97%
MIT

auto-news

AI Assistants · Productivity

905

An AI-powered personal news aggregator that filters multi-source feeds through LLMs and delivers curated, noise-free summaries to your Notion workspace.

View details
43
Repo Health
53
Technical
66
Dependency
Built with
Python97%
Updated 1 years ago
Python
99%
MIT

deepagents

AI Agents · AI Development

29,067

The batteries-included Python agent harness — planning, sub-agents, filesystem, shell, memory, and skills bundled in, built on LangGraph.

View details
88
Repo Health
83
Technical
70
Dependency
Built with
Python99%
Updated yesterday
Python
67%
Apache 2.0

GPT Researcher

Productivity · AI Assistants

29,319

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
90
Repo Health
91
Technical
63
Dependency
Built with
Python67%
TypeScript20%
Updated 1 weeks ago
Python
68%
MIT

Langflow

AI Agents · AI Development

154,349

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
65
Dependency
Built with
Python68%
TypeScript23%
Updated today
Python
45%
GPL 3.0

MaxKB

AI Development · Knowledge Management

22,727

Build enterprise-grade AI agents with RAG, workflows & multi-modal support

View details
91
Repo Health
68
Technical
66
Dependency
Built with
Python45%
Vue37%
TypeScript17%
Updated yesterday
TypeScript
59%
MIT

open-notebook

Note Taking · AI Assistants

38,317

A privacy-first, self-hosted AI research notebook with 18+ model providers, multi-speaker podcast generation, and full REST API—your open-source alternative to Google Notebook LM.

View details
90
Repo Health
84
Technical
74
Dependency
Built with
TypeScript59%
Python39%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search