A sample AI Agent project built with LangChain and LangGraph frameworks, implementing the ReAct (Reasoning and Acting) pattern to create an intelligent agent capable of calling tools and interacting with users.
This project demonstrates how to build an AI agent that can:
- Understand user queries through natural language processing
- Use the ReAct pattern for reasoning and tool selection
- Execute specific tools based on user requests
- Provide interactive conversational experience
- LangChain Integration: Utilizes LangChain for language model interactions
- LangGraph Framework: Implements agent workflows using LangGraph
- ReAct Pattern: Reasoning and Acting pattern for intelligent decision making
- Tool Integration: Custom tools for specific functionalities
- Local Model Support: Uses Ollama with Mistral model for local inference
- Interactive CLI: Command-line interface for user interaction
- Greeting Tool: Provides personalized greetings to users
- Calculator Tool: Performs basic arithmetic operations (addition)
User Input → LangGraph Agent → ReAct Processing → Tool Selection → Tool Execution → Response
The agent uses the ReAct pattern to:
- Observe the user input
- Think about what action to take
- Act by calling appropriate tools
- Observe the results and provide response
- Python 3.8+
- Ollama installed locally with Mistral model
- Required Python packages (see requirements.txt)
- Clone the repository:
git clone https://github.com/MelikaMirdamadi/AI_Agent_Project.git
cd AI_Agent_Project- Create a virtual environment:
python -m venv venv
venv\Scripts\activate # On Windows
# source venv/bin/activate # On macOS/Linux- Install dependencies:
pip install -r requirement.txt- Install and setup Ollama:
# Download Ollama from https://ollama.ai/
# Pull the Mistral model
ollama pull mistral- Create a .env file (if needed for additional configurations)
- Start the AI agent:
python main.py- Interact with the agent:
Hello, welcome, I'm AI assistant, ask me your question , and type 'exit' to quit
You: Hello, my name is John
AI: [Agent will use greeting tool and respond]
You: What is 5 + 3?
AI: [Agent will use calculator tool and respond]
You: exit
Goodbye!
AI_Agent_Project/
├── main.py # Main application file
├── requirement.txt # Python dependencies
├── Readme.txt # Project documentation
└── .env # Environment variables (optional)
Key dependencies include:
langchain-core: Core LangChain functionalitylanggraph: Graph-based agent frameworklangchain-ollama: Ollama integration for LangChainpython-dotenv: Environment variable management
To add new tools:
- Define a new tool using the
@tooldecorator:
@tool
def your_tool_name(param: type) -> str:
"""
Description of what your tool does
"""
# Your tool implementation
return result- Add the tool to the tools list in main():
tools = [greeting, calculator, your_tool_name]- Model: Mistral via Ollama (local inference)
- Agent Type: ReAct agent with tool calling capabilities
- Framework: LangGraph prebuilt agent executor
- Streaming: Real-time response streaming for better user experience
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
- Add more utility tools (weather, web search, file operations)
- Implement memory for conversation history
- Add configuration file for model selection
- Create web interface using Streamlit or FastAPI
- Add logging and error handling
- Implement tool validation and safety checks
Error: "Expected a Runnable, callable or dict"
- Ensure you're using
ChatOllamafromlangchain_ollamainstead of directollama.chat()
Model not found error
- Make sure Ollama is running and Mistral model is pulled:
ollama pull mistral
Import errors
- Verify all dependencies are installed:
pip install -r requirement.txt
This project is open source and available under the MIT License.
For questions or suggestions, please open an issue in the GitHub repository.