Hello I’m pretty new to LangGraph in general but I’m experiencing some issues with recalling using a checkpointer.
So I do have this setup:
import {
Annotation,
StateGraph,
MessagesAnnotation,
START,
END,
MemorySaver,
} from '@langchain/langgraph';
import { createReactAgent } from '@langchain/langgraph/prebuilt';
import { ChatOpenAI } from '@langchain/openai';
import { tools } from './tools';
// LLm model
const llm = new ChatOpenAI({
model: 'gpt-4o',
temperature: 0,
});
// Agent
const agent = createReactAgent({
llm,
tools,
});
// State
const StateAnnotation = Annotation.Root({
...MessagesAnnotation.spec,
test: Annotation<string>(),
});
const graph = new StateGraph(StateAnnotation);
// Nodes
const node1 = async (state: typeof StateAnnotation.State) => {
const { messages, test } = state;
const lastMessage = messages[messages.length - 1];
const result = await agent.invoke(
{
messages: [lastMessage],
},
{
configurable: { thread_id: '1' },
},
);
return result;
};
// Graph
graph.addNode('node1', node1).addEdge(START, 'node1').addEdge('node1', END);
const checkpointer = new MemorySaver();
export const compiledGraph = graph.compile({
checkpointer,
});
And working with it mainly from langgraph studio.
Now on my first prompt i’m sending for example:
user: ‘Hello my name is John’
assistant: ‘Hello John how can I help you today?’
On my second input i’m asking:
user: ‘What is my name?’
assistant: ‘I’m sorry, but I don’t have access to personal data…’
I see If i pass here:
const result = await agent.invoke(
{
messages: [lastMessage],
},
{
configurable: { thread_id: '1' },
},
);
All of the messages it’s able to recall my name but at the same time I don’t want to use all of the previous conversation as a Input ( at least this is how i’m thinking could be wrong tho )
Also I’m using MessagesAnnotation.spec
which I’m aware takes care for the messages inside the state with the reducer and everything but how writing is happening there? I feel like something are happening under the hood and is hard to understand whats going on.
Any advices are much appreciated it!