Skip to content

Commit

Permalink
fix example in docs of state_schema in create_react_agent (#2109)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jokerkeny and vbarda authored Dec 18, 2024
1 parent 4f1bf4f commit 1a6c311
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libs/langgraph/langgraph/prebuilt/chat_agent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"),
Expand All @@ -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"}
Expand Down

0 comments on commit 1a6c311

Please sign in to comment.