1

I'm using langgraph.js to create a simple chatbot.

When the session has ended I'd like to be able to delete the thread but I haven't been able to find any way to do this in the docs.

     this.graph = new StateGraph(AssistantState)
            .addNode('route_node', this.routeNode.bind(this))
            .addNode('init_node', this.initNode.bind(this))
            .addNode('agent', this.agentNode.bind(this))

            .addEdge(START, 'route_node')
            .addConditionalEdges('route_node', async (state) => state.route)

            .addEdge('init_node', END)
            .addEdge('agent', END)

            .compile({ checkpointer: new MemorySaver() })

Any ideas how this is done? Thanks!

0

1 Answer 1

0

as far as I've investigated there is no built in way to delete a thread, which doesn't make sense in my opinion if that's the case. Anyways here is a workaround:


function createEmptyCheckpoint() {
    return {
        v: 1,
        ts: new Date().toISOString(),
        id: crypto.randomUUID(),
        channel_values: {},
        channel_versions: {
            __start__: 1,
        },
        versions_seen: {
            __input__: {},
            __start__: {}
        },
        pending_sends: [],
    };
}

async function clearThread(checkpointer: any, threadId: string) {
    const config = {
        configurable: {
            thread_id: threadId,
            checkpoint_ns: ""
        }
    };

    const emptyCheckpoint = createEmptyCheckpoint();

    await checkpointer.put(config, emptyCheckpoint, {}, {});
}

https://github.com/langchain-ai/langchain/discussions/19744

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.