A simple AI-powered calculator agent built with LangChain and LangGraph. The agent can perform basic arithmetic operations (addition, subtraction, multiplication, division) by interpreting natural language instructions.
- Performs sequential arithmetic operations based on user queries.
- Uses OpenAI's GPT-4 for reasoning and tool calling.
- Handles errors gracefully (e.g., division by zero).
- Python 3.8+
- OpenAI API keys
- Clone or download the repository.
- Install dependencies:
pip install langchain-openai langgraph python-dotenv - Create a
.envfile in the project root and add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key_here
Run the example script:
python User.py
This will execute a sample arithmetic sequence and print the results.
calculator_agent.py: Defines the agent, tools, and graph.User.py: Example usage script.
The agent uses LangGraph to manage a conversation flow:
- Receives a user query.
- Calls appropriate arithmetic tools.
- Returns the final result.
For more details, see the code comments.