This project is a simple AI agent built using LangGraph. The agent analyzes daily business data, such as sales and costs, and generates a summary report with actionable recommendations. It is designed to help businesses make informed decisions based on their daily performance. The project leverages LangGraph Server and LangGraph Studio, a visual debugging IDE, to build, run, and debug the agent.
The AI agent is implemented in src/agent/graph.py and consists of a graph with three nodes:
- Input Node: Receives business data as a Python dictionary or JSON object, validating that it contains the required fields for today’s and yesterday’s data (e.g., sales, costs, customers).
- Processing Node: Calculates key metrics such as profit (sales - costs), customer acquisition cost (CAC = costs / customers), and percentage changes in sales and costs compared to the previous day.
- Recommendation Node: Analyzes the calculated metrics and generates actionable recommendations, such as reducing costs if profit is negative or increasing the marketing budget if sales grew significantly.
The agent outputs a dictionary or JSON object containing the profit/loss status, any alerts or warnings, and decision-making recommendations. Example output:
{
"profit_status": "Profit: $200.00",
"alerts": [],
"recommendations": [
"Consider increasing advertising budget due to 11.11% sales growth"
]
}- Python 3.8+
- Git
-
Clone the repository:
git clone https://github.com/itzreqle/langgraph-business-agent.git
-
Navigate to the project directory:
cd langgraph-business-agent -
Create a virtual environment:
python3 -m venv langgraph-env
-
Activate the virtual environment:
source langgraph-env/bin/activate # On Windows: langgraph-env\Scripts\activate
-
Install dependencies, including the LangGraph CLI:
pip install -e . "langgraph-cli[inmem]"
-
(Optional) Create a
.envfile for secrets, such as a LangSmith API key for tracing:cp .env.example .env
Edit
.envto include:LANGSMITH_API_KEY=lsv2...
-
Run the agent directly:
python src/agent/graph.py
-
Or start the LangGraph Server for development and debugging:
langgraph dev
For more details on using LangGraph Server, see the LangGraph Server tutorial.
The graph, defined in src/agent/graph.py, consists of three nodes:
- Input Node: Ensures the input data is valid and structured correctly.
- Processing Node: Performs calculations like profit, CAC, and percentage changes in performance metrics.
- Recommendation Node: Uses predefined conditions to generate advice, such as warnings for high CAC or suggestions for budget adjustments.
You can visualize and debug this graph in LangGraph Studio, where local changes are hot-reloaded automatically.
The project includes unit and integration tests to validate the agent’s functionality. Run them with:
-
Unit tests:
python -m unittest tests/unit_tests/test_graph.py
-
Integration tests:
python -m unittest tests/integration_tests/test_graph.py
All tests should pass, confirming the agent works as expected.
- Modify Configurable Parameters: Update the
Configurationclass insrc/agent/graph.pyto expose new parameters (e.g., custom thresholds for recommendations). See [Lang -]https://langchain-ai.github.io/langgraph/concepts/low_level/?h=configuration#configuration) for details. - Extend the Graph: Edit
src/agent/graph.pyto add nodes, edges, or adjust the logic. For example, add a node for trend analysis or tweak recommendation conditions.
For advanced examples, refer to the LangGraph documentation.
- Edit past states and rerun the app from any point to debug specific nodes.
- Local changes are applied via hot reload.
- Start a new thread with the
+button in LangGraph Studio to clear history.
Integrate with LangSmith for detailed tracing and collaboration.
