A lightweight, CLI-based AI research agent built from scratch in Python using LangChain and Anthropic Claude. The agent accepts a research prompt from the terminal, uses external tools (DuckDuckGo + Wikipedia) to gather context, produces a structured response validated by Pydantic, and optionally saves the output to a timestamped text file.
This project is a clean starting point for building tool-using agents (search + wiki + persistence) with structured outputs.
- CLI workflow: Ask a question directly from the terminal.
- Tool-using agent:
- Web search via DuckDuckGo
- Wikipedia lookup
- Save results to a local
.txtfile
- Structured output enforced with Pydantic (
ResearchResponse):topicsummarysourcestools_used
- Environment-based configuration using
python-dotenv - Verbose agent tracing enabled for easier debugging (
verbose=True)
.
├── main.py # Entry point: prompt, agent, execution, parsing
├── tools.py # Tool definitions: search, wikipedia, save-to-file
├── .env.example # Example environment config (recommended)
└── research_output.txt (generated) # Output file created after tool usage
## Requirements
- Python 3.10+ recommended
- An Anthropic API key
- Installed dependencies from *requirements.txt* file
## Setup
1. Clone the repository
2. Create & activate a virtual environment
3. Install dependencies (`pip install -r requirements.txt`)
4. Create a .env file in the project root (set ANTHROPIC_API_KEY=your_anthropic_key_here)
## Running the Agent
`
python main.py
`