"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from typing import Annotated\n",
"\n",
"from typing_extensions import TypedDict\n",
"\n",
"from langgraph.graph import StateGraph, START, END\n",
"from langgraph.graph.message import add_messages\n",
"\n",
"class State(TypedDict):\n",
" # Messages have the type \"list\". The `add_messages` function\n",
" # in the annotation defines how this state key should be updated\n",
" # (in this case, it appends messages to the list, rather than overwriting them)\n",
" messages: Annotated[list, add_messages]\n",
"\n",
"graph_builder = StateGraph(State)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
添加智能体节点
"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def chatbot(state: State):\n",
" # return {\"messages\": [llm_tongyi.invoke(state[\"messages\"])]}\n",
" return {\"messages\": [manual_tool_invocation(llm_tongyi, tools, \"What's a 'node' in LangGraph?\")]}\n",
"\n",
"# The first argument is the unique node name\n",
"# The second argument is the function or object that will be called whenever\n",
"# the node is used.\n",
"graph_builder.add_node(\"chatbot\", chatbot)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"