An autonomous AI agent built with LangGraph that performs intelligent web research and data retrieval through a multi-step reasoning system.
This project demonstrates a graph-based AI agent capable of autonomous decision-making and tool usage. The agent operates through interconnected functional nodes that enable sophisticated web research workflows.
- Intelligent Web Search: Conducts contextual Google searches using SerpAPI to discover relevant resources
- Dynamic Data Retrieval: Fetches and processes live content from discovered URLs via HTTP GET requests
- Multi-Step Reasoning: Implements a state graph architecture for complex decision-making
- Tool Integration: Seamlessly switches between search and fetch operations based on query requirements
- Interactive Interface: Command-line interface for natural conversation with the agent
The agent uses LangGraph's StateGraph to orchestrate three main nodes:
- LLM Node: Processes user queries and decides which tools to use
- Tools Node: Executes selected tools (web search or URL fetching)
- LLM Explain Node: Synthesizes results into human-readable responses
- Python 3.8+
- OpenAI API key
- SerpAPI key
- Clone the repository:
git clone https://github.com/yourusername/langgraph-agent.git cd langgraph-agent- Install required packages:
pip install langgraph langchain langchain-openai langchain-community google-search-results requests python-dotenv- Create a
.envfile in the project root:
OPENAI_API_KEY=your_openai_api_key_here SERPAPI_API_KEY=your_serpapi_key_hereRun the agent:
python agent.pyThe agent will prompt you to enter queries. Examples:
- "Search for weather APIs"
- "Find information about machine learning trends"
- "Get data from https://api.example.com/data"
Type your query and press Enter. The agent will autonomously decide whether to search the web or fetch URL content based on your request.
langgraph-agent/ ├── agent.py # Main agent implementation ├── .env # Environment variables (not tracked in git) ├── .gitignore # Git ignore file └── README.md # This file - User enters a query through the command-line interface
- The LLM analyzes the query and selects appropriate tools
- Tools execute (web search or URL fetch)
- Results are processed and synthesized by the LLM
- Final response is presented to the user
- Conversation context is maintained for follow-up queries
- search_tool2: Performs Google searches using SerpAPI to find relevant information
- fetch_url_content: Sends HTTP GET requests to retrieve content from URLs
Never commit your .env file or expose API keys in your code. This project uses environment variables to keep credentials secure.
- LangGraph: Graph-based agent orchestration
- LangChain: LLM integration and tool management
- OpenAI GPT-3.5: Language model for reasoning and response generation
- SerpAPI: Web search capabilities
- Python Requests: HTTP client for data retrieval
MIT License
Contributions are welcome! Please feel free to submit a Pull Request.
Built as a demonstration of autonomous agent capabilities using LangGraph's state management and tool integration features.