
6
route,
{
"continue": "SHED",
"finish": END,
},
)
workflow.add_edge("SHED", "Salesman")
workflow.set_entry_point("Salesman")
graph = workflow.compile()
graph.invoke({"messages": []})
モジュールのインポート
最初に、必要なモジュールをインポートします。
from typing import Annotated, TypedDict, Sequence
import operator
from langchain_core.messages import (
BaseMessage,
HumanMessage,
AIMessage,
SystemMessage,
)
from langchain_openai import ChatOpenAI
from langchain_core.prompts import (
ChatPromptTemplate,
)
from langgraph.graph import END, StateGraph
import functools
ここでは、LangGraphの他に、LangChain 関連のモジュールをインポートしています。
プロンプトの定義
次に、各エージェントのプロンプトを定義します。
salesman_prompt = ChatPromptTemplate.from_messages( ...