# How to Integrate with Google Gemini for Agents: 4 Proven Patterns from the Awesome LLM Apps Repository

> Learn how to integrate Google Gemini with AI agents using 4 proven patterns straight from the Awesome LLM Apps repository. Enhance your agent's capabilities today.

- Repository: [Shubham Saboo/awesome-llm-apps](https://github.com/shubhamsaboo/awesome-llm-apps)
- Tags: how-to-guide
- Published: 2026-02-16

---

**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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/starter_ai_agents/multimodal_ai_agent/mutimodal_agent.py), the implementation instantiates the model with specific version identifiers:

```python
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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/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:

```python
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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/rag_tutorials/gemini_agentic_rag/agentic_rag_gemini.py) implements the LangChain `Embeddings` interface using `models/text-embedding-004`.

```python
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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/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:

```python
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:

```python
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.

```python
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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/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:

```python
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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/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:

```python
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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/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:

```python
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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/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`](https://github.com/Shubhamsaboo/awesome-llm-apps/blob/main/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 `Gemini` class from `agno.models.google` with model IDs like `gemini-2.5-flash` to power standard agent interactions via the `Agent.run()` method.
- **RAG Pipeline Support**: Implement `GeminiEmbedder` using `google.generativeai.embed_content` with `models/text-embedding-004` to 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 using `previous_interaction_id` and 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_key` parameters or `genai.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.