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

@@ -42,7 +42,7 @@ class TestToolInterceptorIntegration:
tools = [search_tool, db_tool]
# Create agent with interrupts on db_tool only
with patch("src.agents.agents.create_react_agent") as mock_create, \
with patch("src.agents.agents.langchain_create_agent") as mock_create, \
patch("src.agents.agents.get_llm_by_type") as mock_llm:
mock_create.return_value = MagicMock()
mock_llm.return_value = MagicMock()
@@ -55,7 +55,7 @@ class TestToolInterceptorIntegration:
interrupt_before_tools=["db_tool"],
)
# Verify create_react_agent was called with wrapped tools
# Verify langchain_create_agent was called with wrapped tools
assert mock_create.called
call_args = mock_create.call_args
wrapped_tools = call_args.kwargs["tools"]