feat: solution for '8. Самописный поисковый агент на основе deep agents from scratch'

This commit is contained in:
2026-06-30 14:52:37 +03:00
parent 4be7a21036
commit b5a9604f58
4 changed files with 244 additions and 47 deletions
+80 -42
View File
@@ -1,76 +1,114 @@
# Deep Agent from Scratch
# Deep Agents from Scratch LangChain Search Agent
This repository demonstrates a **Deep Agent** implementation using the **LangChain** library.
The agent follows the “Deep Agents from Scratch” template and can answer arbitrary questions by leveraging an LLM (OpenAI GPT3.5Turbo by default). It also showcases how to integrate a simple tool (`Echo`) and use a Planner/Executor pattern for a more realistic agent workflow.
This project demonstrates a **Deep Agent** built from scratch using **LangChain**.
The agent can answer user questions by searching the web with DuckDuckGo and
providing concise, uptodate responses.
> **Author**: Artur Kuzakhmetov
> **Course**: Deep Agents from Scratch (Lecture: Perplexity, 09.04.2026)
> **Deadline**: 31.08.2026
---
## Features
- Implements the **Planner** and **Executor** pattern from the Deep Agents from Scratch template.
- Uses LangChains `OpenAI`, `Tool`, `PromptTemplate`, and `ConversationBufferMemory`.
- Configurable LLM model, temperature, and token limits.
- Simple commandline interface for quick testing.
- Environmentvariable based configuration for API keys and model selection.
- Demonstrates tool integration (Echo tool) and the full agent template.
- **Custom Search Tool** queries DuckDuckGos instant answer API.
- **Conversation Memory** keeps context across turns.
- **REACT Agent** follows the “Reason → Act → Think” pattern.
- **CLI** simple commandline interface for interactive use.
- **Unit Tests** basic tests for the search tool.
## Prerequisites
- Node.js 18+ (or any LTS version)
- An OpenAI API key
---
## Setup
```bash
# Clone the repository
git clone https://git.brojs.ru/kuzakhmetovartur/8.-samopisnyy-poiskovyy-agent-na-osnove-
cd 8.-samopisnyy-poiskovyy-agent-na-osnove-
1. **Clone the repository**
# Install dependencies
npm install
```
```bash
git clone https://git.brojs.ru/kuzakhmetovartur/8.-samopisnyy-poiskovyy-agent-na-osnove-.git
cd 8.-samopisnyy-poiskovyy-agent-na-osnove-
```
Create a `.env` file in the project root:
2. **Create a virtual environment**
```dotenv
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-3.5-turbo # optional, defaults to gpt-3.5-turbo
```
```bash
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
```
> **Tip:** Keep your `.env` file out of version control. Add it to `.gitignore` if you plan to push the repo.
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
4. **Set up OpenAI API key**
Create a `.env` file in the project root:
```dotenv
OPENAI_API_KEY=sk-...
```
Replace `sk-...` with your actual key.
---
## Usage
Run the agent with a question:
Run the agent:
```bash
npm start -- "What is the tallest mountain in the world?"
python -m src.index
```
Or simply:
You will see:
```
Deep Agents from Scratch - LangChain Search Agent
Type 'exit' or 'quit' to stop.
Enter your question:
```
Type a question, e.g.:
```
What is the capital of France?
```
The agent will search the web and return an answer.
---
## Running Tests
```bash
node src/index.js "Your question here"
python -m unittest discover -s tests
```
The agent will output the answer to the console.
---
## Project Structure
```
├── package.json # Project metadata and dependencies
├── src/
│ ├── deepAgent.js # Core DeepAgent implementation (Planner/Executor)
│ └── index.js # CLI entry point
├── src
│ └── index.py # Main agent implementation
├── tests
│ └── test_search_tool.py # Unit tests for the search tool
├── requirements.txt # Project dependencies
└── README.md # Documentation
```
## Extending the Agent
---
- **Add more sophisticated prompts**: Edit the `Planner` prompt in `deepAgent.js`.
- **Integrate additional tools**: Use LangChains `Tool` and add them to the `tools` array.
- **Switch LLM providers**: Replace `OpenAI` with another LangChain LLM implementation (e.g., `AzureOpenAI`, `Anthropic`).
## Contributing
Feel free to fork the repository, create a feature branch, and submit a pull request.
Please ensure tests pass before merging.
---
## License
MIT © 2026
---
MIT License.