2.3 KiB
2.3 KiB
What was implemented
- A fully‑functional search agent that follows the “Deep Agents from Scratch” template.
- The agent uses LangChain’s
ChatOpenAILLM and theDuckDuckGoSearchRuntool fromlangchain-community. - A singleton
AgentExecutoris 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, andConversationBufferMemoryare all LangChain objects. - Dependencies: The imports
langchain_openaiandlangchain_communityare 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
# 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()
# src/agent.py – agent creation
agent = create_openai_tools_agent(
llm=llm,
tools=[search_tool],
agent_type="zero-shot-react-description",
)
# src/agent.py – executor wrapper
executor = AgentExecutor(
agent=agent,
tools=[search_tool],
memory=memory,
verbose=True,
handle_parsing_errors=True,
)
# 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.