A professional intelligent agent using ReAct (Reasoning and Acting) methodology to solve mathematical integrals and visualize results with full persistence in PostgreSQL.
This project implements a sophisticated ReAct (Reasoning and Acting) agent that combines advanced AI capabilities with mathematical computation tools. The agent can understand natural language requests for integral calculus problems, reason about the appropriate solution approach, execute calculations, and generate visualizations.
- ReAct Agent: Intelligent reasoning and action cycles using LangGraph
- BigTool Integration: Automatic tool selection via semantic search
- Google Gemini 2.5 Flash: Advanced LLM for mathematical reasoning
- Interactive Visualizations: Dynamic plots with Matplotlib and Plotly
- Full Persistence: PostgreSQL for conversations, cache, and metrics
- Web Interface: Professional Streamlit application
- Docker Deployment: Complete containerized solution
- Comprehensive Testing: Professional test suite with Jupyter notebooks
The project includes a comprehensive suite of Jupyter notebooks for testing, debugging, and development:
00_master_test_suite.ipynb
- Orchestrates all tests with comprehensive reporting
01_environment_test.ipynb
- Environment and dependency validation02_agent_core_test.ipynb
- Core agent components testing03_workflow_integration_test.ipynb
- End-to-end workflow testing04_database_test.ipynb
- Database integration and persistence05_bigtool_integration_test.ipynb
- BigTool semantic search testing06_error_debugging.ipynb
- Comprehensive error detection and debugging07_performance_optimization.ipynb
- Performance analysis and load testing
# Start the environment
make up
# Run Jupyter Lab to access notebooks
make jupyter
# Or run automated test validation
make test-notebooks
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PRESENTATION LAYER β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
β β Streamlit UI β β Jupyter Lab β β REST API β β
β βββββββββββ¬ββββββββ βββββββββββββββββββ βββββββββββββββ β
βββββββββββββ¬β΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Input: "Calculate integral of x^2 from 0 to 3"
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β LANGGRAPH REACT WORKFLOW β
β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββββββ β
β β THINK ββββββΆβ ACT ββββββΆβ OBSERVE β β
β β β β β β β β
β β β’ Analyze β β β’ Select β β β’ Evaluate β β
β β request β β tools β β results β β
β β β’ Plan β β β’ Execute β β β’ Check β β
β β approach β β actions β β completion β β
β β β’ Reason β β β’ Call APIs β β β’ Learn from β β
β β about β β β’ Calculate β β feedback β β
β β math β β integrals β β β’ Decide next β β
β βββββββ¬ββββββββ βββββββ¬ββββββββ βββββββββ¬ββββββββββ β
β β β β β
β β βΌ β β
β β βββββββββββββββββββββββββββββββββββ β β
β β β Google Gemini 2.5 Flash β β β
β β β (Mathematical Reasoning & β β β
β β β Natural Language Processing) β β β
β β βββββββββββββββββββββββββββββββββββ β β
β β β β
β βββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββ€
β β
β βββββββββββββ WORKFLOW CYCLE βββββββββββββββββββββββββ β
β β Continue until problem is solved OR max iterations β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββ
β TOOL MANAGEMENT LAYER β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β BigTool Registry β β
β β (Semantic Tool Selection) β β
β β β β
β β "I need to calculate an integral" β IntegralTool β β
β β "Show me a plot" β PlotTool β β
β β "Analyze the result" β AnalysisTool β β
β βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββ β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β β βIntegralTool β β PlotTool β βAnalysisTool β β β
β β β β β β β β β β
β β ββ’ SymPy β ββ’ Matplotlib β ββ’ Statistics β β β
β β ββ’ SciPy β ββ’ Plotly β ββ’ Validation β β β
β β ββ’ Numerical β ββ’ Interactiveβ ββ’ Error Checkβ β β
β β β Integrationβ β Plots β ββ’ Result Evalβ β β
β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββ
β PERSISTENCE LAYER β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
β β PostgreSQL β β Vector Store β β Cache β β
β β β β (Embeddings) β β (Memory) β β
β ββ’ Conversations β ββ’ Tool Vectors β ββ’ Results β β
β ββ’ Agent State β ββ’ Semantic Index β ββ’ Sessions β β
β ββ’ Workflow Steps β ββ’ Search History β ββ’ Temp Data β β
β ββ’ Results Cache β ββ’ User Patterns β ββ’ Tool Cache β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The system follows a layered architecture with clear separation of concerns:
- Presentation Layer: Streamlit web interface for user interaction
- Agent Layer: ReAct agent powered by LangGraph for reasoning and decision-making
- Tool Layer: Specialized mathematical tools managed by BigTool for intelligent selection
- Data Layer: PostgreSQL database for persistence and conversation history
- LLM Integration: Google Gemini 2.5 Flash for natural language processing and mathematical reasoning
The agent uses BigTool's semantic search to automatically select the most appropriate tools (IntegralTool, PlotTool, AnalysisTool) based on user requests, ensuring efficient and accurate responses.
- AI Framework: LangChain Core 0.3.72 + LangGraph 0.6.2
- LLM Provider: Google Gemini 2.5 Flash (AI Studio)
- Tool Management: BigTool 0.0.3 for intelligent tool selection
- Database: PostgreSQL with vector extensions
- Frontend: Streamlit for web interface
- Mathematical Libraries: SciPy, NumPy, SymPy, Matplotlib
- Deployment: Docker + Docker Compose
- Development: Poetry for dependency management
- Docker and Docker Compose
- Google AI Studio API Key (Get it here)
-
Clone the repository
git clone <repository-url> cd Agent_1
-
Configure environment
cp .env.example .env # Edit .env and add your Google API key
-
Start services
make setup make up
-
Verify installation
make test make health
- Streamlit Application: http://localhost:8501
- Jupyter Lab: http://localhost:8888
- PostgreSQL: localhost:5432 (user: agent_user, pass: agent_pass)
Open the Streamlit interface and try:
Calculate the integral of x^2 from 0 to 3 and visualize the area under the curve
# View all available commands
make help
# Start development environment
make dev
# Monitor services
make status
make logs
# Quality checks
make test
make lint
make format
# Database operations
make db-shell
make db-reset
If you prefer local development without Docker:
-
Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
-
Install dependencies
poetry install
-
Start PostgreSQL
docker-compose up postgres -d
-
Run the application
poetry shell poetry run streamlit run app/main.py
Interactive notebooks for testing and development:
# Open Jupyter Lab
make jupyter
# Test all notebooks
make notebook-test
# Test specific notebooks
make notebook-env # Environment tests
make notebook-math # Mathematical tools
make notebook-agent # ReAct agent tests
make notebook-db # Database tests
# All tests
make test
# Unit tests only
poetry run pytest tests/unit/ -v
# Integration tests
poetry run pytest tests/integration/ -v
# Coverage report
poetry run pytest --cov=app --cov-report=html
# Specific test suites
poetry run pytest tests/unit/test_persistence.py -v
poetry run pytest tests/unit/test_bigtool_integration.py -v
Create a .env
file with the following configuration:
# Required
GOOGLE_API_KEY=your_google_api_key_here
DATABASE_URL=postgresql://agent_user:agent_pass@localhost:5432/react_agent_db
# Optional
DEBUG=true
ENVIRONMENT=development
LOG_LEVEL=INFO
# BigTool Configuration
BIGTOOL_INDEX_BATCH_SIZE=100
BIGTOOL_SEARCH_LIMIT=5
# Cache Settings
CALCULATION_CACHE_TTL_HOURS=24
CONVERSATION_HISTORY_LIMIT=100
PostgreSQL extensions required:
CREATE EXTENSION IF NOT EXISTS vector; -- For embeddings
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- For UUIDs
User: "Calculate the integral of x^2 from 0 to 2"
Agent:
Think: I need to compute the definite integral of x^2 over [0,2]
Act: Using IntegralTool with function="x**2", lower=0, upper=2
Observe: Result = 8/3 β 2.667
The integral of xΒ² from 0 to 2 is 8/3 β 2.667
User: "Show the plot of sin(x) and the area under the curve from 0 to Ο"
Agent:
Think: I need to compute the integral and create a visualization
Act: IntegralTool β PlotTool with shaded area
Observe: Integral = 2.0, plot generated
[Interactive plot with shaded area showing sin(x) from 0 to Ο]
The area under the curve of sin(x) from 0 to Ο is 2.0
The system maintains persistent state across sessions:
- Conversations: Full history across sessions
- Calculation Cache: Avoids recalculating integrals
- Usage Metrics: Tool usage analysis
- Agent State: Recovery after restarts
-- Main tables
conversations -- Conversation sessions
messages -- User/agent messages
calculation_results -- Integral cache
tool_usage -- Tool usage logs
Available metrics include:
- Tool usage frequency and performance
- Cache hit rate for calculations
- Agent response time
- Conversation history and analytics
Access metrics through the Streamlit sidebar:
tool_stats = st.session_state.tool_tracker.get_tool_statistics()
st.sidebar.json(tool_stats)
This project is licensed under the MIT License. See the LICENSE file for details.