Intelligent Research Assistant with Multi-Tool Integration
An advanced AI-powered search and research agent that leverages multiple tools including web search, Wikipedia lookup, and file operations to provide comprehensive research capabilities with automatic output saving and structured responses.
- π§ Intelligent Research - Multi-source research using web search and Wikipedia
- π Web Search Integration - Real-time web search via DuckDuckGo
- π Wikipedia Integration - Comprehensive encyclopedia lookup
- π€ Tool-Calling Agent - Advanced LangChain agent with structured outputs
- π Structured Responses - Pydantic-based response formatting with validation
Example screenshots (stored in imgs/):
Backend: Python 3.8+, LangChain, OpenAI GPT-4o
Search Tools: DuckDuckGo Search, Wikipedia API
Data Processing: Pydantic for structured outputs and validation
Agent Framework: LangChain tool-calling agent architecture
The system uses a sophisticated tool-calling agent architecture built with LangChain:
- π€ LangChain Agent - Tool-calling agent with GPT-4o integration
- π Search Tools - Web search and Wikipedia lookup capabilities
- οΏ½ Structured Output - Pydantic models for consistent response formatting
- π― Prompt Engineering - Optimized prompts for research tasks
- π Web Search -
DuckDuckGoSearchRunfor real-time web information - π Wikipedia -
WikipediaQueryRunfor encyclopedia content
- π Query Input - User provides research topic or question
- π€ Agent Processing - LangChain agent analyzes query and selects appropriate tools
- οΏ½ Information Gathering - Tools execute searches and retrieve relevant data
- π Response Generation - GPT-4o synthesizes information into structured output
- π Structured Output - Results returned in standardized ResearchResponse format
class ResearchResponse(BaseModel):
topic: str # Main research topic
summary: str # Comprehensive summary of findings
sources: list[str] # List of sources used
tools_used: list[str] # Tools utilized in research- Python 3.8+
- OpenAI API key
- Git
- Clone the repository
git clone https://github.com/Haythem532002/ai-search-agent.git
cd ai-search-agent- Set up Python virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Configure environment variables
Create a .env file and add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_hereStart the research agent
python main.pyThe agent will automatically research the default query: "What is the capital of Tunisia"
Modify the query in main.py:
raw_response = agent_executor.invoke(
{"query": "Your research question here"})# Example queries you can try:
queries = [
"What are the latest developments in AI?",
"Explain quantum computing basics",
"What is the history of machine learning?",
"How does blockchain technology work?"
]AI-Search-Agent/
βββ app.py # Flask API server (primary backend)
βββ main.py # Legacy or alternate entrypoint (may be duplicate)
βββ tools.py # Tool definitions and implementations
βββ my-app/ # Next.js frontend application
βββ imgs/ # Example screenshots and images
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (API keys) - not committed
βββ .gitignore # Git ignore configuration
βββ README.md # Project documentation
βββ venv/ # Python virtual environment (optional)
βββ .git/ # Git repository metadata
Note: Prefer running app.py as the primary server (python app.py). If main.py exists it may be an older/duplicate server β run only one server to avoid port conflicts.
# Test the agent with a simple query
python main.py
# Test individual tools
python -c "from tools import search_tool, wiki_tool, save_tool; print('Tools imported successfully')"
# Test OpenAI connection
python -c "from langchain_openai import ChatOpenAI; llm = ChatOpenAI(model='gpt-4o'); print('OpenAI connection OK')"# Test web search
python -c "from tools import search_tool; print(search_tool.run('Python programming'))"
# Test Wikipedia search
python -c "from tools import wiki_tool; print(wiki_tool.run('Artificial Intelligence'))"
# Test file saving
python -c "from tools import save_tool; print(save_tool.run('Test data'))"# Example test script
from main import agent_executor
test_queries = [
"What is machine learning?",
"History of the internet",
"Climate change effects"
]
for query in test_queries:
response = agent_executor.invoke({"query": query})
print(f"Query: {query}")
print(f"Response: {response}")
print("-" * 50)- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Install development dependencies (
pip install -r requirements.txt) - Make your changes with proper tests
- Commit your changes (
git commit -m 'Add AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow PEP 8 for Python code
- Use type hints where appropriate
- Write docstrings for functions and classes
- Test new features before submitting
- Update documentation for new functionality
- Use conventional commits for clear history
To add a new tool to the agent:
- Create the tool in
tools.py:
def your_new_tool(query: str) -> str:
# Your tool implementation
return result
new_tool = Tool(
name="YourTool",
func=your_new_tool,
description="Description of what your tool does"
)- Add it to the tools list in
main.py:
tools = [search_tool, wiki_tool, save_tool, new_tool]- β‘ Response Times: Typical query response under 10-15 seconds
- π― Accuracy: High-quality responses with multi-source validation
- πΎ Storage: Automatic research output persistence
- π Search Quality: Dual-source information gathering (web + Wikipedia)
- π Output Format: Structured, validated responses with Pydantic
- οΏ½ API Key Management: Store OpenAI API key in
.envfile - π File Security: Research outputs saved locally with timestamps
- π‘οΈ Input Validation: Pydantic models ensure data integrity
- π« Rate Limiting: Be mindful of OpenAI API usage limits
- π Search Safety: DuckDuckGo provides safe web search results
- π PDF Processing - Add document ingestion capabilities
- ποΈ Database Integration - Store research results in database
- π Web Interface - Add Flask/FastAPI web frontend
- π Analytics Dashboard - Track research patterns and topics
- π Batch Processing - Process multiple queries simultaneously
- π― Source Ranking - Implement source credibility scoring
This project is licensed under the MIT License. See the LICENSE file for details.
- π¦ LangChain for the excellent agent framework and tool integration
- π€ OpenAI for providing the powerful GPT-4o language model
- π DuckDuckGo for privacy-focused web search capabilities
- π Wikipedia for comprehensive encyclopedia content
- οΏ½ Pydantic for robust data validation and parsing
Built with β€οΈ using Modern AI & Agent Architecture



