Skip to content

🐛 Bug: Thread Reloading not working with LangGraph + AG-UI Interface ? #2200

Closed

Description

@bobbyo

♻️ Reproduction Steps

  1. Clone and run demo repo CopilotKit / with-langgraph-fastapi, try changing threadId

See repro details in gitub issue I filed in the with-langgraph-fastapi:
CopilotKit/with-langgraph-fastapi#1

  1. Alternate: open fresh directory, follow Copilotkit Langgraph Quickstart self-hosted Fastapi demo docs at
    https://docs.copilotkit.ai/coagents/quickstart?path=code-along&agent=coagents-starter&copilot-hosting=self-hosted&lg-deployment-type=Self+hosted+%28FastAPI%29

This was on 2025/07/20. That demo page switched to the agui approach recently; from that demo page:

add_langgraph_fastapi_endpoint(
  app=app,
  agent=LangGraphAGUIAgent(
    name="sample_agent", # the name of your agent defined in langgraph.json
    description="Describe your agent here, will be used for multi-agent orchestration",
    graph=graph, # the graph object from your langgraph import
  ),
  path="/your-agent-path", # the endpoint you'd like to serve your agent on
)

✅ Expected Behavior

Expected

set threadId on copilotkit chat component, see thread reload from langgraph backend and display the user's original messages and tool calls. (set on the component prop ,or via the setThreadId from the hook, as described in CopilotKit/with-langgraph-fastapi#1 )

const { threadId: copilotKitThreadId, setThreadId: copilotKitSetThreadId } = useCopilotContext();

const firstThreadId = threadId;
setThredId(secondThreadId);  // Should load the messages of secondThreadId from backend and display in chat UI

...

❌ Actual Behavior

Observed

Changing threadId does not affect the chat UI.
The chat continues.

const { threadId: copilotKitThreadId, setThreadId: copilotKitSetThreadId } = useCopilotContext();

const firstThreadId = threadId;
setThredId(secondThreadId);  // Observed No change in chat UI. But adding UI element <h1>{threadId}</h1> as sibling to the chat component proves threadId was set

𝌚 CopilotKit Version

https://github.com/CopilotKit/with-langgraph-fastapi/blob/2170f41e8dd7837bbaa9da9f544bd68440faf0b1/package.json#L18

:~/CopilotKit-github/with-langgraph-fastapi (addcors)$ pnpm ls | grep '@copilotkit'
@copilotkit/react-core 1.9.2
@copilotkit/react-ui 1.9.2
@copilotkit/runtime 1.9.2

📄 Logs (Optional)

