From 729637a347cceac75201f3f89ea48f135d9d75ba Mon Sep 17 00:00:00 2001 From: ccurme Date: Mon, 29 Sep 2025 16:38:01 -0400 Subject: [PATCH] docs(anthropic): document support for memory tool and context management (#33149) --- docs/docs/integrations/chat/anthropic.ipynb | 66 +++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/docs/docs/integrations/chat/anthropic.ipynb b/docs/docs/integrations/chat/anthropic.ipynb index 091ba69fd5f..215eeeb756d 100644 --- a/docs/docs/integrations/chat/anthropic.ipynb +++ b/docs/docs/integrations/chat/anthropic.ipynb @@ -1191,6 +1191,40 @@ "response.content" ] }, + { + "cell_type": "markdown", + "id": "74247a07-b153-444f-9c56-77659aeefc88", + "metadata": {}, + "source": [ + "## Context management\n", + "\n", + "Anthropic supports a context editing feature that will automatically manage the model's context window (e.g., by clearing tool results).\n", + "\n", + "See [Anthropic documentation](https://docs.claude.com/en/docs/build-with-claude/context-editing) for details and configuration options.\n", + "\n", + ":::info\n", + "Requires ``langchain-anthropic>=0.3.21``\n", + ":::" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cbb79c5d-37b5-4212-b36f-f27366192cf9", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_anthropic import ChatAnthropic\n", + "\n", + "llm = ChatAnthropic(\n", + " model=\"claude-sonnet-4-5-20250929\",\n", + " betas=[\"context-management-2025-06-27\"],\n", + " context_management={\"edits\": [{\"type\": \"clear_tool_uses_20250919\"}]},\n", + ")\n", + "llm_with_tools = llm.bind_tools([{\"type\": \"web_search_20250305\", \"name\": \"web_search\"}])\n", + "response = llm_with_tools.invoke(\"Search for recent developments in AI\")" + ] + }, { "cell_type": "markdown", "id": "cbfec7a9-d9df-4d12-844e-d922456dd9bf", @@ -1457,6 +1491,38 @@ "" ] }, + { + "cell_type": "markdown", + "id": "29405da2-d2ef-415c-b674-6e29073cd05e", + "metadata": {}, + "source": [ + "### Memory tool\n", + "\n", + "Claude supports a memory tool for client-side storage and retrieval of context across conversational threads. See docs [here](https://docs.claude.com/en/docs/agents-and-tools/tool-use/memory-tool) for details.\n", + "\n", + ":::info\n", + "Requires ``langchain-anthropic>=0.3.21``\n", + ":::" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bbd76eaa-041f-4fb8-8346-ca8fe0001c01", + "metadata": {}, + "outputs": [], + "source": [ + "from langchain_anthropic import ChatAnthropic\n", + "\n", + "llm = ChatAnthropic(\n", + " model=\"claude-sonnet-4-5-20250929\",\n", + " betas=[\"context-management-2025-06-27\"],\n", + ")\n", + "llm_with_tools = llm.bind_tools([{\"type\": \"memory_20250818\", \"name\": \"memory\"}])\n", + "\n", + "response = llm_with_tools.invoke(\"What are my interests?\")" + ] + }, { "cell_type": "markdown", "id": "040f381a-1768-479a-9a5e-aa2d7d77e0d5",