-
Notifications
You must be signed in to change notification settings - Fork 880
Description
When implementing a simple LangGraph app that exposes itself via a FastAPI interface using AG-UI and connecting to it using Copilotkit's Chat interface, I cannot get the system to regenerate a message. I get the following error message:
ValueError: Checkpointer requires one or more of the following 'configurable' keys: thread_id, checkpoint_ns, checkpoint_id
I'm using:
- copilotkit python sdk 0.1.70
- langgraph 0.6.11
- langgraph-checkpoint 2.1.0
- ag-ui-protocol 0.1.9
- ag-ui-langgraph 0.0.18
And in the frontend side:
- "@ag-ui/langgraph": "0.0.18"
- "@copilotkit/react-core": "1.10.6"
A minimal reproducible example follows:
graph.py
import operator
import uuid
from typing import Optional, TypedDict, Annotated
from langchain_core.messages import AnyMessage, AIMessage, SystemMessage
from langchain_core.runnables import RunnableConfig
class AgentState(TypedDict):
messages: Annotated[list[AnyMessage], operator.add]
async def input_node(state:AgentState, config: Optional[RunnableConfig] = None):
messages = state.get('messages')
last_message = messages[-1]
if config is None:
config = RunnableConfig(recursion_limit=25)
a_message = AIMessage(
role="assistant",
content=f"Processed: {last_message.content}",
id=str(uuid.uuid4())
)
return {"messages": [a_message]}
workflow = StateGraph(AgentState)
checkpointer = InMemorySaver()
workflow.add_node("input", input_node)
workflow.set_entry_point("input")
workflow.add_edge("input", END)
graph = workflow.compile(checkpointer=checkpointer)
main.py
import os
import sys
import uuid
import uvicorn
from fastapi import FastAPI
from ag_ui_langgraph import LangGraphAgent, add_langgraph_fastapi_endpoint
from graph import graph # Import the LangGraph agent
# Initialize FastAPI application instance
app = FastAPI(title="LangGraph Agent")
# Wrap the agent in the SDK Class
agent = LangGraphAgent(name="main_agent", graph=graph)
# Use the built-in function to create the FastAPI endpoint
add_langgraph_fastapi_endpoint(
app=app, agent=agent, path="/agent"
)
def main():
port = int(os.getenv("PORT", "8000"))
uvicorn.run(
"main:app", # Reference to the FastAPI app instance
host="0.0.0.0", # Listen on all available interfaces
port=port, # Use the configured port
reload=True, # Enable auto-reload for development
)
if __name__ == "__main__":
main()
In the frontend:
layout.tsx
import type { Metadata } from "next";
import { CopilotKit } from "@copilotkit/react-core";
export const metadata: Metadata = {
title: "AI Chat agent",
description: "AI Chat agent",
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>
<CopilotKit runtimeUrl="/api/copilotkit" agent="chat_agent">
{children}
</CopilotKit>
</body>
</html>
);
}
page.tsx
"use client";
import { CopilotChat } from "@copilotkit/react-ui";
import "@copilotkit/react-ui/styles.css";
export default function CopilotKitPage() {
return (
<main>
<CopilotChat
instructions={"You are assisting the user as best as you can. Answer in the best way possible given the data you have."}
labels={{
initial : "I am a LangGraph AI agent. Say something to me!",
}}
/>
</main>
)
}
route.ts
import {
CopilotRuntime,
ExperimentalEmptyAdapter,
copilotRuntimeNextJSAppRouterEndpoint
} from "@copilotkit/runtime";
import { LangGraphHttpAgent } from "@ag-ui/langgraph"
import { NextRequest } from "next/server";
const serviceAdapter = new ExperimentalEmptyAdapter();
const chat_agent = new LangGraphHttpAgent({
url: "http://127.0.0.1:8000/agent",
});
const runtime = new CopilotRuntime({
agents: {
chat_agent,
},
});
export const POST = async (req: NextRequest) => {
const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
serviceAdapter,
endpoint: "/api/copilotkit",
});
return handleRequest(req);
};
I see the same (?) issue in the current version of the AG-UI dojo (https://dojo.ag-ui.com/).
When I select the LangGraph FastAPI integration, the interface does not regenerate anything when I click the "regenerate" button.
However, when I select the LangGraph Python integration, the "regenerate" button works as expected.