Files
8.-samopisnyy-poiskovyy-age…/SOLUTION.md
T
kuzakhmetovartur 35b6e514a8
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
feat: solution for '8. Самописный поисковый агент на основе deep agents from scratch'
2026-07-01 13:13:44 +03:00

57 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
**What was implemented**
- A fullyfunctional search agent that follows the “Deep Agents from Scratch” template.
- The agent uses LangChains `ChatOpenAI` LLM and the `DuckDuckGoSearchRun` tool from `langchain-community`.
- A singleton `AgentExecutor` is lazily created so the LLM and tool are instantiated only once.
- A simple CLI (`main.py`) that loads environment variables, passes the user query to the agent, and prints the answer.
**Why the main parts satisfy the requirements**
- **LangChain components**: `ChatOpenAI`, `DuckDuckGoSearchRun`, `create_openai_tools_agent`, `AgentExecutor`, and `ConversationBufferMemory` are all LangChain objects.
- **Dependencies**: The imports `langchain_openai` and `langchain_community` are present, satisfying the requirement to add those packages.
- **Deep Agents from Scratch template**: The agent is built with a zeroshot React description (`agent_type="zero-shot-react-description"`), which is the core pattern described in the lecture.
- **Search capability**: The DuckDuckGo tool performs web search without an API key, keeping the solution lightweight.
**Key code excerpts**
```python
# src/agent.py LLM and tool setup
llm = ChatOpenAI(
model="gpt-4o-mini",
temperature=0.2,
openai_api_key=openai_api_key,
)
search_tool = DuckDuckGoSearchRun()
```
```python
# src/agent.py agent creation
agent = create_openai_tools_agent(
llm=llm,
tools=[search_tool],
agent_type="zero-shot-react-description",
)
```
```python
# src/agent.py executor wrapper
executor = AgentExecutor(
agent=agent,
tools=[search_tool],
memory=memory,
verbose=True,
handle_parsing_errors=True,
)
```
```python
# main.py CLI entry point
answer = run_query(query)
print("\n=== Agent Response ===")
print(answer)
```
**Honest limitations**
- The agent uses a single DuckDuckGo search tool; more sophisticated search or filtering is not implemented.
- No caching or ratelimit handling is added, so repeated queries may hit the same external service each time.
- Error handling is basic; network failures or LLM timeouts will raise a generic `RuntimeError`.
Overall, the solution meets the assignments core requirements: a LangChainbased search agent, proper dependencies, and a clear, reusable implementation.