Skip to content

regenerate response doesn't work with create_agent in langgraph #6618

@junan-trustarc

Description

@junan-trustarc

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

from typing import Annotated, TypedDict

from langchain.agents import create_agent
from langchain.chat_models import BaseChatModel, init_chat_model
from langchain_core.messages import BaseMessage
from langgraph.graph import StateGraph, add_messages


class TempState(TypedDict):
    messages: Annotated[list[BaseMessage], add_messages]


class TempGraphService:
    def __init__(self):
        self.llm: BaseChatModel = init_chat_model(model="anthropic:claude-sonnet-4-5")
        self.agent = create_agent("anthropic:claude-sonnet-4-5")

    def build_graph(self):
        graph_builder = StateGraph(state_schema=TempState)
        graph_builder.add_node("node1", self.get_node)
        graph_builder.set_entry_point("node1")
        return graph_builder.compile()

    async def get_node(self, state: TempState):
        messages = state["messages"]

        # using init_chat_model (works)
        # result = await self.llm.ainvoke(messages)
        # return {"messages": [result]}

        # using create_agent
        # this is not working, when re-generate response is happening, agent invoking doesn't call LLM and just return previous response.
        result = await self.agent.ainvoke({"messages": messages})
        return {"messages": [result["messages"][-1]]}

Error Message and Stack Trace (if applicable)

Description

As you can see above code, regenerate response is working with init_chat_model but not working with create_agent.
It looks like returning previous AI message without calling LLM even though this is re-generate case.
create_agent with built-in middleware has a lot of advantages but it should support regenerate features otherwise I can't switch over.

How to repro:

  1. write "Hi" in human message and send.
  2. then AI will response like "Hello! How can I help you today?"
  3. click re-generate icon from langsmith studio
  4. it should create new branch and response should be switchable but it doesn't work when create_agent is used.
Image

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 25.1.0: Mon Oct 20 19:34:05 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6041
Python Version: 3.13.7 (main, Sep 18 2025, 22:52:34) [Clang 20.1.4 ]

Package Information

langchain_core: 1.2.0
langsmith: 0.4.59
langgraph_api: 0.6.11
langgraph_runtime_inmem: 0.20.1
langgraph_sdk: 0.3.0

Optional packages not installed

langserve

Other Dependencies

blockbuster: 1.5.26
cloudpickle: 3.1.2
cryptography: 44.0.3
grpcio: 1.76.0
grpcio-tools: 1.75.1
httpx: 0.28.1
jsonpatch: 1.33
jsonschema-rs: 0.29.1
langgraph: 1.0.5
langgraph-checkpoint: 3.0.1
opentelemetry-api: 1.39.1
opentelemetry-exporter-otlp-proto-http: 1.39.1
opentelemetry-sdk: 1.39.1
orjson: 3.11.5
packaging: 25.0
protobuf: 6.33.2
pydantic: 2.12.5
pyjwt: 2.10.1
pyyaml: 6.0.3
requests: 2.32.5
requests-toolbelt: 1.0.0
sse-starlette: 2.1.3
starlette: 0.50.0
structlog: 25.5.0
tenacity: 9.1.2
truststore: 0.10.4
typing-extensions: 4.15.0
uuid-utils: 0.12.0
uvicorn: 0.38.0
watchfiles: 1.1.1
zstandard: 0.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpendingawaiting review/confirmation by maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions