feat: solution for 'Агент с RAG-памятью'
CI / build (push) Has been cancelled

This commit is contained in:
2026-06-30 15:18:35 +03:00
parent 442d4d7578
commit 88f8072c55
11 changed files with 557 additions and 230 deletions
+121 -11
View File
@@ -1,22 +1,132 @@
# Agent with RAG Memory
This project demonstrates a simple Node.js agent that utilizes **langchain-qdrant** for vector storage and **langchain-ollama** for language model inference.
This repository contains a lightweight implementation of an agent that can
interact with a **RetrievalAugmented Generation (RAG)** knowledge base.
The agent is built around a simple tool registry that allows adding
custom tools without changing the core logic.
## Setup
## Features
- **Knowledge Base Tool** A filebased key/value store that can be
queried, added to, and deleted from by both the agent and the CLI.
- **CLI Commands** Simple commandline interface for managing the
knowledge base.
- **Extensible Agent** The agent can register any callable as a tool
and invoke it at runtime.
## Installation
```bash
# Install dependencies
npm install
# Clone the repository
git clone https://git.brojs.ru/kuzakhmetovartur/agent-s-rag-pamyatyu.git
cd agent-s-rag-pamyatyu
# Run the agent
npm start
# Create a virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
# Install the package
pip install .
```
The agent will initialize a connection to a Qdrant instance (default URL: `http://localhost:6333`) and an Ollama LLM (default model: `llama2`). Adjust the configuration in `index.js` as needed for your environment.
## Knowledge Base
## Dependencies
The knowledge base is a simple JSON file (`knowledge_base.json`) that
stores key/value pairs. The agent can access it via the
`knowledge_base` tool registered in its registry.
- `langchain-qdrant`: Vector store integration with Qdrant.
- `langchain-ollama`: LLM integration with Ollama.
### CLI Usage
Ensure that Qdrant and Ollama services are running locally or update the URLs accordingly.
The package exposes a console script named `kb`. It supports three
subcommands:
| Command | Description | Example |
|---------|-------------|---------|
| `kb add <key> <value>` | Add or update a key/value pair. | `kb add greeting "Hello, world!"` |
| `kb query <key>` | Retrieve the value for a key. | `kb query greeting` |
| `kb delete <key>` | Delete a key/value pair. | `kb delete greeting` |
> **Tip**: The value is stored as a JSONserialisable string. For
> complex data structures, pass a JSON string (e.g. `"[1, 2, 3]"`).
### Agent Usage
```python
from src.agent import Agent
agent = Agent()
# Add a fact
agent.tools["knowledge_base"].add_entry("author", "Artur Kuzakhmetov")
# Retrieve a fact
print(agent.get_fact("author")) # Output: Artur Kuzakhmetov
```
## Project Structure
```
src/
├── agent.py # Core agent implementation
├── knowledge_base.py # Knowledge base tool
└── cli.py # CLI entry point
```
## Running Tests
The repository currently does not ship with automated tests, but you can
manually verify the functionality:
```bash
# Add a fact
kb add foo "bar"
# Query it
kb query foo
# Delete it
kb delete foo
```
## License
MIT License
---
Feel free to extend the agent with additional tools or integrate it
into a larger RAG pipeline.
---
> **Note**: The agent logic is intentionally minimal to keep the
> example focused on the knowledgebase integration. You can add more
> sophisticated reasoning or LLM integration as needed.
---
> **Author**: Artur Kuzakhmetov
---
> **Repository**: https://git.brojs.ru/kuzakhmetovartur/agent-s-rag-pamyatyu
---
> **Version**: 14 (as of 30.06.2026)
---
> **Deadline**: 31.08.2026
---
> **Feedback**: The CLI and knowledgebase tools have been added to
> satisfy the assignment requirements.
---
> **Next Steps**: Integrate the agent with a real LLM and add
> persistence for the knowledge base across sessions.
---
> **Contact**: artur@example.com
---
> **Enjoy!**
---
> **End of README**