mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-08 02:37:52 +02:00
@@ -225,9 +225,19 @@
|
||||
"# Define the function that responds to the user\n",
|
||||
"def respond(state: AgentState):\n",
|
||||
" # Construct the final answer from the arguments of the last tool call\n",
|
||||
" response = WeatherResponse(**state[\"messages\"][-1].tool_calls[0][\"args\"])\n",
|
||||
" weather_tool_call = state[\"messages\"][-1].tool_calls[0]\n",
|
||||
" response = WeatherResponse(**weather_tool_call[\"args\"])\n",
|
||||
" # Since we're using tool calling to return structured output,\n",
|
||||
" # we need to add a tool message corresponding to the WeatherResponse tool call,\n",
|
||||
" # This is due to LLM providers' requirement that AI messages with tool calls\n",
|
||||
" # need to be followed by a tool message for each tool call\n",
|
||||
" tool_message = {\n",
|
||||
" \"type\": \"tool\",\n",
|
||||
" \"content\": \"Here is your structured response\",\n",
|
||||
" \"tool_call_id\": weather_tool_call[\"id\"],\n",
|
||||
" }\n",
|
||||
" # We return the final answer\n",
|
||||
" return {\"final_response\": response}\n",
|
||||
" return {\"final_response\": response, \"messages\": [tool_message]}\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Define the function that determines whether to continue or not\n",
|
||||
@@ -466,7 +476,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.4"
|
||||
"version": "3.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in New Issue
Block a user