add README.md

This commit is contained in:
2026-05-26 14:45:13 +00:00
parent 3ca8ee7e63
commit 88efd3438f
+33 -29
View File
@@ -1,39 +1,43 @@
# Simple Hierarchical AI ShoppingList Agent # ShoppingList AI Assistant
## What it does This repository contains a minimal example of a hierarchical LangChain agent that can estimate prices for products in a city. The toplevel agent uses the ``get_price`` tool, which internally creates a shortlived subagent to generate a markdown table row with the price.
This repository contains a minimal example of a **hierarchical LangChain agent** that helps you plan a shopping list. The main agent:
1. Accepts a naturallanguage request with a list of products and a city. ## Project structure
2. Calls an internal tool `get_price(product, city)` which itself creates a tiny subagent to generate realistic price tables for the requested product in the specified city.
3. Aggregates the prices and prints a final summary.
The example demonstrates: - **main.py** entry point; demonstrates three example calls and prints the full message chain.
- Connecting to a local LLM via LM Studio (OpenAIcompatible API). - **agent.py** defines the ``get_price`` tool used by the main agent.
- Using `@tool` to expose a function that internally runs another agent. - **requirements.txt** Python dependencies (no pinned versions, only ``>=``).
- Running the main agent with `create_agent` and printing all intermediate tool calls. - **README.md** this documentation.
## File structure
| File | Purpose |
|------|---------|
| `requirements.txt` | Pinning LangChain, langchainopenai and dotenv dependencies |
| `main.py` | Full implementation of the hierarchical agent and demo usage |
| `README.md` | This documentation |
## Installation ## Installation
```bash
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
```
Make sure LM Studio is running on `http://localhost:1234/v1` (or set `LM_BASE_URL` and `LM_MODEL`).
## Running the demo ```bash
pip install -r requirements.txt
# Ensure LM Studio is running at http://localhost:1234/v1 or set the env vars below:
export LOCAL_LLM_MODEL=gpt-3.5-turbo
export LOCAL_LLM_BASE_URL=http://localhost:1234/v1
export LOCAL_LLM_API_KEY=fake
```
## Running the examples
```bash ```bash
python main.py python main.py
``` ```
The script will:
- Run the main agent with a hardcoded prompt.
- Print each tool call (`get_price`) and its output.
- Show aggregated price tables and total cost.
Feel free to modify `user_prompt` in `main.py` or pass input from stdin for interactive use. You should see three blocks of output, each showing the assistants messages and the tool calls that were made.
## How it works
1. **Subagent** The ``get_price`` tool creates a lightweight subagent with a focused system prompt to generate a single markdown table row containing product name, price (rub.) and store.
2. **Main agent** Uses the ``get_price`` tool to estimate prices for each product in the users list.
3. **Output** The assistant prints all intermediate messages (tool calls) followed by the final answer summarizing the shopping list and total cost.
## Dependencies
- `langchain-openai>=0.3.0`
- `langgraph>=0.2.0`
- `langchain-core>=0.3.0`
- `python-dotenv>=1.0.0`
All versions are specified with ``>=`` to avoid pinning to potentially nonexistent releases.