A local AI agent project powered by Ollama, LangChain, and LangGraph. The agent runs on your machine, can use tools, remembers conversation context, and includes both command-line and web interfaces.
- Local LLM support through Ollama
- ReAct-style agent workflow using LangChain and LangGraph
- Calculator tool for math expressions
- Knowledge base tool for technical topics
- Date and time tool
- Conversation memory support
- Streamlit chat UI
- FastAPI backend for API-based chat
- React + Vite frontend
- Unit tests for tools
Basic_Agent/
+-- agent.py # Basic agent example
+-- agent_with_memory.py # Agent with conversation memory
+-- agent_langgraph.py # LangGraph-based agent
+-- app.py # Streamlit web app
+-- config.py # Environment-based configuration
+-- setup.py # Local setup checker
+-- requirements.txt # Python dependencies
+-- backend/
| +-- api.py # FastAPI backend
+-- frontend/
| +-- package.json # React frontend dependencies
| +-- src/ # Frontend source files
+-- tools/
| +-- calculator.py
| +-- datetime_tool.py
| +-- knowledge_base.py
+-- tests/
+-- test_tools.py
- Python 3.9 or newer
- Node.js and npm, for the React frontend
- Ollama installed locally
- An Ollama model such as
phi3,llama3.2, ormistral
Clone the project and enter the folder:
git clone https://github.com/YOUR_USERNAME/Basic_Agent.git
cd Basic_AgentCreate and activate a virtual environment:
python -m venv venv
venv\Scripts\activateInstall Python dependencies:
pip install -r requirements.txtInstall Ollama from:
https://ollama.com/download
Pull a local model:
ollama pull phi3Start Ollama:
ollama serveCreate a .env file in the project root:
OLLAMA_MODEL=phi3
OLLAMA_BASE_URL=http://localhost:11434
TEMPERATURE=0.1
MAX_TOKENS=1024The .env file is ignored by Git, so your local settings stay private.
Run the basic agent:
python agent.pyRun the memory-enabled agent:
python agent_with_memory.pyRun the LangGraph agent:
python agent_langgraph.pyRun the Streamlit web UI:
streamlit run app.pyIf needed, install API dependencies:
pip install fastapi uvicorn pydanticStart the API server:
uvicorn backend.api:app --reload --port 8000Useful API endpoints:
GET /health
GET /tools
POST /chat
GET /sessions
GET /sessions/{session_id}
DELETE /sessions/{session_id}
Open a second terminal:
cd frontend
npm install
npm run devThe frontend usually runs at:
http://localhost:5173
Make sure the FastAPI backend is running on port 8000 before using the frontend chat.
| Tool | Purpose | Example |
|---|---|---|
| Calculator | Evaluates math expressions | sqrt(144), 2**10 |
| Knowledge Base | Looks up technical topics | python, langchain, ollama |
| DateTime | Returns current date and time | date, time, full |
python -m pytest tests -vIf this is a new repository:
git init
git branch -M main
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/YOUR_USERNAME/Basic_Agent.git
git push -u origin mainReplace YOUR_USERNAME with your GitHub username.
- Do not commit
.env,venv/,__pycache__/,frontend/node_modules/, or build output. - Keep Ollama running before starting the agent.
- Use a model that works well with tool calling for best results.