LangChain으로 에이전트형 시스템 설계하기
Dilini K. Sumanapala, PhD
Founder & AI Engineer, Genverv, Ltd.
User: Where is the Congo?Agent: 자세한 내용을 확인해 보겠습니다...Agent: AIMessage([Tool Call to Google Maps] "the Congo"에 대한 정보 검색 중)Agent: 콩고민주공화국은 중앙아프리카에 있는 나라입니다.
# 사용자 입력으로 챗봇을 실행하는 함수 정의 def stream_graph_updates(user_input: str):# 그래프에서 사용자 입력으로 이벤트 스트리밍 시작 for event in graph.stream({"messages": [("user", user_input)]}):# 챗봇 노드 응답을 가져와 출력 for value in event.values(): print("Agent:", value["messages"])# 사용자 질의 정의 및 챗봇 실행 user_query = "Who is Mary Shelley?" stream_graph_updates(user_query)
Agent: [AIMessage(content='Mary Shelley (1797-1851)는 영국의 소설가......고딕 장르의 선구적 작품으로 가장 잘 알려져 있으며, 특히 1818년에 출간된 "Frankenstein; or, The Modern Prometheus"로 유명합니다. 이 소설은 초기 공상과학소설로 여겨지며, 창조, 책임, 인간성의 본질을 탐구합니다. 과학자 빅터 프랑켄슈타인이 비정통적 실험으로 지각 있는 존재를 만들어내는 이야기...',response_metadata={'finish_reason': 'stop', 'model_name': 'gpt-4o-mini-...')]
Agent: [AIMessage(content='Judith
Love Cohen은 미국의 항공우주
엔지니어로, Apollo
프로그램을 포함한 다양한
우주 임무에 참여했습니다... 또한
배우이자 작가 Adam Cohen의
어머니로, 그는 그녀가 자신의 삶과
경력에 미친 영향에 대해 말했습니다.
additional_kwargs={},
response_metadata={'finish_reason':
'stop', 'model_name':
'gpt-4o-mini-...)
# 챗봇 다이어그램 모듈 임포트 from IPython.display import Image, display# 그래프 다이어그램 생성 및 표시 시도 try: display(Image(graph.get_graph() .draw_mermaid_png()))
# 필요 시 예외 반환
except Exception:
print("Additional dependencies
required.")

LangChain으로 에이전트형 시스템 설계하기