A simple LangChain-based agent that conducts research, generates content, and saves findings to structured documents.
This project implements a simple, focused research assistant using LangChain and large language models. The agent can search the web, query Wikipedia, generate comprehensive documents, and automatically save research findings to files.
- Multi-source Research: Combines web search and Wikipedia data
- Structured Output: Returns findings in a standardized format
- File Storage: Automatically saves research documents with formatting
- Error Handling: Robust error management for network and API issues
- Agent-based Architecture: Uses LangChain's agent framework for complex tasks
- Python 3.8+
- Dependencies listed in
requirements.txt
-
Clone the repository:
git clone [repository-url] cd AI-Agent -
Create a virtual environment:
python -m venv venv -
Activate the virtual environment:
- Windows:
.\venv\Scripts\activate - Unix/MacOS:
source venv/bin/activate
- Windows:
-
Install dependencies:
pip install -r requirements.txt -
Set up environment variables: Create a
.envfile with your API keys:OPENAI_API_KEY=your_openai_key GOOGLE_API_KEY=your_google_key # Add other API keys as needed
Run the main script:
python main.py
Enter your research query when prompted. The agent will:
- Gather information from the web and Wikipedia
- Generate a structured research document
- Save the results to
research_output.txt
main.py: Core application with LangChain agent setuptools.py: Custom tools for search, Wikipedia, and file operationsrequirements.txt: Project dependenciesresearch_output.txt: Generated research documents
- LangChain: Framework for LLM applications and agents
- LLM Integration: Supports OpenAI, Google Gemini, and Anthropic models
- Pydantic Models: Type validation for structured output
- DuckDuckGo Search: Web search integration
- Wikipedia API: Structured knowledge source
Research documents are saved with the following structure:
- Research topic and summary
- Detailed content
- Research process documentation
- Sources and references
- Tools used
You can modify the agent's behavior by:
-
Changing the LLM provider in
main.py:llm = ChatOpenAI(model="gpt-4") # Change to your preferred model
-
Adjusting the system prompt for different instructions
-
Adding new tools to
tools.pyfor additional capabilities
- Depends on third-party API access and rate limits
- Research quality depends on the underlying LLM capabilities
- Web search results may vary in quality and relevance
MIT License