"
]
},
{
"cell_type": "markdown",
"id": "8d57b011-2029-4ebf-a158-4ebc15c65ce5",
"metadata": {},
"source": [
" 如上图所示的代理架构在 `LangGraph` 中的实现机制类似于 `LangChain` 中的 `ReAct Agent`,毕竟 `LangGraph` 的底层语言是 `LangChain` 的 `LCEL` 表达式语言。因此,该 `ReAct Agent` 架构是从 `LangChain` 已实现的 `ReAct Agent` 迁移而来,不同的是在`LangGraph`框架中适配的是图结构,而非`AgentExecuter`。其本质依然基于一种规划(Planning)的思想:"
]
},
{
"cell_type": "markdown",
"id": "e569d5d3-5db5-4553-8481-a5820ab6c12f",
"metadata": {},
"source": [
"> LangChain Agents Type: https://python.langchain.com/v0.1/docs/modules/agents/agent_types/\n",
">\n",
"> Agent Planning:https://smith.langchain.com/hub/hwchase17/react?organizationId=33612d73-91c5-5140-b8a0-f3155ff5dc45"
]
},
{
"cell_type": "markdown",
"id": "88f5c294-d1e7-4d04-8c9f-3387c1d8bdda",
"metadata": {},
"source": [
"```json\n",
"Answer the following questions as best you can. You have access to the following tools:\n",
"\n",
"{tools}\n",
"\n",
"Use the following format:\n",
"\n",
"Question: the input question you must answer\n",
"\n",
"Thought: you should always think about what to do\n",
"\n",
"Action: the action to take, should be one of [{tool_names}]\n",
"\n",
"Action Input: the input to the action\n",
"\n",
"Observation: the result of the action\n",
"\n",
"... (this Thought/Action/Action Input/Observation can repeat N times)\n",
"\n",
"Thought: I now know the final answer\n",
"\n",
"Final Answer: the final answer to the original input question\n",
"\n",
"Begin!\n",
"\n",
"Question: {input}\n",
"\n",
"Thought:{agent_scratchpad}\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "73386feb-ff05-4093-b2fc-33981010ac34",
"metadata": {},
"source": [
" 这种代理实现的机制表明了,在`LangGraph`中实现的预构建`ReAct`代理结构,它支持:\n",
"\n",
"- **Tool calling :允许大模型根据需要选择和使用各种工具。**\n",
"- **Memory:使代理能够保留和使用先前步骤中的信息。**\n",
"- **Planning :授权大模型制定并遵循多步骤计划以实现目标。**\n",
"\n",
"\n",
" 而其在图结构中的具体构建的工作流如下图所示:"
]
},
{
"cell_type": "markdown",
"id": "88178062-598d-4007-9468-5d732875e44d",
"metadata": {},
"source": [
"