From 242b564d4e9033abf47ee16927b9d75945a3ed27 Mon Sep 17 00:00:00 2001 From: lonpatovaadelina Date: Thu, 28 May 2026 10:37:44 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3d14c20..0f2f420 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,96 @@ -# stream-rezhim-ai-agenta +# Stream‑Mode AI Agent -Решение: Stream-режим AI-агента \ No newline at end of file +A lightweight LangChain agent that prints its output **as it is generated** using the `.stream()` API. +The project demonstrates how to replace a single `.invoke()` call with streaming so that users see partial responses in real time. + +> **Why stream?** +> When an LLM produces long answers or calls multiple tools, waiting for the whole result can feel like a freeze. Streaming gives instant feedback and improves UX. + +--- + +## 📦 Project Structure + +``` +. +├── agent.py # Agent definition with streaming support +├── client.py # Simple CLI to interact with the agent +└── README.md +``` + +- **agent.py** – creates an agent that uses a single tool (`get_price`) and streams its output. +- **client.py** – runs the agent in a loop, reading user queries from stdin. + +--- + +## ⚙️ Prerequisites + +| Item | Version | +|------|---------| +| Python | 3.10+ | +| pip | latest | +| LangChain | `>=0.2.0` | +| Rich | `>=13.0` | + +> **Tip:** Use a virtual environment to keep dependencies isolated. + +--- + +## 🚀 Installation + +```bash +# Clone the repo (or copy the files) +git clone https://github.com/your-username/stream-agent.git +cd stream-agent + +# Create and activate a venv (optional but recommended) +python -m venv .venv +source .venv/bin/activate # Windows: .venv\Scripts\activate + +# Install dependencies +pip install --upgrade pip +pip install langchain rich +``` + +> If you plan to use an OpenAI model, set the API key: +> ```bash +> export OPENAI_API_KEY="sk-..." +> ``` + +--- + +## 📖 Usage + +Run the client script and type your questions. The agent will stream its answer token‑by‑token. + +```bash +python client.py +``` + +Example session: + +``` +$ python client.py +Enter your query (Ctrl+C to exit): +> What is the price of Bitcoin today? + +Agent: Checking price... +Agent: Current BTC price is $42,300.00 +``` + +The output appears progressively as the LLM generates it. + +--- + +## 🛠️ Customization + +- **Add more tools** – decorate a function with `@tool` and pass it to `create_agent`. +- **Change model** – modify the `model_name` argument in `agent.py`. +- **Adjust streaming format** – tweak the `stream()` call or use Rich’s live rendering for fancy UI. + +--- + +## 📄 License + +MIT © 2026 + +--- \ No newline at end of file