Langchain에서 agent를 생성할 때 AgentType을 선택할 수 있었는데 AgentType들이 어떤것이 있는지 확인해보려고 한다.
from langchain.agents import initialize_agent, Tool
from langchain.agents.agent_types import AgentType
from langchain_community.chat_models import ChatOpenAI
agent = initialize_agent(
tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)
AgentType
확인해보니 deprecated되었다고 한다. 그렇다면 어떤걸 사용하는게 좋을까?
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class AgentType(str, Enum):
"""An enum for agent types.
See documentation: https://python.langchain.com/docs/modules/agents/agent_types/
"""
ZERO_SHOT_REACT_DESCRIPTION = "zero-shot-react-description"
"""A zero shot agent that does a reasoning step before acting."""
REACT_DOCSTORE = "react-docstore"
"""A zero shot agent that does a reasoning step before acting.
This agent has access to a document store that allows it to look up
relevant information to answering the question.
"""
SELF_ASK_WITH_SEARCH = "self-ask-with-search"
"""An agent that breaks down a complex question into a series of simpler questions.
This agent uses a search tool to look up answers to the simpler questions
in order to answer the original complex question.
"""
CONVERSATIONAL_REACT_DESCRIPTION = "conversational-react-description"
CHAT_ZERO_SHOT_REACT_DESCRIPTION = "chat-zero-shot-react-description"
"""A zero shot agent that does a reasoning step before acting.
This agent is designed to be used in conjunction
"""
CHAT_CONVERSATIONAL_REACT_DESCRIPTION = "chat-conversational-react-description"
STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION = (
"structured-chat-zero-shot-react-description"
)
"""An zero-shot react agent optimized for chat models.
This agent is capable of invoking tools that have multiple inputs.
"""
OPENAI_FUNCTIONS = "openai-functions"
"""An agent optimized for using open AI functions."""
OPENAI_MULTI_FUNCTIONS = "openai-multi-functions"
AGENT_DEPRECATION_WARNING
langchain의 agnet는 여전히 지원하지만 LangGraph를 사용하면 유연하게 구성할 수 있다고 한다.
추후 LangGraph를 사용하는 방법도 공부 해야겠다.
공부할 todo를 정해야할듯 하다.
AGENT_DEPRECATION_WARNING = (
"LangChain agents will continue to be supported, but it is recommended for new "
"use cases to be built with LangGraph. LangGraph offers a more flexible and "
"full-featured framework for building agents, including support for "
"tool-calling, persistence of state, and human-in-the-loop workflows. For "
"details, refer to the "
"`LangGraph documentation <https://langchain-ai.github.io/langgraph/>`_"
" as well as guides for "
"`Migrating from AgentExecutor <https://python.langchain.com/docs/how_to/migrate_agent/>`_" # noqa: E501
" and LangGraph's "
"`Pre-built ReAct agent <https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/>`_." # noqa: E501
)
agentType enum의 설명을 찾아보자
AgentType — 🦜🔗 LangChain documentation
Deprecated since version 0.1.0: LangChain agents will continue to be supported, but it is recommended for new use cases to be built with LangGraph. LangGraph offers a more flexible and full-featured framework for building agents, including support for tool
python.langchain.com
용어 정리
Zero-Shot: 이전에 학습되어 있는 모델을 가지고 배우지 않은 작업을 수행하는 것 즉, 현재 모델로 일반화된 작업을 수행하게 한다. (간단히 말하면 기본상모델)
reasoning, ReAct: Tool 선택의 추론과정 및 사용
https://arxiv.org/abs/2210.03629
ReAct: Synergizing Reasoning and Acting in Language Models
While large language models (LLMs) have demonstrated impressive capabilities across tasks in language understanding and interactive decision making, their abilities for reasoning (e.g. chain-of-thought prompting) and acting (e.g. action plan generation) ha
arxiv.org
Document Store: 특정 도메인을 관련된 정보를 저장해둔 벡터 저장소, RAG 구성할 때 사용된다.
- ZERO_SHOT_REACT_DESCRIPTION: 학습되지 않은 범용 agent를 사용하며 동작하기 전 Tool 선택의 추론 과정을 거친다.
- REACT_DOCSTORE: 1번 agent + 질문에 관련된 정보를 찾기 위해 Document Store를 사용한다. (즉 RAG)
- SELF_ASK_WITH_SEARCH: 복잡한 질문을 여러개의 간단한 질문으로 변환한다.
이 agent는 변환한 간단한 질문의 답을 찾기위해 검색툴을 이용한다. - CONVERSATIONAL_REACT_DESCRIPTION: 문맥을 유지
- CHAT_ZERO_SHOT_REACT_DESCRIPTION : 문맥을 유지하지 않는 단발성 대화
- CHAT_CONVERSATIONAL_REACT_DESCRIPTION: 문맥을 유지하는 대화
- STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION : 일반적인 텍스트가아닌 특정 형식으로 구성된 대화
TODO
- Conversational과 chat이 문맥 유지의 여부 차이인데 그렇다면 ONVERSATIONAL_REACT_DESCRIPTION 과 CHAT_CONVERSATIONAL_REACT_DESCRIPTION는 어떤 차이가 있는지 소스 및 프롬프트를 비교해
- LangGraph를 공부
'AI????, LLM???' 카테고리의 다른 글
AI Agent와 Tool 2 (langchain을 사용한) (0) | 2025.04.15 |
---|---|
AI Agent와 Tool 1 (Python을 사용한 간단한 AI Agnet 만들기) (0) | 2025.04.15 |
LangChain을 사용한 RAG 구성 1 (0) | 2025.04.15 |