35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""LangGraph 기반 대화 그래프 (구 N-profiling/domain/graph.py 이식).
|
|
|
|
원본 import 버그 수정: `n_profiling.llm`(존재하지 않음) → `negotiation.profiling.infra.llm_adapter`.
|
|
chat_engine 은 이 모듈을 사용하지 않으며(script_modifier/verifier 만 사용), langgraph 는 선택 의존성이다.
|
|
직접 import 할 때만 langgraph 가 필요하다.
|
|
"""
|
|
|
|
from typing import List, TypedDict
|
|
|
|
from langchain_core.messages import BaseMessage
|
|
from langgraph.graph import StateGraph
|
|
from langgraph.checkpoint.sqlite import SqliteSaver
|
|
|
|
from negotiation.profiling.infra.llm_adapter import get_llm
|
|
|
|
|
|
class AgentState(TypedDict):
|
|
"""대화 상태. messages: 대화 히스토리."""
|
|
|
|
messages: List[BaseMessage]
|
|
|
|
|
|
def call_model(state: AgentState):
|
|
response = get_llm().invoke(state["messages"])
|
|
return {"messages": [response]}
|
|
|
|
|
|
# 대화 상태를 메모리에 임시 저장하는 체크포인터.
|
|
memory = SqliteSaver.from_conn_string(":memory:")
|
|
|
|
graph = StateGraph(AgentState)
|
|
graph.add_node("llm", call_model)
|
|
graph.set_entry_point("llm")
|
|
graph.set_finish_point("llm")
|