Skip to content

[GSoC 2026] chatbot: LangChain 1.x migration (create_agent) — Refs #3833#3842

Merged
mlodic merged 2 commits into
developfrom
gsoc-2026/llm-chatbot-langchain-1x
Jul 3, 2026
Merged

[GSoC 2026] chatbot: LangChain 1.x migration (create_agent) — Refs #3833#3842
mlodic merged 2 commits into
developfrom
gsoc-2026/llm-chatbot-langchain-1x

Conversation

@berardifra

Copy link
Copy Markdown
Contributor

Migrates the chatbot agent engine from the deprecated AgentExecutor + create_tool_calling_agent (LangChain 0.3.x) to create_agent on 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, DjangoChatMessageHistory memory, and multi-tenant tool scoping are untouched.

Why

  • AgentExecutor is deprecated; create_agent is the supported API.
  • Security: GHSA-gr75-jv2w-4656 is fixed only in langchain>=1.3.9. Bumping to 1.3.11 removes the exposure, so the dependency_review.yml allow-ghsas entry for it is removed in this same PR.

Changes

  • agent.py: build_agent() -> ChatAgent(runnable, tool_names) via create_agent(model, tools, system_prompt); final_answer() helper; RECURSION_LIMIT = 2*rounds + 2 (=14, LangGraph counts supersteps, not agent rounds); page_context baked into the system prompt.
  • streaming.py: ChatStreamConsumer consuming stream_mode=["messages","values"], emitting identical token/status/action_required events and returning the terminal answer (no callback handler).
  • tasks.py / views.py: GraphRecursionError -> ITERATION_LIMIT (the AGENT_STOPPED_OUTPUT sentinel no longer exists in 1.x); agent input is a messages list.
  • deps: langchain==1.3.11, langchain-ollama==1.1.0 (langchain-core / langgraph stay transitive, unpinned).

Testing

All 168 tests.api_app.chatbot_manager tests 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 the analyze_observable pending_id preview path are unchanged.

Refs #3833

…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 mlodic merged commit d6839b8 into develop Jul 3, 2026
10 checks passed
@berardifra berardifra deleted the gsoc-2026/llm-chatbot-langchain-1x branch July 3, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gsoc-2026 GSoC 2026 - LLM Chatbot project (Francesco Berardi)

Development

Successfully merging this pull request may close these issues.

2 participants