Skip to content

PaulPextra/python-ai-research-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Python AI Research Agent (LangChain + Anthropic)

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.


Features

  • CLI workflow: Ask a question directly from the terminal.
  • Tool-using agent:
    • Web search via DuckDuckGo
    • Wikipedia lookup
    • Save results to a local .txt file
  • Structured output enforced with Pydantic (ResearchResponse):
    • topic
    • summary
    • sources
    • tools_used
  • Environment-based configuration using python-dotenv
  • Verbose agent tracing enabled for easier debugging (verbose=True)

Project Structure

.
├── 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
`

About

A CLI-based Python AI research agent built with LangChain and Anthropic Claude that uses DuckDuckGo and Wikipedia tools to generate Pydantic-validated, structured research outputs and optionally save results to a text file.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages