fix: migrate from deprecated create_react_agent to langchain.agents.create_agent (#802)

* fix: migrate from deprecated create_react_agent to langchain.agents.create_agent

Fixes #799

- Replace deprecated langgraph.prebuilt.create_react_agent with
  langchain.agents.create_agent (LangGraph 1.0 migration)
- Add DynamicPromptMiddleware to handle dynamic prompt templates
  (replaces the 'prompt' callable parameter)
- Add PreModelHookMiddleware to handle pre-model hooks
  (replaces the 'pre_model_hook' parameter)
- Update AgentState import from langchain.agents in template.py
- Update tests to use the new API

* fix:update the code with review comments
This commit is contained in:
Willem Jiang
2026-01-07 09:06:16 +08:00
committed by GitHub
parent 1ced90b055
commit d4ab77de5c
5 changed files with 440 additions and 14 deletions

View File

@@ -2,10 +2,10 @@
# SPDX-License-Identifier: MIT
"""
Unit tests for agent locale restoration after create_react_agent execution.
Unit tests for agent locale restoration after agent execution.
Tests that meta fields (especially locale) are properly restored after
agent.ainvoke() returns, since create_react_agent creates a MessagesState
agent.ainvoke() returns, since the agent creates a MessagesState
subgraph that filters out custom fields.
"""
@@ -22,7 +22,7 @@ class TestAgentLocaleRestoration:
"""
Demonstrate the problem: agent subgraph filters out locale.
When create_react_agent creates a subgraph with MessagesState,
When the agent creates a subgraph with MessagesState,
it only returns messages, not custom fields.
"""
# Simulate agent behavior: only returns messages