How to Integrate with Google Gemini for Agents: 4 Proven Patterns from the Awesome LLM Apps Repository
You can integrate Google Gemini with AI agents by using it as an LLM provider for Agno-based agents, as an embedding model for vector search, or through the Gemini Interactions API for multi-step research workflows.
The Shubhamsaboo/awesome-llm-apps repository demonstrates production-ready patterns for Google Gemini integration across diverse agent architectures. Whether you are building simple chat agents or complex research pipelines, these implementations show how to leverage Gemini's multimodal capabilities, embedding models, and advanced interaction APIs.
Four Integration Patterns for Google Gemini
Direct LLM Agent with Agno
The most straightforward way to integrate with Google Gemini for agents is using the Gemini model class from the agno.models.google module. This wraps the Gemini REST API into a standard interface compatible with Agno's Agent class.
In starter_ai_agents/multimodal_ai_agent/mutimodal_agent.py, the implementation instantiates the model with specific version identifiers:
from agno.models.google import Gemini
agent = Agent(
name="Multimodal Analyst",
model=Gemini(id="gemini-2.5-flash", api_key=gemini_api_key),
markdown=True,
)
The id parameter accepts model names like gemini-2.5-flash or gemini-exp-1206, while api_key authenticates requests to Google's generative AI platform.
Query-Rewriting RAG Agent
For retrieval-augmented generation (RAG) pipelines, Gemini serves dual purposes: rewriting user queries for better retrieval and generating final responses based on retrieved context. The rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py file demonstrates this pattern using two separate Gemini model instances.
The query rewriter uses gemini-exp-1206 to expand vague user inputs into search-optimized queries:
from agno.models.google import Gemini
query_rewriter = Agent(
model=Gemini(id="gemini-exp-1206", api_key=api_key),
instructions="Rewrite the query to be more specific for web search",
)
A second agent then consumes the rewritten query along with retrieved documents to produce the final answer, maintaining separation of concerns between retrieval optimization and response generation.
Embedding Provider for Vector Stores
Beyond text generation, you can integrate with Google Gemini for agents by using its embedding models to vectorize content for similarity search. The GeminiEmbedder class in rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py implements the LangChain Embeddings interface using models/text-embedding-004.
import google.generativeai as genai
from langchain_core.embeddings import Embeddings
class GeminiEmbedder(Embeddings):
def __init__(self, api_key: str, model_name="models/text-embedding-004"):
genai.configure(api_key=api_key)
self.model = model_name
def embed_query(self, text: str):
resp = genai.embed_content(
model=self.model,
content=text,
task_type="retrieval_document",
)
return resp["embedding"]
def embed_documents(self, texts: list):
return [self.embed_query(t) for t in texts]
This produces 768-dimensional vectors suitable for storage in Qdrant or similar vector databases, enabling semantic search capabilities within agent workflows.
Multi-Step Interactions API
For advanced agentic workflows, the Gemini Interactions API supports stateful, multi-step processes that chain planning, research, and synthesis phases. The advanced_ai_agents/single_agent_apps/research_agent_gemini_interaction_api/research_planner_executor_agent.py demonstrates a complete research pipeline.
The workflow begins by creating a plan using a lightweight model:
import google.generativeai as genai
client = genai.Client(api_key=api_key)
plan = client.interactions.create(
model="gemini-3-flash-preview",
input="Create a numbered research plan for: AI-generated music tools.",
tools=[{"type": "google_search"}],
store=True,
)
Subsequent steps reference the plan via previous_interaction_id to maintain context:
research = client.interactions.create(
agent="deep-research-pro-preview-12-2025",
input="Research the above tasks thoroughly.",
previous_interaction_id=plan.id,
background=True,
store=True,
)
This pattern supports long-running background tasks with status polling via wait_for_completion logic, enabling complex research agents that operate across multiple sessions.
Implementation Details and Code Examples
Setting Up API Authentication
All Gemini integrations require a valid API key from Google AI Studio. The repository consistently uses Streamlit sidebar inputs for key management, storing the value in session state for reuse across components.
import streamlit as st
with st.sidebar:
api_key = st.text_input("Enter your Gemini API Key", type="password")
if not api_key:
st.warning("Please provide your API key to continue")
st.stop()
# Store for downstream usage
st.session_state.google_api_key = api_key
This pattern appears in starter_ai_agents/multimodal_ai_agent/mutimodal_agent.py and ensures the key is available for both the Agno wrapper and direct Google SDK calls.
Building a Minimal Gemini Agent
For rapid prototyping, you can instantiate a functional agent in fewer than 20 lines of code using the Agno framework:
import streamlit as st
from agno.agent import Agent
from agno.models.google import Gemini
st.title("Gemini LLM Agent")
api_key = st.sidebar.text_input("Gemini API Key", type="password")
if not api_key:
st.stop()
@st.cache_resource
def get_agent(key):
return Agent(
name="Gemini Demo",
model=Gemini(id="gemini-2.5-flash", api_key=key),
markdown=True,
)
agent = get_agent(api_key)
prompt = st.chat_input("Ask Gemini...")
if prompt:
with st.chat_message("user"):
st.write(prompt)
response = agent.run(prompt).content
with st.chat_message("assistant"):
st.write(response)
This implementation from starter_ai_agents/multimodal_ai_agent/mutimodal_agent.py demonstrates the core flow: API key validation, cached agent initialization, and synchronous run() calls that return RunOutput objects containing the generated content.
Creating Custom Embeddings
When building RAG systems, you may need to customize the embedding behavior beyond the basic implementation. The GeminiEmbedder class supports both single queries and batch document processing:
import google.generativeai as genai
from langchain_core.embeddings import Embeddings
class GeminiEmbedder(Embeddings):
def __init__(self, api_key: str, model_name="models/text-embedding-004"):
genai.configure(api_key=api_key)
self.model = model_name
def embed_query(self, text: str) -> list[float]:
"""Generate embedding for a single query string."""
resp = genai.embed_content(
model=self.model,
content=text,
task_type="retrieval_document",
)
return resp["embedding"]
def embed_documents(self, texts: list[str]) -> list[list[float]]:
"""Batch process multiple documents."""
return [self.embed_query(t) for t in texts]
This code from rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py generates 768-dimensional vectors compatible with Qdrant and other vector stores, using the models/text-embedding-004 model specifically optimized for document retrieval tasks.
Orchestrating Research Workflows
The Interactions API enables complex multi-agent workflows where each step maintains context through interaction IDs. The research planner implementation demonstrates this pattern:
import google.generativeai as genai
import streamlit as st
import time
client = genai.Client(api_key=st.session_state.gemini_api_key)
# Step 1: Planning
plan = client.interactions.create(
model="gemini-3-flash-preview",
input="Create a numbered research plan for: AI-generated music tools.",
tools=[{"type": "google_search"}],
store=True,
)
st.session_state.plan_id = plan.id
# Step 2: Background Research
research = client.interactions.create(
agent="deep-research-pro-preview-12-2025",
input="Research the above tasks thoroughly.",
previous_interaction_id=plan.id,
background=True,
store=True,
)
# Step 3: Polling for completion
while research.status == "in_progress":
time.sleep(5)
research = client.interactions.get(research.id)
# Step 4: Synthesis
report = client.interactions.create(
model="gemini-3-pro-preview",
input=f"Write a comprehensive report based on: {research.outputs}",
previous_interaction_id=research.id,
store=True,
)
This implementation from advanced_ai_agents/single_agent_apps/research_agent_gemini_interaction_api/research_planner_executor_agent.py shows how to chain interactions using previous_interaction_id, execute long-running tasks with background=True, and poll for status updates before triggering dependent steps.
Key Files and Architecture
The repository organizes Gemini integrations across four primary categories, each demonstrating different architectural patterns:
| File Path | Integration Type | Key Components |
|---|---|---|
starter_ai_agents/multimodal_ai_agent/mutimodal_agent.py |
Direct LLM Agent | Gemini model wrapper, Agent.run(), Streamlit UI |
rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py |
RAG & Embeddings | GeminiEmbedder, query rewriting, Qdrant vector store |
advanced_ai_agents/single_agent_apps/research_agent_gemini_interaction_api/research_planner_executor_agent.py |
Interactions API | genai.Client, multi-step workflows, background tasks |
ai_agent_framework_crash_course/google_adk_crash_course/ |
Framework Examples | Model selection patterns, gemini-3-flash-preview usage |
These files demonstrate that integrating with Google Gemini for agents requires choosing the appropriate abstraction layer: the Agno framework for standard agent construction, the Gemini SDK directly for embeddings, or the Interactions API for stateful, multi-step research workflows.
Summary
- Direct LLM Integration: Use the
Geminiclass fromagno.models.googlewith model IDs likegemini-2.5-flashto power standard agent interactions via theAgent.run()method. - RAG Pipeline Support: Implement
GeminiEmbedderusinggoogle.generativeai.embed_contentwithmodels/text-embedding-004to generate 768-dimensional vectors for Qdrant or similar vector stores. - Advanced Workflows: Leverage the
genai.Client.interactions.create()API to build stateful, multi-step agents that chain planning, research, and synthesis phases usingprevious_interaction_idand background execution. - Authentication Pattern: Consistently use Streamlit sidebar inputs for API key management, passing keys to both the Agno wrapper and direct Google SDK calls via
api_keyparameters orgenai.configure().
Frequently Asked Questions
How do I authenticate with Google Gemini when building an agent?
You must provide a valid API key from Google AI Studio either through environment variables or direct parameter passing. In the repository examples, the pattern uses st.text_input(type="password") in a Streamlit sidebar to capture the key, then passes it to Gemini(api_key=key) for Agno agents or genai.configure(api_key=key) for direct SDK usage.
What is the difference between using Gemini through Agno versus the Interactions API?
Using Gemini through Agno (agno.models.google.Gemini) provides a high-level abstraction for standard question-answering and tool-calling agents with synchronous run() methods. The Interactions API (genai.Client.interactions.create()) offers lower-level control for stateful, multi-step workflows where you must explicitly chain interactions via previous_interaction_id, execute background tasks, and poll for completion status.
Which Gemini model should I use for embeddings in a RAG system?
For vector embeddings, use the models/text-embedding-004 model via the GeminiEmbedder class, which produces 768-dimensional vectors optimized for document retrieval. This implementation configures the Google SDK once with genai.configure(api_key=api_key) and calls genai.embed_content() with task_type="retrieval_document" for both single queries and batch document processing.
How do I handle long-running research tasks with Gemini?
Use the Interactions API with background=True when calling client.interactions.create(), which returns immediately while the research continues server-side. Store the interaction ID and poll using client.interactions.get(research.id) until status changes from "in_progress" to "completed", then retrieve the outputs for synthesis in subsequent steps.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →