contextEditingMiddleware doesn't work

I am trying contextEditingMiddleware for one our use case. I don’t see the middleware being invoked at all. Tried with lot of configuration but did n’t see the log. code snippet

const supervisor = createAgent({

  model: llm,  

tools: workerTools,

checkpointer,  /

middleware: [

loggingMiddleware2,

contextEditingMiddleware({

edits: [

new ClearToolUsesEdit({

triggerTokens: 2000,      // Lower threshold for demo (default is 100K)

keep: { messages: 3 },    // Keep 3 most recent tool results

clearToolInputs: false,   // Keep tool call arguments for context

excludeTools: [],         // No tools excluded from clearing

placeholder: "[cleared]", // Placeholder for cleared results

        }),

      ],

tokenCountMethod: "approx", // Use approximate counting for speed

    }),

  ],

systemPrompt: `system prompt`,

});

even if i don’t see the function trace in langsmith (waterfall). See the pic attached. Any other configuration that I am missing here?

Thanks for reporting, I will take a look into this.

have you got a chance to look at the issue ?

I created a reproduction case here: GitHub - christian-bromann/contexteditingrepro: Small reproduction case reproducing a potential bug in the ContextEditing middleware - it seems to me that the contextEditingMiddleware was correctly invoked. Unfortunately it is not visible at all within the LangSmith waterfall since the middleware uses the wrapModelCall hook which is not displayed in LangSmith. I will bring this back to the team so see how we can improve the UI here.

thank you for the update. Let me recheck the app. if I am not wrong, the token size was also not reduced after the threshold was reached. However, I will reverify and the update here.

PS: I had also followed LangChain video on this https://www.youtube.com/watch?v=Gkv0L_32SPU

Looks like your assessment is correct. I did verify again. I could see the token size (count) is being reset. See the screenshot attached. All these are part of a single thread_id.