[GSoC 2026] chatbot: LangChain 1.x migration (create_agent) — Refs #3833#3842
Merged
Conversation
…nt (Refs #3833) Replace the deprecated AgentExecutor + create_tool_calling_agent with create_agent on the LangGraph runtime. External behavior and the chat WebSocket wire protocol are unchanged. - agent.py: build_agent() -> ChatAgent(runnable, tool_names) via create_agent(model, tools, system_prompt); page_context baked into the system prompt; final_answer() helper. - streaming.py: ChatStreamConsumer consumes stream_mode=["messages","values"] and emits the same token/status/action_required events, returning the terminal answer (no callbacks). - tasks.py / views.py: GraphRecursionError -> ITERATION_LIMIT (the AGENT_STOPPED_OUTPUT sentinel no longer exists in 1.x); agent input is a messages list. - RECURSION_LIMIT = 2*rounds + 2 (=14): LangGraph bounds a run by supersteps, not agent rounds. - deps: langchain==1.3.11, langchain-ollama==1.1.0 (core/langgraph stay transitive). - security: remove the dependency-review allow-ghsas for GHSA-gr75-jv2w-4656 (fixed in langchain>=1.3.9, so the allowlist is no longer needed). All 168 chatbot tests pass; a live Ollama smoke confirms token streaming, tool-call visibility and the M-1 pending_id path are unchanged.
… tests (Refs #3833) - test_agent.py: index the ToolMessage list instead of a bare next() (PTC-W0063). - test_streaming.py / test_query_counts.py: make the self-less test helpers static (_make_consumer, the _FakeRunnable.stream fake) (PYL-R0201). Behavior unchanged; 168 chatbot tests still green.
mlodic
approved these changes
Jul 3, 2026
This was referenced Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrates the chatbot agent engine from the deprecated
AgentExecutor+create_tool_calling_agent(LangChain 0.3.x) tocreate_agenton the LangGraph runtime (LangChain 1.3.11). Drop-in engine swap — external behavior and the chat WebSocket contract (events.py) are unchanged; the M-1 guardrail,DjangoChatMessageHistorymemory, and multi-tenant tool scoping are untouched.Why
AgentExecutoris deprecated;create_agentis the supported API.langchain>=1.3.9. Bumping to 1.3.11 removes the exposure, so thedependency_review.ymlallow-ghsasentry for it is removed in this same PR.Changes
agent.py:build_agent() -> ChatAgent(runnable, tool_names)viacreate_agent(model, tools, system_prompt);final_answer()helper;RECURSION_LIMIT = 2*rounds + 2(=14, LangGraph counts supersteps, not agent rounds);page_contextbaked into the system prompt.streaming.py:ChatStreamConsumerconsumingstream_mode=["messages","values"], emitting identicaltoken/status/action_requiredevents and returning the terminal answer (no callback handler).tasks.py/views.py:GraphRecursionError -> ITERATION_LIMIT(theAGENT_STOPPED_OUTPUTsentinel no longer exists in 1.x); agent input is amessageslist.langchain==1.3.11,langchain-ollama==1.1.0(langchain-core / langgraph stay transitive, unpinned).Testing
All 168
tests.api_app.chatbot_managertests pass on a rebuilt test image (LLM mocked, no real Ollama/HTTP). A live Ollama smoke (qwen2.5:3b) confirms token-by-token streaming, tool-call visibility, and theanalyze_observablepending_id preview path are unchanged.Refs #3833