87 lines
2.6 KiB
Markdown
87 lines
2.6 KiB
Markdown
# Deep Agents from Scratch – Search Agent
|
||
|
||
This project implements a simple web‑search agent using the **LangChain** framework, following the “Deep Agents from Scratch” template.
|
||
The agent can answer user questions by performing a DuckDuckGo search and reasoning over the results with an OpenAI LLM.
|
||
|
||
## Features
|
||
|
||
- **Zero‑shot React** agent powered by LangChain.
|
||
- Uses **DuckDuckGo** for web search (no API key required).
|
||
- Powered by **OpenAI** (requires an API key).
|
||
- Conversation memory to keep context across turns.
|
||
- Simple command‑line interface.
|
||
|
||
## Prerequisites
|
||
|
||
- Python 3.10+
|
||
- An OpenAI API key (set in `OPENAI_API_KEY` environment variable).
|
||
|
||
## Installation
|
||
|
||
```bash
|
||
# Clone the repository
|
||
git clone https://git.brojs.ru/kuzakhmetovartur/8.-samopisnyy-poiskovyy-agent-na-osnove.git
|
||
cd 8.-samopisnyy-poiskovyy-agent-na-osnove
|
||
|
||
# Create a virtual environment (recommended)
|
||
python -m venv .venv
|
||
source .venv/bin/activate # On Windows use `.venv\Scripts\activate`
|
||
|
||
# Install dependencies
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
## Configuration
|
||
|
||
Create a `.env` file in the project root (or export the variable directly):
|
||
|
||
```dotenv
|
||
OPENAI_API_KEY=sk-...
|
||
```
|
||
|
||
> **Note**: The DuckDuckGo search tool does not require any API key.
|
||
|
||
## Usage
|
||
|
||
Run the agent from the command line:
|
||
|
||
```bash
|
||
python main.py "What is the capital of France?"
|
||
```
|
||
|
||
You should see the agent perform a search and return an answer.
|
||
|
||
## Example
|
||
|
||
```bash
|
||
$ python main.py "Who is the current CEO of Tesla?"
|
||
=== Agent Response ===
|
||
Elon Musk is the current CEO of Tesla. He has been in the role since 2008 and is also the founder of SpaceX and Neuralink.
|
||
```
|
||
|
||
## Project Structure
|
||
|
||
```
|
||
├── src
|
||
│ └── agent.py # Agent implementation
|
||
├── main.py # CLI entry point
|
||
├── requirements.txt # Dependencies
|
||
├── README.md # Documentation
|
||
└── .env # (Optional) Environment variables
|
||
```
|
||
|
||
## Extending the Agent
|
||
|
||
- **Add more tools**: Import additional tools from `langchain_community.tools` and add them to the `tools` list in `src/agent.py`.
|
||
- **Change the LLM**: Replace `ChatOpenAI` with another LLM provider (e.g., Anthropic, Gemini) by adjusting the import and initialization.
|
||
- **Adjust temperature**: Modify the `temperature` parameter in `ChatOpenAI` to control creativity.
|
||
|
||
## Troubleshooting
|
||
|
||
- **Missing OpenAI key**: Ensure `OPENAI_API_KEY` is set in your environment or `.env` file.
|
||
- **Network errors**: Check your internet connection and retry.
|
||
- **Agent hangs**: Increase the `timeout` in the DuckDuckGo tool or switch to a different search provider.
|
||
|
||
## License
|
||
|
||
MIT License. |