[PR #1023] [MERGED] langgraph: allow passing custom state & let message modifiers access state in create_react_agent #1838

Closed
opened 2026-02-20 17:45:40 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraph/pull/1023
Author: @vbarda
Created: 7/15/2024
Status: Merged
Merged: 7/16/2024
Merged by: @vbarda

Base: mainHead: vb/customize-react-agent


📝 Commits (10+)

📊 Changes

3 files changed (+241 additions, -42 deletions)

View changed files

📝 libs/langgraph/langgraph/_api/deprecation.py (+24 -3)
📝 libs/langgraph/langgraph/prebuilt/chat_agent_executor.py (+159 -26)
📝 libs/langgraph/tests/test_prebuilt.py (+58 -13)

📄 Description

Addressing #991

This change allows passing custom, user-defined agent_state schema to StateGraph, as well as a new, custom state_modifier parameter that takes in the whole graph state and prepares inputs to the LLM

SYSTEM_INIT_PROMPT = """
You are a helpful assistant.

Today is {today}.
"""

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", SYSTEM_INIT_PROMPT),
        ("placeholder", "{messages}"),
    ]
)

class AgentState(TypedDict):
    today: str
    messages: Annotated[list[BaseMessage], add_messages]
    is_last_step: str


new_react_agent = create_react_agent(model, [search], state_schema=AgentState, state_modifier=prompt)
new_react_agent.invoke({
    "messages": [("human", "what's the weather in sf? make sure to mention today's date")], 
    "today": "July 12, 2004"
})

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraph/pull/1023 **Author:** [@vbarda](https://github.com/vbarda) **Created:** 7/15/2024 **Status:** ✅ Merged **Merged:** 7/16/2024 **Merged by:** [@vbarda](https://github.com/vbarda) **Base:** `main` ← **Head:** `vb/customize-react-agent` --- ### 📝 Commits (10+) - [`725ef23`](https://github.com/langchain-ai/langgraph/commit/725ef23b46570e449bdaf38f70e917c539b18b56) [RFC] langgraph: allow passing custom state & let message modifiers access state - [`c62815c`](https://github.com/langchain-ai/langgraph/commit/c62815c086fabab404bbc6e97ddc779faf997ccd) update - [`c574df7`](https://github.com/langchain-ai/langgraph/commit/c574df7d19e0f9948ce6be922a60cc9c90e4f14c) add a new kwarg and mark for deprecation - [`91c5b86`](https://github.com/langchain-ai/langgraph/commit/91c5b860d9608493401edfa46e2574127e1fca8d) Merge branch 'main' into vb/customize-react-agent - [`90e31bd`](https://github.com/langchain-ai/langgraph/commit/90e31bda1a9189777fa91b86ba3b4a0f4184907b) simplify - [`87212dd`](https://github.com/langchain-ai/langgraph/commit/87212dd532d01722f38f10dce71510e001ddac0f) add tests - [`f3d8ec5`](https://github.com/langchain-ai/langgraph/commit/f3d8ec542800b39395108287f4edb6f9c722ee9d) code review - [`f56b945`](https://github.com/langchain-ai/langgraph/commit/f56b945d277f4085ce756359c06ae1def2bcf64a) update docstring + code review - [`2c584e8`](https://github.com/langchain-ai/langgraph/commit/2c584e80648fd1774d885d6d995a4d4acb9d2b48) better name - [`84525fe`](https://github.com/langchain-ai/langgraph/commit/84525fe2bae41f800760a8810e31e903e30346b7) better name ### 📊 Changes **3 files changed** (+241 additions, -42 deletions) <details> <summary>View changed files</summary> 📝 `libs/langgraph/langgraph/_api/deprecation.py` (+24 -3) 📝 `libs/langgraph/langgraph/prebuilt/chat_agent_executor.py` (+159 -26) 📝 `libs/langgraph/tests/test_prebuilt.py` (+58 -13) </details> ### 📄 Description Addressing #991 This change allows passing custom, user-defined `agent_state` schema to `StateGraph`, as well as a new, custom `state_modifier` parameter that takes in the whole graph state and prepares inputs to the LLM ```python SYSTEM_INIT_PROMPT = """ You are a helpful assistant. Today is {today}. """ prompt = ChatPromptTemplate.from_messages( [ ("system", SYSTEM_INIT_PROMPT), ("placeholder", "{messages}"), ] ) class AgentState(TypedDict): today: str messages: Annotated[list[BaseMessage], add_messages] is_last_step: str new_react_agent = create_react_agent(model, [search], state_schema=AgentState, state_modifier=prompt) new_react_agent.invoke({ "messages": [("human", "what's the weather in sf? make sure to mention today's date")], "today": "July 12, 2004" }) ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-20 17:45:40 -05:00
yindo closed this issue 2026-02-20 17:45:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#1838