57 lines
2.3 KiB
Markdown
57 lines
2.3 KiB
Markdown
**What was implemented**
|
||
- A fully‑functional search agent that follows the “Deep Agents from Scratch” template.
|
||
- The agent uses LangChain’s `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 zero‑shot 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 rate‑limit 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 assignment’s core requirements: a LangChain‑based search agent, proper dependencies, and a clear, reusable implementation. |