35b6e514a8f495bfac20790e3d09e0338c343b36
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_KEYenvironment variable).
Installation
# 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):
OPENAI_API_KEY=sk-...
Note
: The DuckDuckGo search tool does not require any API key.
Usage
Run the agent from the command line:
python main.py "What is the capital of France?"
You should see the agent perform a search and return an answer.
Example
$ 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.toolsand add them to thetoolslist insrc/agent.py. - Change the LLM: Replace
ChatOpenAIwith another LLM provider (e.g., Anthropic, Gemini) by adjusting the import and initialization. - Adjust temperature: Modify the
temperatureparameter inChatOpenAIto control creativity.
Troubleshooting
- Missing OpenAI key: Ensure
OPENAI_API_KEYis set in your environment or.envfile. - Network errors: Check your internet connection and retry.
- Agent hangs: Increase the
timeoutin the DuckDuckGo tool or switch to a different search provider.
License
MIT License.
Languages
Python
80.3%
JavaScript
19.7%