에이전트에 사용자 정의 도구 통합하기
이제 도구 준비가 끝났으니, 에이전트 워크플로를 설정해 볼까요? 여기서도 다시 ReAct 에이전트를 사용할 거예요. ReAct 에이전트는 수행해야 할 단계를 스스로 추론하고, 이 문맥과 도구 설명을 바탕으로 적합한 도구를 선택합니다. OpenAI의 gpt-4o-mini 모델을 사용하는 llm은 이미 정의되어 있어요.
이 연습은 강의의 일부입니다
LangChain으로 LLM 애플리케이션 개발하기
연습 안내
llm과retrieve_customer_info도구를 담은 리스트를 인자로 하여create_react_agent()로 ReAct 에이전트를 생성하세요.- 제공된 입력에 대해
agent.invoke()로 에이전트를 실행하세요. - 마지막 메시지의 콘텐츠를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
@tool
def retrieve_customer_info(name: str) -> str:
"""Retrieve customer information based on their name."""
customer_info = customers[customers['name'] == name]
return customer_info.to_string()
# Create a ReAct agent
agent = create_react_agent(____, [____])
# Invoke the agent on the input
messages = agent.____({"messages": [("human", "Create a summary of our customer: Peak Performance Co.")]})
print(messages['messages'][-1].____)