From 1a6c3114f3c0412af0914a17f8418cf439713474 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Thu, 19 Dec 2024 01:46:33 +0800 Subject: [PATCH] fix example in docs of state_schema in create_react_agent (#2109) because in ```python def call_model( state: AgentState, config: RunnableConfig, ) ... if ( ( "remaining_steps" not in state and state["is_last_step"] and has_tool_calls ) ``` https://github.com/langchain-ai/langgraph/blob/c0b56bf60d84ed435609c35b0691cd0305ceae78/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py#L543 the AgentState requires is_last_step to have a default value, like `False`, and `IsLastStep` can satisfy it. --------- Co-authored-by: Vadym Barda --- libs/langgraph/langgraph/prebuilt/chat_agent_executor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py index 4c8699360..b5207d167 100644 --- a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py @@ -382,6 +382,8 @@ class Agent,Tools otherClass ```pycon >>> from typing import TypedDict + >>> + >>> from langgraph.managed import IsLastStep >>> prompt = ChatPromptTemplate.from_messages( ... [ ... ("system", "Today is {today}"), @@ -392,7 +394,7 @@ class Agent,Tools otherClass >>> class CustomState(TypedDict): ... today: str ... messages: Annotated[list[BaseMessage], add_messages] - ... is_last_step: str + ... is_last_step: IsLastStep >>> >>> graph = create_react_agent(model, tools, state_schema=CustomState, state_modifier=prompt) >>> inputs = {"messages": [("user", "What's today's date? And what's the weather in SF?")], "today": "July 16, 2004"}