Repository navigation
Closed
Labels
bugSomething isn't working
Description
♻️ Reproduction Steps
- 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
- 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)
Reacted by walker flynn, Sebastian Nystorm, sowrabh-at-featurely and johandieman
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
linear commentedon Jul 21, 2025
CPK-3476 🐛 Bug: Thread Reloading not working with LangGraph + AG-UI Interface ?
alexvarden commentedon Jul 24, 2025
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>>>tymkiwdylan commentedon Jul 24, 2025
Any updates on this? I am having the same issue.
bobbyo commentedon Jul 25, 2025
@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?
alexvarden commentedon Jul 25, 2025
@bobbyo yes, this seems to initiate the chat and loads in previous messages
Sneruall commentedon Jul 25, 2025
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?
bobbyo commentedon Jul 29, 2025
@Sneruall have you tried assigning a new UUID as the threadId, e.g. using one of the copilotkit
use*hooks ?roman-rr commentedon Jul 30, 2025
reset() hook is works for new ThreadId, but loading state message is still big issue.
jhanke00 commentedon Sep 26, 2025
Note
This is for LangGraph CoPilotKit Python implementation.
My team found that
self.thread_statemanages the existingthread_idstate. The CoPilotKit UI will make a call for/agents/stateto fetch the thread's current state which makes a call toget_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 fromself.thread_stateand only gets updates when there is no value for thatthread_id.CopilotKit/sdk-python/copilotkit/langgraph_agent.py
Lines 616 to 617 in 799582f
This is the only place that the
thread_stategets updated, but when there is an update the agent_state it doesn't updatethread_state, so when you change thethread_idit still has the old state that was initially loaded. Often this will be empty which is why we see an empty conversation andthreadExistsasfalse.What my team found is whenever the
current_graph_stategets updated we just need to update theself.thread_state[thread_id]to match thecurrent_graph_stateso 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 thisthread_statein 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
david-morris commentedon Sep 30, 2025
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.
fix(sdk-python): Fix thread state caching bug causing stale state (Co…
bobbyo commentedon Oct 10, 2025
@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.
9 remaining items
nawangwe commentedon Dec 10, 2025
Can we please get an update on this massive blocker please?
PvH-SPC commentedon Dec 12, 2025
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:
and python:
joeychrys commentedon Dec 21, 2025
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...
souzantero commentedon Dec 23, 2025
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.
erowan commentedon Jan 7, 2026
Hello @NathanTarbert can you comment on copilots direction on state management for self-hosted deployments.
ElishaKay commentedon Feb 3, 2026
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
martinvillarreal5 commentedon Feb 5, 2026
Any update on this? we're still having problems with thread reloading
fix(CopilotKit#2200): implement thread reloading with LangGraph + AG-UI
willymateo commentedon Apr 6, 2026
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
agherasim commentedon Apr 15, 2026
+1, AGUI reloading session from Google ADK endpoint over fastapi is not running.
joeychrys commentedon Jul 9, 2026
Is this resolved?
NathanTarbert commentedon Jul 9, 2026
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
useThreadshook or the built-inCopilotThreadsDrawerUI component (full docs here):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.