chap9 Project
chap9 is a LangChain learning project covering the implementation of a web browsing agent. It ran from January to February 2025, across 8 commits.
Agent Architecture
graph TD
A[사용자 질의] --> B[LLM Agent]
B --> C{도구 선택}
C --> D[DuckDuckGo 검색]
C --> E[웹 페이지 스크래핑]
C --> F[데이터 분석]
D --> G[결과 종합]
E --> G
F --> G
G --> B
B --> H[최종 답변]
DuckDuckGo Search Tool
Uses the free DuckDuckGo search instead of the Google API:
from langchain_community.tools import DuckDuckGoSearchRun
search = DuckDuckGoSearchRun()
tools = [search]
agent = initialize_agent(
tools=tools,
llm=ChatOpenAI(model="gpt-4"),
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True
)
Streamlit UI (2/6)
Implements an interactive UI with Streamlit:
import streamlit as st
st.title("🔍 웹 검색 에이전트")
if prompt := st.chat_input("질문을 입력하세요"):
with st.chat_message("user"):
st.write(prompt)
with st.chat_message("assistant"):
with st.spinner("검색 중..."):
result = agent.invoke({"input": prompt})
st.write(result["output"])
Key Takeaways
- AgentType selection: OPENAI_FUNCTIONS vs ZERO_SHOT_REACT
- Tool composition: search + scraping + calculation
- Agent memory: using ConversationBufferMemory
- Streamlit integration: building a chat interface
This was a solid starting point for getting hands-on with LangChain.