# Strategies for Context Management

**URL:** <https://forum.langchain.com/t/strategies-for-context-management/1839>\
**Category:** Talking Shop\
**Created:** [October 16, 2025, 8:02am UTC](https://forum.langchain.com/t/strategies-for-context-management/1839 "2025-10-16T08:02:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeymanKh](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/peymankh/32/955_2.png) [@PeymanKh](https://forum.langchain.com/u/PeymanKh)\
**Post date:** [October 16, 2025, 8:02am UTC](https://forum.langchain.com/t/strategies-for-context-management/1839/1 "2025-10-16T08:02:46Z")

</div>

Hello friends, I am working on a multi-agent system and wanted to ask how you would approach a challenge I’m facing.

I’m building a ReAct agent with a web search tool, and the topic it researches can require around 40 tool calls. The agent accumulates text after each tool call and passes it to the LLM again, so I need a way to handle this accumulation efficiently to optimize latency and token usage.

One idea I had is to compress the web search results after each tool call. However, LangChain seems to require that each AIMessage with a tool call be followed by a ToolMessage generated in the tool\_node with the same tool\_call\_id in the message history. This prevents me from inserting a compression node that adds a compressed ToolMessage in between.

How would you handle this situation? Are there any resources or design patterns you’d recommend for managing this kind of context growth in a ReAct workflow?

---

<div class="post-metadata">

**Author:** ![pawel-twardziak](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/pawel-twardziak/32/960_2.png) [@pawel-twardziak](https://forum.langchain.com/u/pawel-twardziak)\
**Post date:** [October 16, 2025, 11:41am UTC](https://forum.langchain.com/t/strategies-for-context-management/1839/2 "2025-10-16T11:41:43Z")

</div>

hi @PeymanKh

A few positions:

- [Context Engineering](https://blog.langchain.com/context-engineering-for-agents/)
- [The rise of "context engineering"](https://blog.langchain.com/the-rise-of-context-engineering/)
- [Context engineering in agents - Docs by LangChain](https://docs.langchain.com/oss/python/langchain/context-engineering)
- [How Long Contexts Fail](https://www.dbreunig.com/2025/06/22/how-contexts-fail-and-how-to-fix-them.html)
- [How to Fix Your Context](https://www.dbreunig.com/2025/06/26/how-to-fix-your-context.html)
- [GitHub - langchain-ai/context\_engineering](https://github.com/langchain-ai/context_engineering)
- [GitHub - langchain-ai/how\_to\_fix\_your\_context](https://github.com/langchain-ai/how_to_fix_your_context)
- [https://www.youtube.com/watch?v=6\_BcCthVvb8](https://www.youtube.com/watch?v=6_BcCthVvb8)
- [Deep Agents](https://blog.langchain.com/deep-agents/)

---

<div class="post-metadata">

**Author:** ![PeymanKh](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/peymankh/32/955_2.png) [@PeymanKh](https://forum.langchain.com/u/PeymanKh)\
**Post date:** [October 16, 2025, 4:23pm UTC](https://forum.langchain.com/t/strategies-for-context-management/1839/3 "2025-10-16T16:23:34Z")

</div>

@pawel-twardziak Thank you so much my friend ❤
