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-07-01 13:56:19 +03:00
parent fea117b469
commit dbd910be14
5 changed files with 176 additions and 119 deletions
+28 -47
View File
@@ -1,70 +1,51 @@
# Deep Agent Search
# Deep Search Agent
This project demonstrates a simple search agent built with **LangChain**'s `DeepAgent` and the **OpenAI** language model. The agent can answer user queries and perform web searches when needed.
A minimal implementation of a deep search agent built from scratch using the LangChain framework and OpenAI API.
The agent decides whether to answer a query directly or perform a web search using SerpAPI.
## Prerequisites
- Node.js 18+ (ES modules support)
- An OpenAI API key. Set it in your environment:
- Node.js 18+ (ESM support)
- An OpenAI API key
- A SerpAPI key (free tier available)
## Setup
```bash
export OPENAI_API_KEY="your-api-key-here"
```
# Clone the repository
git clone https://github.com/your-username/deep-search-agent.git
cd deep-search-agent
## Installation
```bash
# Install dependencies
npm install
# Create a .env file with your API keys
cp .env.example .env
# Edit .env and replace the placeholders with your actual keys
```
## Usage
### CLI
Run the agent interactively:
Run the agent with a query:
```bash
npm start
npm start -- "What is the capital of France?"
```
You will be prompted to enter a question. The agent will respond.
The agent will output either a direct answer or the results of a web search.
### Programmatic
## How It Works
```js
import { ask } from "./src/index.js";
1. **Planner** Uses an LLM to decide if the query requires a web search or can be answered directly.
2. **Executor** If a search is needed, the agent calls the SerpAPI tool and returns the results.
3. **Memory** Stores conversation context (optional for future extensions).
async function main() {
const answer = await ask("Who wrote 'Pride and Prejudice'?");
console.log(answer);
}
## Extending
main();
```
## Testing
A simple test script is provided:
```bash
npm test
```
It queries the agent with a sample question and prints the answer.
## Project Structure
- `src/agent.js` Configures the `DeepAgent` with OpenAI LLM and the search tool.
- `src/index.js` Exposes the `ask` function and a CLI demo.
- `test.js` Quick test script.
- `package.json` Project metadata and dependencies.
## Dependencies
- `langchain` Core LangChain library.
- `langchain-openai` OpenAI wrapper for LangChain.
- `langchain-community` Community tools, including the web search tool.
- Add more tools (e.g., Wikipedia, Calculator) and update the planner prompt accordingly.
- Replace the planner with a more sophisticated planner (e.g., chain of thought).
- Persist memory to a database for longterm context.
## License
MIT
MIT License