feat: solution for '8. Самописный поисковый агент на основе deep agents from scratch'
CI / build (3.1) (push) Has been cancelled
CI / build (3.11) (push) Has been cancelled
CI / build (3.8) (push) Has been cancelled
CI / build (3.9) (push) Has been cancelled

This commit is contained in:
2026-06-30 16:25:43 +03:00
parent 1039c7065c
commit 54499668c4
3 changed files with 225 additions and 50 deletions
+53 -28
View File
@@ -1,43 +1,68 @@
# DeepAgent
# Deep Search Agent LangChain Implementation
DeepAgent is a minimal example of a deep learning based search agent.
It demonstrates how to combine a neural network with a simple search algorithm
(MonteCarlo Tree Search style) without relying on external search libraries.
This repository contains a minimal implementation of a **search agent** built with LangChain, following the “Deep Agents from Scratch” template.
The agent can answer arbitrary questions by performing a web search and reasoning over the results.
## Installation
## Features
- Uses **OpenAI GPT4omini** as the language model.
- Performs web searches via **SerpAPI** (Google/SerpAPI).
- Maintains conversation context with a memory buffer.
- Implements the **ZeroShot React** agent pattern.
- Simple commandline interface for interactive use.
## Prerequisites
- Python 3.10+
- An OpenAI API key.
- A SerpAPI key (free tier available).
## Setup
```bash
# Create a virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate # On Windows use `.venv\\Scripts\\activate`
# Clone the repository
git clone https://git.brojs.ru/kuzakhmetovartur/8.-samopisnyy-poiskovyy-agent-na-osnove-<repo>.git
cd <repo>
# Install the package
pip install .
# Create a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\\Scripts\\activate
# Install dependencies
pip install -r requirements.txt
```
Create a `.env` file in the project root with your credentials:
```
OPENAI_API_KEY=sk-...
SERPAPI_KEY=your-serpapi-key
```
## Usage
```python
from src.search_agent import SearchAgent, PolicyValueNet
# Create a policyvalue network
net = PolicyValueNet(input_dim=1, action_space=2)
# Create the agent
agent = SearchAgent(policy_value_net=net, max_depth=3)
# Run the agent on a simple state
state = 0
action = agent.act(state)
print(f"Chosen action: {action}")
```
## Running Tests
Run the agent interactively:
```bash
pytest
python -m src.agent
```
You will be prompted to enter a question. The agent will search the web and return a concise answer.
## Example
```
Enter your question: What is the capital of France?
Processing...
=== Answer ===
The capital of France is Paris.
```
## Testing
The agent can be tested programmatically by importing `create_search_agent` from `src.agent` and calling `agent.run("your question")`.
## License
MIT License see the [LICENSE](LICENSE) file for details.
MIT License