SIGN IN SIGN UP

fix(deepagents): count tokens once per model call in summarization middleware (#595)

## Summary
- Port
[langchain-ai/deepagents#3877](https://github.com/langchain-ai/deepagents/pull/3877):
`createSummarizationMiddleware` now counts tokens once per model call
instead of twice on the common pass-through path.
- Pass the precomputed total into `truncateArgs` via an optional
`totalTokens` parameter; recount only when truncation modifies messages.
- Add a regression test asserting `countTokensApproximately` runs
exactly once when nothing is truncated or summarized.
C
Christian Bromann committed
18fbb4839050e98ae3cfd36ec69b11f0725ad6d6
Parent: 61db938
Committed by GitHub <noreply@github.com> on 6/13/2026, 12:26:50 AM