chandankumar4/ai-agent

AI Agent (Google AI Studio + LangChain)

★ 0Forks 0PythonGitHub ↗Compare

README

AI Agent (Google AI Studio + LangChain)

A lightweight research agent built with LangChain and Gemini models from Google AI Studio.

The script sends a research query to a Gemini model and parses the model output into a structured Pydantic schema.

Features

  • Uses Google Gemini via langchain-google-genai
  • Uses a structured output schema (topic, summary, sources, tools_used)
  • Uses LangChain tool-calling agent setup (currently with an empty tools list)
  • Loads secrets from .env

Project Structure

  • main.py: main agent workflow
  • requirements.txt: Python dependencies
  • .env: environment variables (local only, not committed)

Prerequisites

  • Python 3.10+
  • A Google AI Studio API key

Get your key from Google AI Studio and place it in .env as shown below.

Setup

  1. Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Expprt GOOGLE_API_KEY in the SHELL:
export GOOGLE_API_KEY=your_google_ai_studio_api_key

Run

python ./main.py

If your shell is not inside the venv, run:

./venv/bin/python ./main.py

How It Works

  1. Loads environment variables via python-dotenv.
  2. Creates ChatGoogleGenerativeAI(model="gemini-3.5-flash").
  3. Builds a prompt with output-format instructions from PydanticOutputParser.
  4. Runs a tool-calling agent.
  5. Parses the final model text into the Pydantic model.

Structured Output Schema

The expected output is parsed into this shape:

  • topic: str
  • summary: str
  • sources: list[str]
  • tools_used: list[str]

Common Issues

1) RESOURCE_EXHAUSTED / 429

You hit model quota/rate limits for your current API key or model.

What to do:

  • Wait and retry
  • Switch to another Gemini model
  • Check Google AI Studio quota/billing limits

2) Missing package errors

If you see errors like ModuleNotFoundError, ensure:

  • venv is activated
  • dependencies are installed with pip install -r requirements.txt
  • you are running the same Python interpreter where packages were installed

3) Parsing errors

If parsing fails, the model output might not strictly match the schema format. The script currently prints both the parser error and raw model response to help debugging.

Notes

  • The agent currently has tools=[]. You can add tools later and include them in the create_tool_calling_agent(...) call.

Contributors

chandankumar4

Issues