Back Home

GitHub Repo

langchain-anthropic 1.7.4 Supports Adding and Removing Tools Mid-Conversation

The new version uses system messages to convey tool changes, allowing agents to adjust their capabilities in stages and potentially preserve existing prompt caches. The feature is still subject to model, message-position, and cache-setting limitations, and no performance test data is available.

Dirck van Baburen · Public domain · Image source
zh-Hant

LangChain released langchain-anthropic 1.7.4 on September 23, enabling ChatAnthropic to send tool addition and removal information through `SystemMessage` objects in a conversation. The package is also available on PyPI. This closes a gap between the framework and the provider’s native interface for long-running agents that need to make capabilities available in stages. [Release notes](https://github.com/langchain-ai/langchain/releases/tag/langchain-anthropic==1.7.4), [package page](https://pypi.org/project/langchain-anthropic/1.7.4/)

The pull request says this kind of content could previously be lost during conversion or trigger HTTP 400 errors that were difficult to interpret. The new version preserves `tool_addition` and `tool_removal` blocks and accepts both native dictionaries and `non_standard` wrappers. Developers can append tool definitions after a user’s question so the model can call them in later steps. [Pull request](https://github.com/langchain-ai/langchain/pull/40758)

The engineering benefit is less disruption to prompt caching when switching tools. Anthropic’s documentation explains that the top-level tool list sits at the start of the cache prefix, so changing it invalidates the cache that follows. Appending changes later in the conversation can preserve the existing prefix. This allows agents to provide tools as a task progresses without rewriting the initial list each time; actual savings still depend on whether caching is enabled and whether cache hits occur. [Documentation on caching and tool changes](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages)

The implementation checks the outgoing system messages: if a block carries new tool definitions directly, it automatically adds the inline-tools beta header; if a block only references tools to add or remove, it adds the earlier tool-change header when needed. A new integration test uses Claude Opus 5.5 to confirm that the model returns the specified tool call, but the test does not measure long-conversation latency, cost, or success rates across models. [Code and tests](https://github.com/langchain-ai/langchain/pull/40758/files)

The upgrade also introduces a compatibility change: unrecognized content blocks in system messages are now removed with a warning; tool changes made mid-conversation may also be discarded if moved to the top level. Maintainers should inspect the actual outgoing requests and warning logs rather than assuming tool configuration took effect based only on the final answer. [Conversion logic](https://github.com/langchain-ai/langchain/pull/40758/files)

Before deployment, check the model and message-position limitations. There is also a caching exception: if the initial list contains no non-deferred-loading tools, defining a tool in a message for the first time will still cause a full cache miss. [Official limitations](https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages) Engineering teams can replay the same conversation history against requests from before and after the upgrade to verify the add, remove, and retry flows, then compare cache read volume, input costs, and time to first token. Services with existing long conversation histories should also confirm that tool sets and error handling remain consistent, helping distinguish the gains from wiring up the interface from differences caused by model choice and cache settings.

Sources

  1. Release langchain-anthropic==1.7.4
  2. langchain-anthropic 1.7.4
  3. feat(anthropic,openai): mid-conversation tool changes on SystemMessage
  4. PR #40758:程式碼與整合測試
  5. Mid-conversation system messages and tool changes