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.
- 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
main.py: main agent workflowrequirements.txt: Python dependencies.env: environment variables (local only, not committed)
- Python 3.10+
- A Google AI Studio API key
Get your key from Google AI Studio and place it in .env as shown below.
- Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Expprt GOOGLE_API_KEY in the SHELL:
export GOOGLE_API_KEY=your_google_ai_studio_api_keypython ./main.pyIf your shell is not inside the venv, run:
./venv/bin/python ./main.py- Loads environment variables via
python-dotenv. - Creates
ChatGoogleGenerativeAI(model="gemini-3.5-flash"). - Builds a prompt with output-format instructions from
PydanticOutputParser. - Runs a tool-calling agent.
- Parses the final model text into the Pydantic model.
The expected output is parsed into this shape:
topic: strsummary: strsources: list[str]tools_used: list[str]
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
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
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.
- The agent currently has
tools=[]. You can add tools later and include them in thecreate_tool_calling_agent(...)call.