LangChain 에이전트 소개

LangChain으로 LLM 애플리케이션 개발하기

Jonathan Bennion

AI Engineer & LangChain Contributor

에이전트란?

 

에이전트: LLM을 사용하여 _행동_을 취함

도구: 에이전트가 호출하는 _함수_

 

  • 이번 장ReAct 에이전트

사용자 입력을 바탕으로 에이전트가 도구를 선택하는 모습.

LangChain으로 LLM 애플리케이션 개발하기

ReAct 에이전트

  • Reason + Act

 

자메이카 킹스턴의 날씨는 어떤가요?

Thought: I should call Weather() to find the
weather in Kingston, Jamaica.


Act: Weather("Kingston, Jamaica")
Observe: The weather is mostly sunny with temperatures of 82°F.

사고, 행동, 관찰의 반복 루프.

LangChain으로 LLM 애플리케이션 개발하기

LangGraph

LangGraph 로고.

 

  • 에이전트 시스템 설계에 특화된 LangChain 브랜치
  • 통합된 도구 독립적 문법
  • pip install langgraph==0.2.74
LangChain으로 LLM 애플리케이션 개발하기

ReAct 에이전트

from langgraph.prebuilt import create_react_agent
from langchain_community.agent_toolkits.load_tools import load_tools

llm = ChatOpenAI(model="gpt-4o-mini", api_key=openai_api_key) tools = load_tools(["llm-math"], llm=llm)
agent = create_react_agent(llm, tools)
messages = agent.invoke({"messages": [("human", "What is the square root of 101?")]})
print(messages)
LangChain으로 LLM 애플리케이션 개발하기

ReAct 에이전트

{'messages': [
    HumanMessage(content='What is the square root of 101?', ...),
    AIMessage(content='', ..., tool_calls=[{'name': 'Calculator', 'args': {'__arg1': 'sqrt(101)'}, ...),
    ToolMessage(content='Answer: 10.04987562112089', ...),
    AIMessage(content='The square root of 101 is approximately 10.05.', ...)
]}
print(messages['messages'][-1].content)
The square root of 101 is approximately 10.05.
LangChain으로 LLM 애플리케이션 개발하기

연습해 봅시다!

LangChain으로 LLM 애플리케이션 개발하기

Preparing Video For Download...