# How to Configure Hiring Agent to Use Google Gemini: Complete Setup Guide

> Easily configure Hiring Agent to use Google Gemini. Set GEMINI_API_KEY and LLM_PROVIDER=gemini in your .env file for a seamless setup. Learn how now.

- Repository: [HackerRank/hiring-agent](https://github.com/interviewstreet/hiring-agent)
- Tags: how-to-guide
- Published: 2026-07-03

---

**Set the `GEMINI_API_KEY` environment variable and specify `LLM_PROVIDER=gemini` in your `.env` file to switch the Hiring Agent from the default Ollama backend to Google Gemini.**

The Hiring Agent by InterviewStreet supports multiple LLM backends, including **Ollama** (default) and **Google Gemini**. To configure the agent to use Gemini, you must provide an API key and select a supported Gemini model name. This guide walks through the configuration process using the actual source code implementation.

## Prerequisites

### Obtain a Gemini API Key

Before configuring the Hiring Agent, you need a valid Google Gemini API key from Google AI Studio. The application expects this key to be available as the `GEMINI_API_KEY` environment variable.

## Configuration Steps

### Step 1: Configure Environment Variables

The Hiring Agent loads environment variables from `.env` files via `python-dotenv`. In [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py), lines 12-18, the code calls `load_dotenv()` and then reads `GEMINI_API_KEY` (falling back to an empty string if unset).

Create your environment file by copying the template:

```bash
cp main/.env.example .env

```

Edit the `.env` file to set the required variables:

```bash
LLM_PROVIDER=gemini
GEMINI_API_KEY=your_actual_gemini_api_key_here
DEFAULT_MODEL=gemini-2.5-pro

```

The [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py) module validates these settings at runtime. Lines 66-68 retrieve the API key using `os.getenv("GEMINI_API_KEY")`, while lines 36-44 and 55-63 map model names like `gemini-2.5-pro` to the `ModelProvider.GEMINI` enum.

### Step 2: Select a Gemini Model

In [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py), the application maintains a mapping between model names and providers. Any model name starting with `gemini-` (such as `gemini-2.5-pro` or `gemini-2.5-flash`) automatically resolves to the Gemini provider. Set your preferred model using the `DEFAULT_MODEL` environment variable.

### Step 3: Install Dependencies

Ensure the Google Generative AI SDK is installed:

```bash
pip install -r requirements.txt

```

The [`requirements.txt`](https://github.com/interviewstreet/hiring-agent/blob/main/requirements.txt) should include the `google-generativeai` package required by the Gemini provider implementation.

## How the Gemini Integration Works

### Environment Loading in prompt.py

The configuration flow begins in [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py), where `load_dotenv()` processes your `.env` file. The module exposes the API key as a module-level variable, making it available to the provider factory. Lines 12-18 handle the dotenv loading, while lines 66-68 expose `GEMINI_API_KEY` to the rest of the application.

### Provider Implementation in models.py

The `GeminiProvider` class in [`main/models.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/models.py) (lines 13-21) handles the Gemini API connection. Its constructor receives the API key and immediately calls `google.generativeai.configure(api_key=...)` to initialize the client. Lines 31-38 store this configured client for subsequent chat operations.

### Chat Request Handling

When processing requests, the `GeminiProvider.chat()` method (lines 48-66 in [`main/models.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/models.py)) instantiates a `GenerativeModel` using the model name specified in your configuration. It applies generation parameters (temperature, top-p) from `MODEL_PARAMETERS` defined in [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py), then forwards messages to the Gemini API. Lines 70-78 handle the response parsing and format conversion to match the application's internal message schema.

## Configuration Examples

### Basic Environment Setup

```bash

# From the repository root

cp main/.env.example .env

# Edit .env to include:

# LLM_PROVIDER=gemini

# GEMINI_API_KEY=AIzaSy...

# DEFAULT_MODEL=gemini-2.5-pro

```

### Running the Agent with Gemini

```bash
python -m main.evaluate path/to/resume.json

```

The script will automatically instantiate `GeminiProvider` using your configured API key and model.

### Programmatic Configuration

If you prefer not to use a `.env` file, set variables before importing the agent modules:

```python
import os

os.environ["LLM_PROVIDER"] = "gemini"
os.environ["DEFAULT_MODEL"] = "gemini-2.5-flash"
os.environ["GEMINI_API_KEY"] = "AIzaSy..."

# Import after environment setup

from main.evaluate import evaluate_resume

```

This works because [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py) reads environment variables at import time.

## Troubleshooting

### API Key Validation

The Hiring Agent validates the presence of the Gemini API key before attempting API calls. If `GEMINI_API_KEY` is empty or unset, the application raises an error early in the initialization process (handled in [`llm_utils.py`](https://github.com/interviewstreet/hiring-agent/blob/main/llm_utils.py) and [`prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/prompt.py) line 66-68). Ensure your `.env` file is in the correct directory and that the variable name matches exactly.

## Summary

- **Set `GEMINI_API_KEY`** in your `.env` file or environment to authenticate with Google Gemini.
- **Set `LLM_PROVIDER=gemini`** to switch from the default Ollama backend.
- **Choose a Gemini model** via `DEFAULT_MODEL` (e.g., `gemini-2.5-pro`); the system automatically maps these to the Gemini provider in [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py) lines 36-44.
- **Install dependencies** including `google-generativeai` to support the `GeminiProvider` class in [`main/models.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/models.py).
- **Validation occurs early**: The application checks for the API key before initializing the provider, preventing silent failures.

## Frequently Asked Questions

### What happens if I don't set GEMINI_API_KEY?

The Hiring Agent will raise a validation error during initialization. According to the source code in [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py) (lines 66-68) and validation logic in [`llm_utils.py`](https://github.com/interviewstreet/hiring-agent/blob/main/llm_utils.py), the application explicitly checks for the presence of the API key before constructing the `GeminiProvider` instance. Without this key, the agent cannot authenticate with Google's API.

### Can I use other Gemini models like gemini-2.5-flash?

Yes. The model mapping in [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py) (lines 55-63) supports any model name prefixed with `gemini-`. Simply set `DEFAULT_MODEL=gemini-2.5-flash` in your `.env` file. The system will resolve this to `ModelProvider.GEMINI` and pass the model name to the `GenerativeModel` constructor in [`main/models.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/models.py) (lines 48-52).

### How do I switch back to Ollama?

Change the `LLM_PROVIDER` environment variable to `ollama` or simply remove the `GEMINI_API_KEY` variable and ensure your chosen model name is one supported by Ollama. The provider selection logic in [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py) maps model names to providers; if you select a non-Gemini model, the system will instantiate the Ollama provider instead.

### Where does the Hiring Agent store the API key configuration?

The application does not store the API key in code; it reads from environment variables at runtime. In [`main/prompt.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/prompt.py), lines 12-18, the `load_dotenv()` function reads from `.env` files, and lines 66-68 retrieve the key using `os.getenv("GEMINI_API_KEY")`. This key is then passed to the `GeminiProvider` constructor in [`main/models.py`](https://github.com/interviewstreet/hiring-agent/blob/main/main/models.py) (lines 13-21) without persisting to disk.