Activity

  1. added
    bug
    on Jul 21, 2025
  2. alexvarden commented on Jul 24, 2025

    @alexvarden

    I have found a workaround for the moment bobbyo by passing a Textmessage manually and handling within langgraph by skipping when my agent receives
    <<<loading>>>

    
    import {  TextMessage, Role } from "@copilotkit/runtime-client-gql";
    import { CopilotChat } from "@copilotkit/react-ui";
    
    const { appendMessage } = useCopilotChat();
    
    // after threadId has been changed
    appendMessage(
        new TextMessage({
          content: "<<<loading>>>",
          role: Role.System,
        }),
        { followUp: true }
    );
    
    
  3. tymkiwdylan commented on Jul 24, 2025

    @tymkiwdylan

    Any updates on this? I am having the same issue.

  4. bobbyo commented on Jul 25, 2025

    @bobbyo
    Author

    @alexvarden thanks; you mean you manually append a special message after changing the threadId and that makes the UI reload all of the historical chat messages, tool calls, etc--full history reload into the chat?

  5. alexvarden commented on Jul 25, 2025

    @alexvarden

    @bobbyo yes, this seems to initiate the chat and loads in previous messages

  6. Sneruall commented on Jul 25, 2025

    @Sneruall

    I have a question related to this: The docs explain how to dynamically switch between threads by setting the threadId, but I couldn't find any documentation on how to properly create a new thread from the frontend. Is there a recommended way to trigger a truly new/empty thread (e.g., by setting threadId to "" or undefined)? In my case, doing this does not clear the previous messages, the old chat history from other thread leaks into the new thread.

    As a workaround, I currently force a component remount by changing the key prop on the CopilotKit component whenever a new thread is created. This ensures a clean state, but is not a good solution. Is there an official approach for new thread creation, or is this a known issue?

  7. bobbyo commented on Jul 29, 2025

    @bobbyo
    Author

    @Sneruall have you tried assigning a new UUID as the threadId, e.g. using one of the copilotkit use* hooks ?

  8. roman-rr commented on Jul 30, 2025

    @roman-rr

    reset() hook is works for new ThreadId, but loading state message is still big issue.

  9. added and removed
    bug
    on Aug 27, 2025
  10. jhanke00 commented on Sep 26, 2025

    @jhanke00

    Note

    This is for LangGraph CoPilotKit Python implementation.

    My team found that self.thread_state manages the existing thread_id state. The CoPilotKit UI will make a call for /agents/state to fetch the thread's current state which makes a call to get_state. Whenever you switch threads or try to refresh the same thread, it will not update with the latest state changes because the thread state comes from self.thread_state and only gets updates when there is no value for that thread_id.

    if self.thread_state.get(thread_id, None) is None:
    self.thread_state[thread_id] = {**(await self.graph.aget_state(config)).values}

    This is the only place that the thread_state gets updated, but when there is an update the agent_state it doesn't update thread_state, so when you change the thread_id it still has the old state that was initially loaded. Often this will be empty which is why we see an empty conversation and threadExists as false.

    What my team found is whenever the current_graph_state gets updated we just need to update the self.thread_state[thread_id] to match the current_graph_state so that it keeps in sync with changes to the graph on that thread. This would still reduce the number of calls to get the state that was the intention behind introducing this thread_state in this PR as the updates would happen within the agent on any updates.

    My team will open a PR to add these changes. If this was an intended behavior by the maintainers, let me know if we are incorrect with our observations.

    #2516

  11. david-morris commented on Sep 30, 2025

    @david-morris

    I'm also having these issues.

    This is needed for e.g. running langgraph in a lambda or allowing chat to work when reloading.

    Thanks @jhanke00 , trying #2516 by hand-writing the patch into my site-packages turned out to be the easiest way to test.

  12. bobbyo commented on Oct 10, 2025

    @bobbyo
    Author

    @david-morris fyi -- I opened PR #2605 to fix the backend part of this issue. That PR removes a stale state caching bug introduced in PR #2063. I believe that is one of the resons thread history has not worked since the pre-AG-UI code (around copilotkit 1.9.1 or .2). It also leaves the single source of truth on state with the checkpointer, which is more robust and likely fixes other thread-history issues. If there is a perf hit from this, a follow-on PR should profile the issue and add a single source of truth for state, maybe caching wrapper or equivalent.

    Caveat: Frontend issues remain.

  13. 9 remaining items

  14. nawangwe commented on Dec 10, 2025

    @nawangwe

    Can we please get an update on this massive blocker please?

  15. PvH-SPC commented on Dec 12, 2025

    @PvH-SPC

    Hi i think this is related to this thread, but we have migrated from the remoteEndpoint approach to connect to a langgraph agent to the new, the old way the history for a given thread would load using the langgraph chechpointer. Now with the new, i think the AgentRunner defaults to 'in memory' even for agents, and as such while the history is still in the checkpointer, the history used to rehydrate the UI comes from the in memory store, if you restart the runtime server its all lost, and doesnt refresh from the langsmith checkpointer. Is there a way to pass through like it did before, so we dont store memory in the copilotkit runtime server, but always reload from the python apis?

    Here is some sample code its quite simple:

    
      const runtime = new CopilotRuntime({
        agents: {
          "chat_agent": new LangGraphHttpAgent({ 
            url: pythonBackend + "/agents/chat_agent",
            headers: {
              "authorization": req.headers.authorization
            }
          })
        }
      })
    

    and python:

    
    @copilotkit_router.post("/agents/{agent_name}")
    async def run_agent(
        agent_name: str,
        request: Request,
        input_data: RunAgentInput,
      ):
        print(f"Received {request.method} request for path: {agent_name}")
       
        graph = request.app.state.graphs[agent_name]
    
        agent = LangGraphAGUIAgent(
            name=agent_name,  # the name of your agent defined in langgraph.json
            description="This is a generic chat agent that can be used to search the internet and answer questions.",
            graph=graph,  # the graph object from your langgraph import
            config={
                "configurable": {
                    "session_maker": request.app.state.async_session_maker,  # Pass session maker instead of ChatService
                    **input_data.forwarded_props
                }
            }
        )
    
    ``
    I think thats what this thread is discussing?  I would have thought it would work out of the box that way, but maybe a custom runner is needed to proxy back to back end or just disable all together?
    
    Thank you!
    Peter
    
  16. joeychrys commented on Dec 21, 2025

    @joeychrys

    Hi i think this is related to this thread, but we have migrated from the remoteEndpoint approach to connect to a langgraph agent to the new, the old way the history for a given thread would load using the langgraph chechpointer. Now with the new, i think the AgentRunner defaults to 'in memory' even for agents, and as such while the history is still in the checkpointer, the history used to rehydrate the UI comes from the in memory store, if you restart the runtime server its all lost, and doesnt refresh from the langsmith checkpointer. Is there a way to pass through like it did before, so we dont store memory in the copilotkit runtime server, but always reload from the python apis?

    Here is some sample code its quite simple:

    
      const runtime = new CopilotRuntime({
        agents: {
          "chat_agent": new LangGraphHttpAgent({ 
            url: pythonBackend + "/agents/chat_agent",
            headers: {
              "authorization": req.headers.authorization
            }
          })
        }
      })
    

    and python:

    
    @copilotkit_router.post("/agents/{agent_name}")
    async def run_agent(
        agent_name: str,
        request: Request,
        input_data: RunAgentInput,
      ):
        print(f"Received {request.method} request for path: {agent_name}")
       
        graph = request.app.state.graphs[agent_name]
    
        agent = LangGraphAGUIAgent(
            name=agent_name,  # the name of your agent defined in langgraph.json
            description="This is a generic chat agent that can be used to search the internet and answer questions.",
            graph=graph,  # the graph object from your langgraph import
            config={
                "configurable": {
                    "session_maker": request.app.state.async_session_maker,  # Pass session maker instead of ChatService
                    **input_data.forwarded_props
                }
            }
        )
    
    ``
    I think thats what this thread is discussing?  I would have thought it would work out of the box that way, but maybe a custom runner is needed to proxy back to back end or just disable all together?
    
    Thank you!
    Peter
    
    

    I was able to get in touch with support on discord. Their solution is to create a custom AgentRunner. I was able to make one that loads checkpoints by using the Langgraph Platform API endpoints. It all just seems inefficient especially when you want to start adding auth. Not to be conspiratorial but it feel like their lack of support on this is a way to sell their cloud platform. Their recommendation to move your app into production is to use their cloud offering to store thread information...

  17. souzantero commented on Dec 23, 2025

    @souzantero

    Hi i think this is related to this thread, but we have migrated from the remoteEndpoint approach to connect to a langgraph agent to the new, the old way the history for a given thread would load using the langgraph chechpointer. Now with the new, i think the AgentRunner defaults to 'in memory' even for agents, and as such while the history is still in the checkpointer, the history used to rehydrate the UI comes from the in memory store, if you restart the runtime server its all lost, and doesnt refresh from the langsmith checkpointer. Is there a way to pass through like it did before, so we dont store memory in the copilotkit runtime server, but always reload from the python apis?
    Here is some sample code its quite simple:

    
      const runtime = new CopilotRuntime({
        agents: {
          "chat_agent": new LangGraphHttpAgent({ 
            url: pythonBackend + "/agents/chat_agent",
            headers: {
              "authorization": req.headers.authorization
            }
          })
        }
      })
    

    and python:

    
    @copilotkit_router.post("/agents/{agent_name}")
    async def run_agent(
        agent_name: str,
        request: Request,
        input_data: RunAgentInput,
      ):
        print(f"Received {request.method} request for path: {agent_name}")
       
        graph = request.app.state.graphs[agent_name]
    
        agent = LangGraphAGUIAgent(
            name=agent_name,  # the name of your agent defined in langgraph.json
            description="This is a generic chat agent that can be used to search the internet and answer questions.",
            graph=graph,  # the graph object from your langgraph import
            config={
                "configurable": {
                    "session_maker": request.app.state.async_session_maker,  # Pass session maker instead of ChatService
                    **input_data.forwarded_props
                }
            }
        )
    
    ``
    I think thats what this thread is discussing?  I would have thought it would work out of the box that way, but maybe a custom runner is needed to proxy back to back end or just disable all together?
    
    Thank you!
    Peter
    

    I was able to get in touch with support on discord. Their solution is to create a custom AgentRunner. I was able to make one that loads checkpoints by using the Langgraph Platform API endpoints. It all just seems inefficient especially when you want to start adding auth. Not to be conspiratorial but it feel like their lack of support on this is a way to sell their cloud platform. Their recommendation to move your app into production is to use their cloud offering to store thread information...

    I understand your point of view, and I even think it makes sense to look at it this way, after all, they need to make money somehow. That said, from an engineering perspective, this feels a bit like shooting yourself in the foot.

    If you already have a backend agent using some framework, whether it’s LangChain, Mastra, the Agent SDK, or any other. Those frameworks already provide mechanisms to manage threads, state, messages, and so on. If CopilotKit tries to handle the same things, you end up with redundancy: duplicated state, duplicated threads, duplicated message handling. I don’t think that’s something people would see as a good or clean adoption pattern.

    In that scenario, CopilotKit would essentially need to become a backend agent framework itself, built on top of or alongside existing agent frameworks. And at that point, it starts to drift away from what I see as its main purpose, which is being frontend-oriented.

    Personally, I’d really like to see threads and state being driven by the backend agent and properly synchronized with the frontend, without this kind of duplication. Anyway, just sharing this as a point for discussion and something worth thinking through.

  18. erowan commented on Jan 7, 2026

    @erowan

    Hello @NathanTarbert can you comment on copilots direction on state management for self-hosted deployments.

  19. ElishaKay commented on Feb 3, 2026

    @ElishaKay
    Contributor

    You can achieve the copilotkit<->langgraph thread history with a custom runner plugged into copilotkit. Got a simple example working here:

    https://github.com/ElishaKay/copilotkit-starter-template

  20. martinvillarreal5 commented on Feb 5, 2026

    @martinvillarreal5

    Any update on this? we're still having problems with thread reloading

  21. added a commit that references this issue on Apr 4, 2026
  22. willymateo commented on Apr 6, 2026

    @willymateo

    Hi guys, any update about this bug? I'm having the same issue with:
    frontend: nextjs + copilotkit
    backend: fastapi
    agents: deepagents library from langchain
    checkpointer: dynamodb + s3

  23. agherasim commented on Apr 15, 2026

    @agherasim

    +1, AGUI reloading session from Google ADK endpoint over fastapi is not running.

  24. joeychrys commented on Jul 9, 2026

    @joeychrys

    Is this resolved?

  25. NathanTarbert commented on Jul 9, 2026

    @NathanTarbert
    Contributor

    Hey folks, @joeychrys, we released full thread support with CopilotKit Enterprise Intelligence, which runs both as a managed cloud and self-hosted.

    We've put a lot of work into making both best-in-class with minimal setup, and self-hosting means you keep full ownership of your data if that matters to you.

    Intelligence threads support everything your agent does:
    → Every kind of generative UI, user file uploads, and (soon) voice transcripts
    → Realtime multicast across devices
    → Automatic resumption on page refresh or network disconnection, even mid-run
    → Automatic migrations as AG-UI evolves and new generative UI variants land, so your thread history never gets lost or corrupted on upgrade
    If you're curious about the underlying architecture, it's covered here.

    You can also import existing conversations from LangChain or ADK and keep them in sync perpetually going forward. So if you're using those native threads for analytics or anything else downstream, that keeps working as-is. It's not an either/or choice, and you're not starting from scratch.

    Turning it on is basically a flag flip, then everything works with the useThreads hook or the built-in CopilotThreadsDrawer UI component (full docs here):

    // app/api/copilotkit/route.ts
    import { CopilotRuntime, IntelligenceAgentRunner } from "@copilotkit/runtime/v2";
    
    const runtime = new CopilotRuntime({
      agents: { default: defaultAgent },
    
      intelligence: new CopilotKitIntelligence({
        apiKey: process.env.INTELLIGENCE_API_KEY,
      }),
    
      // Demo stub — replace with your real auth-derived user identity before any
      // multi-user deployment, or all users share one thread history.
      identifyUser: (req) => ({ id: "demo-user", name: "Demo User" }),
    })
    
    
    // drop-in thread sidebar, zero wiring
    <CopilotThreadsDrawer />
    <CopilotChat />

    Starts at $39/month for personal use, full details on our pricing page.
    Docs: https://docs.copilotkit.ai/premium/overview

    Happy to hop on a short call if you want to dig in.

  26. added
    bug
    and removed on Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions