mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-11 12:17:53 +02:00
docs: replace 'state_modifier' with 'prompt' (#3190)
This commit is contained in:
@@ -828,13 +828,13 @@
|
||||
"addition_expert = create_react_agent(\n",
|
||||
" model,\n",
|
||||
" [add, make_handoff_tool(agent_name=\"multiplication_expert\")],\n",
|
||||
" state_modifier=\"You are an addition expert, you can ask the multiplication expert for help with multiplication.\",\n",
|
||||
" prompt=\"You are an addition expert, you can ask the multiplication expert for help with multiplication.\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"multiplication_expert = create_react_agent(\n",
|
||||
" model,\n",
|
||||
" [multiply, make_handoff_tool(agent_name=\"addition_expert\")],\n",
|
||||
" state_modifier=\"You are a multiplication expert, you can ask an addition expert for help with addition.\",\n",
|
||||
" prompt=\"You are a multiplication expert, you can ask an addition expert for help with addition.\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"builder = StateGraph(MessagesState)\n",
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
"model = ChatOpenAI(model=\"gpt-4o\")\n",
|
||||
"tools = [TavilySearchResults(max_results=1)]\n",
|
||||
"web_search_agent = create_react_agent(\n",
|
||||
" model, tools, state_modifier=\"You are an agent specializing in web search\"\n",
|
||||
" model, tools, prompt=\"You are an agent specializing in web search\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
"\n",
|
||||
"This tutorial will show how to add a custom system prompt to the [prebuilt ReAct agent](https://langchain-ai.github.io/langgraph/reference/prebuilt/#langgraph.prebuilt.chat_agent_executor.create_react_agent). Please see [this tutorial](../create-react-agent) for how to get started with the prebuilt ReAct agent\n",
|
||||
"\n",
|
||||
"You can add a custom system prompt by passing a string to the `state_modifier` param.\n"
|
||||
"You can add a custom system prompt by passing a string to the `prompt` param.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -144,7 +144,7 @@
|
||||
"\n",
|
||||
"from langgraph.prebuilt import create_react_agent\n",
|
||||
"\n",
|
||||
"graph = create_react_agent(model, tools=tools, state_modifier=prompt)"
|
||||
"graph = create_react_agent(model, tools=tools, prompt=prompt)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -195,7 +195,7 @@
|
||||
"source": [
|
||||
"## Using in `create_react_agent`\n",
|
||||
"\n",
|
||||
"Add semantic search to your tool calling agent by injecting the store in the `state_modifier`. You can also use the store in a tool to let your agent manually store or search for memories."
|
||||
"Add semantic search to your tool calling agent by injecting the store in the `prompt` function. You can also use the store in a tool to let your agent manually store or search for memories."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -248,9 +248,9 @@
|
||||
"agent = create_react_agent(\n",
|
||||
" init_chat_model(\"openai:gpt-4o-mini\"),\n",
|
||||
" tools=[upsert_memory],\n",
|
||||
" # The state_modifier is run to prepare the messages for the LLM. It is called\n",
|
||||
" # The 'prompt' function is run to prepare the messages for the LLM. It is called\n",
|
||||
" # right before each LLM call\n",
|
||||
" state_modifier=prepare_messages,\n",
|
||||
" prompt=prepare_messages,\n",
|
||||
" store=store,\n",
|
||||
")"
|
||||
]
|
||||
@@ -524,7 +524,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.2"
|
||||
"version": "3.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -229,7 +229,7 @@
|
||||
"travel_advisor = create_react_agent(\n",
|
||||
" model,\n",
|
||||
" travel_advisor_tools,\n",
|
||||
" state_modifier=(\n",
|
||||
" prompt=(\n",
|
||||
" \"You are a general travel expert that can recommend travel destinations (e.g. countries, cities, etc). \"\n",
|
||||
" \"If you need hotel recommendations, ask 'hotel_advisor' for help. \"\n",
|
||||
" \"You MUST include human-readable response before transferring to another agent.\"\n",
|
||||
@@ -254,7 +254,7 @@
|
||||
"hotel_advisor = create_react_agent(\n",
|
||||
" model,\n",
|
||||
" hotel_advisor_tools,\n",
|
||||
" state_modifier=(\n",
|
||||
" prompt=(\n",
|
||||
" \"You are a hotel expert that can provide hotel recommendations for a given destination. \"\n",
|
||||
" \"If you need help picking travel destinations, ask 'travel_advisor' for help.\"\n",
|
||||
" \"You MUST include human-readable response before transferring to another agent.\"\n",
|
||||
|
||||
@@ -555,7 +555,7 @@
|
||||
"travel_advisor = create_react_agent(\n",
|
||||
" model,\n",
|
||||
" travel_advisor_tools,\n",
|
||||
" state_modifier=(\n",
|
||||
" prompt=(\n",
|
||||
" \"You are a general travel expert that can recommend travel destinations (e.g. countries, cities, etc). \"\n",
|
||||
" \"If you need hotel recommendations, ask 'hotel_advisor' for help. \"\n",
|
||||
" \"You MUST include human-readable response before transferring to another agent.\"\n",
|
||||
@@ -579,7 +579,7 @@
|
||||
"hotel_advisor = create_react_agent(\n",
|
||||
" model,\n",
|
||||
" hotel_advisor_tools,\n",
|
||||
" state_modifier=(\n",
|
||||
" prompt=(\n",
|
||||
" \"You are a hotel expert that can provide hotel recommendations for a given destination. \"\n",
|
||||
" \"If you need help picking travel destinations, ask 'travel_advisor' for help.\"\n",
|
||||
" \"You MUST include human-readable response before transferring to another agent.\"\n",
|
||||
|
||||
@@ -180,7 +180,7 @@
|
||||
" state: AgentState,\n",
|
||||
" config: RunnableConfig,\n",
|
||||
"):\n",
|
||||
" # this is similar to customizing the create_react_agent with state_modifier, but is a lot more flexible\n",
|
||||
" # this is similar to customizing the create_react_agent with 'prompt' parameter, but is more flexible\n",
|
||||
" system_prompt = SystemMessage(\n",
|
||||
" \"You are a helpful AI assistant, please respond to the users query to the best of your ability!\"\n",
|
||||
" )\n",
|
||||
|
||||
@@ -220,7 +220,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def state_modifier(state: State):\n",
|
||||
"def prompt(state: State):\n",
|
||||
" user_info = state.get(\"user_info\")\n",
|
||||
" if user_info is None:\n",
|
||||
" return state[\"messages\"]\n",
|
||||
@@ -265,7 +265,7 @@
|
||||
" [lookup_user_info],\n",
|
||||
" state_schema=State,\n",
|
||||
" # pass dynamic prompt function\n",
|
||||
" state_modifier=state_modifier,\n",
|
||||
" prompt=prompt,\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -201,7 +201,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"research_agent = create_react_agent(\n",
|
||||
" llm, tools=[tavily_tool], state_modifier=\"You are a researcher. DO NOT do any math.\"\n",
|
||||
" llm, tools=[tavily_tool], prompt=\"You are a researcher. DO NOT do any math.\"\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"\n",
|
||||
|
||||
@@ -525,7 +525,7 @@
|
||||
"doc_writer_agent = create_react_agent(\n",
|
||||
" llm,\n",
|
||||
" tools=[write_document, edit_document, read_document],\n",
|
||||
" state_modifier=(\n",
|
||||
" prompt=(\n",
|
||||
" \"You can read, write and edit documents based on note-taker's outlines. \"\n",
|
||||
" \"Don't ask follow-up questions.\"\n",
|
||||
" ),\n",
|
||||
@@ -548,7 +548,7 @@
|
||||
"note_taking_agent = create_react_agent(\n",
|
||||
" llm,\n",
|
||||
" tools=[create_outline, read_document],\n",
|
||||
" state_modifier=(\n",
|
||||
" prompt=(\n",
|
||||
" \"You can read documents and create outlines for the document writer. \"\n",
|
||||
" \"Don't ask follow-up questions.\"\n",
|
||||
" ),\n",
|
||||
|
||||
@@ -190,7 +190,7 @@
|
||||
"research_agent = create_react_agent(\n",
|
||||
" llm,\n",
|
||||
" tools=[tavily_tool],\n",
|
||||
" state_modifier=make_system_prompt(\n",
|
||||
" prompt=make_system_prompt(\n",
|
||||
" \"You can only do research. You are working with a chart generator colleague.\"\n",
|
||||
" ),\n",
|
||||
")\n",
|
||||
@@ -220,7 +220,7 @@
|
||||
"chart_agent = create_react_agent(\n",
|
||||
" llm,\n",
|
||||
" [python_repl_tool],\n",
|
||||
" state_modifier=make_system_prompt(\n",
|
||||
" prompt=make_system_prompt(\n",
|
||||
" \"You can only generate charts. You are working with a researcher colleague.\"\n",
|
||||
" ),\n",
|
||||
")\n",
|
||||
|
||||
@@ -143,7 +143,7 @@
|
||||
"# Choose the LLM that will drive the agent\n",
|
||||
"llm = ChatOpenAI(model=\"gpt-4-turbo-preview\")\n",
|
||||
"prompt = \"You are a helpful assistant.\"\n",
|
||||
"agent_executor = create_react_agent(llm, tools, state_modifier=prompt)"
|
||||
"agent_executor = create_react_agent(llm, tools, prompt=prompt)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user