This project is a functional Python-based AI agent built using LangChain, LangGraph, and OpenAI.
It provides a real-time, command-line chat interface and demonstrates how to implement a ReAct-style agent that can reason about user input and invoke tools when needed.
The agent is designed to be simple, extensible, and easy to understand, making it a strong foundation for more advanced AI agent systems.
The goals of this project are to:
- Demonstrate how to build an AI agent using the ReAct pattern
- Enable natural language interaction via a CLI interface
- Show how tools can be integrated into agent reasoning
- Stream responses in real time for improved user experience
- Provide a clear, extensible agent architecture
The agent follows the ReAct (Reason + Act) paradigm:
- The user provides input through the terminal
- The LLM reasons about the intent of the input
- The agent decides whether to respond directly or invoke a tool
- Tool outputs are incorporated into the final response
- The response is streamed back to the user in real time
LangGraph manages the ReAct execution flow, while LangChain provides abstractions for models, tools, and message handling.
System Architecture Overview
This diagram illustrates the high-level architecture of the AI agent. The user interacts with the agent through a command-line interface. The agent coordinates reasoning using an OpenAI language model and can optionally invoke tools (such as a calculator) before returning responses to the user.
- Interactive CLI-based chat interface
- ReAct-style reasoning using LangGraph
- Tool support via LangChain decorators
- Streaming responses for conversational interaction
- Environment-based configuration using dotenv
- Minimal, readable, and extensible codebase
The project includes a simple calculator tool that:
- Accepts two numeric inputs
- Performs basic arithmetic
- Returns results in natural language
This tool demonstrates how agents can decide when to act versus when to respond directly.
- Python 3.10+
- LangChain
- LangGraph
- OpenAI API
- python-dotenv
.
├── main.py # Agent entry point
├── diagrams/
│ ├── system_architecture.png
│ └── runtime_sequence.png
├── .env.example
├── requirements.txt
└── README.md
- git clone (https://github.com/IT21314742/AI-agent.git)
- cd AI-agent
pip install -r requirements.txt
OPENAI_API_KEY=your_openai_key
python main.py
You can interact with the assistant in real time.
quit
You: What is 8 plus 12?
Assistant: The sum of 8 and 12 is 20
You: What is an AI agent?
Assistant: An AI agent is a system that can perceive input, reason about it, and take actions to achieve a goal..
-
Adding additional tools
-
Introducing conversational memory
-
Supporting multiple tools or agents
-
Switching to different LLM providers
-
Building a web or API interface
Contributions, issues, and suggestions are welcome. This project serves as a foundational example for developers exploring AI agents, LLM reasoning, and tool-augmented systems.
