본문 바로가기
Bigdata

LangChain Messages 역활

by 올엠 2025. 6. 10.
반응형
LangChain Messages 역활

LangChain에서 Messages는 LLM과의 상호작용을 구성하는 핵심 요소 중 하나로 프롬프트 엔지니어링에 많이 사용되는 요소라고 할 수 있다. 특히 LangChain의 ChatMessage 시스템은 다양한 역할(role)을 가진 메시지를 통해 대화의 흐름과 문맥을 명확하게 정의할 수 있는데, 각 역활은 다음과 같다.

 

SystemMessage
역할: 모델의 동작 방식을 지시하거나 설정하는 메시지
예시: "당신은 친절한 영어 튜터입니다."
용도: 모델의 톤, 스타일, 태도 등을 설정할 때 사용


HumanMessage
역할: 사용자가 모델에게 보내는 메시지
예시: "이 문장을 영어로 번역해줘."


AIMessage
역할: 모델이 사용자에게 응답한 메시지
예시: "Sure! Here's the translation: ..."


FunctionMessage (또는 ToolMessage)
역할: LangChain에서 도구 호출 결과를 모델에게 전달할 때 사용
예시: 모델이 계산기 도구를 호출한 후, 그 결과를 FunctionMessage로 전달
형식: FunctionMessage(name="calculator", content="42")


FunctionCallMessage (또는 ToolCallMessage)
역할: 모델이 외부 도구를 호출하고자 할 때 생성되는 메시지
예시: 모델이 "function": "get_weather", "arguments": {"location": "Seoul"} 같은 호출을 요청할 때 사용

from langchain.schema import SystemMessage, HumanMessage, AIMessage

messages = [
    SystemMessage(content="You are a helpful assistant."),
    HumanMessage(content="What's the capital of France?"),
    AIMessage(content="The capital of France is Paris.")
]
반응형