Jarvis — an interactive command-line research assistant built with LangChain and Google's Gemini model. Ask it questions in a continuous session, and it uses web search and Wikipedia tools to gather information, returning a structured, nicely formatted summary each time — with the option to save findings to a file.
- Runs as an interactive loop , ask multiple research questions in one session without restarting the script
- Uses an LLM-powered agent (Gemini
2.5-flash) that can call tools as needed:- Web search (DuckDuckGo) for current, general information
- Wikipedia lookup for background/reference information
- Save to file to persist structured findings to
research_output.txt
- Parses the agent's final answer into a structured response with
topic,summary,source, andtools_usedfields, using Pydantic for validation - Displays results in a formatted
richpanel plus a plain-text breakdown (topic, summary, sources, tools used), with a spinner shown while researching - Handles empty input,
exit/quit/qcommands,Ctrl+Cinterruption, and unexpected errors gracefully — the loop keeps running instead of crashing on a single bad query
- Python 3.9+
- A Google AI API key (for Gemini) — see Google AI Studio to get one
- Clone the repo:
git clone https://github.com/<your-username>/ai-research-agent.git
cd ai-research-agent- Create and activate a virtual environment:
python -m venv venv
# macOS/Linux
source venv/bin/activate
# Windows
venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtNote: rename
requirement.txttorequirements.txtbefore publishing —pip install -r requirements.txtexpects that exact filename by convention, and most people (and CI tools) won't think to look for anything else.
- Create a
.envfile in the project root with your API key:
GOOGLE_API_KEY=your_key_here
- Run the agent:
python main.py- Ask a research question at the prompt:
>>> Recent advances in solid-state batteries
Keep asking questions in the same session — type exit, quit, or q when you're done. Each query is researched independently (there's no memory of earlier questions in the session yet — see Limitations below).
The agent will search, reason about what it finds, and print a formatted panel plus a plain-text breakdown of the topic, summary, sources, and tools used. If it saves results, they'll be appended to research_output.txt.
.
├── main.py # Entry point: sets up the LLM, prompt, and agent executor
├── tools.py # Tool definitions: web search, Wikipedia, save-to-file
├── requirements.txt # Python dependencies
└── research_output.txt # Created automatically when the save tool is used
tools.pydefines three LangChainToolobjects: a DuckDuckGo search wrapper, a Wikipedia query tool (limited to 1 result, 100 characters, to keep responses concise), and a file-saving utility that timestamps and appends research output.main.pybuilds aChatPromptTemplateinstructing the model to act as a research assistant and return output in a fixed format, defined by a Pydantic model (ResearchResponse). It creates a tool-calling agent viacreate_tool_calling_agentand runs it through anAgentExecutor.- The
research()function wraps a single query: it invokes the agent (showing arichstatus spinner while it works), parses the raw output into the structuredResearchResponsemodel, and prints both a formatted panel and a plain-text breakdown. Since agent output format can vary (plain string vs. a list of content blocks), the parsing step handles both cases before validating with Pydantic. - The main loop reads input continuously, handling
exit/quit/q, blank input,Ctrl+C, and any other exception fromresearch()without crashing the whole program — each is caught and reported, then the loop continues (except for a deliberate exit).
- No memory between queries — each question in a session is researched independently, with no awareness of earlier questions or answers (the
chat_historyplaceholder in the prompt is never actually populated) - Error handling is broad (a single
except Exception) rather than specific — a missing API key, a network timeout, and a parsing failure all get the same generic message - Wikipedia results are capped very short (100 characters) — may lose useful context on complex topics
- No test suite yet
- Could be extended with:
- A simple web UI (Streamlit/Gradio) instead of terminal-only interaction
- Support for additional LLM providers (the dependencies already include OpenAI/Anthropic LangChain integrations, unused so far)
- Real conversation memory — actually populating
chat_historyso follow-up questions can reference earlier answers - Structured citation formatting instead of a flat source list
- More specific error handling (e.g. a clear message when
GOOGLE_API_KEYis missing, rather than surfacing whatever the SDK raises) - Unit tests for the tools and the output-parsing logic