[KongchangAI]
· 2 min read· 1,407 words

AI SDK Batch Update: ToolLoopAgent and Multi-Provider Compatibility Fixes

AI SDK Batch Update: ToolLoopAgent and Multi-Provider Compatibility Fixes

AI SDK ships a broad patch update fixing Anthropic streaming resume, Google mid-conversation instructions, and OpenAI-compatible billing mapping.

The AI SDK released a wide-ranging patch update, bumping core ai to 7.1.1 with a read-only settings getter on ToolLoopAgent, cascading to React, Vue, Svelte, RSC, and LangChain packages. Fixes include Anthropic streaming failures when message_start carries server tool results, Google mid-conversation system instructions with stable prompt caching, OpenAI-compatible cache_write_tokens mapping to avoid double-counting, and Workflow delegating toUIMessageChunk to the core package to preserve metadata.

rss source: @ai-sdk/tui@1.0.192: Version Packages (#25819)

The AI SDK has shipped a broad patch-level update. The core package ai is bumped to 7.1.1, with its React, Vue, Svelte, RSC, LangChain, and LlamaIndex integration packages following suit. There's no major version jump here, but the changes touch several issues that genuinely affect production environments: Anthropic streaming resume, Google's mid-conversation system instructions, cache billing in the OpenAI-compatible layer, and message-chunk fidelity in the Workflow package.

Core package changes: read-only settings on ToolLoopAgent

The main change in ai@7.1.1 comes from a single commit that adds a read-only settings getter to ToolLoopAgent. For developers who need to inspect an agent's configuration at runtime, this means they no longer have to rely on internal fields or maintain their own copy of the config—they can read the current settings state directly. It's a small change, but a textbook API observability improvement: it exposes key state of the wrapper layer while the read-only constraint prevents external mutation of internal state.

This change also cascades to a large number of downstream packages: @ai-sdk/react, @ai-sdk/vue, @ai-sdk/svelte, @ai-sdk/rsc, @ai-sdk/langchain, @ai-sdk/llamaindex, @ai-sdk/otel, @ai-sdk/devtools, and others are all bumped because they depend on ai@7.1.1. These chained updates are common in a Changesets-driven release flow, and they show that downstream packages strictly track the core package's semantic version.

Anthropic: fix for lost tool results during streaming resume

@ai-sdk/anthropic@4.0.115 fixes a specific but tricky scenario: when a resumed Anthropic response includes server-side tool results within the message_start content, streaming would fail. The new handling treats these results as standalone content blocks, preserving the tool results and their source information.

The root of the problem is the "resume-from-checkpoint" scenario for streaming responses. When Anthropic server tools return results mid-response, the resume logic previously failed to correctly recognize this nested structure, causing tool results to be dropped or parsed incorrectly. For applications that rely on tool calls for multi-turn reasoning, this kind of bug often manifests as "silent tool failures" that are costly to diagnose.

Server tools and streaming resume: Anthropic's Messages API supports server-side execution of tools (such as web search and code execution) within streaming responses, with results returned as server_tool_use and corresponding result blocks. Streaming resume refers to the client rebuilding stream state from already-received events such as message_start after a connection drops. If the message_start content already contains server tool results, the resume logic must recognize these nested blocks—otherwise they get discarded as ordinary text. The AI SDK fix promotes such results to standalone content blocks, preserving tool results and source references across resume, and avoiding "silent failures" in multi-turn tool reasoning.

Google: mid-conversation system instructions and expanded safety categories

@ai-sdk/google@4.0.133 brings three changes. The most notable is support for "mid-conversation system instructions" and function-tool updates in the Google Interactions API: the position of system messages is preserved via a system_input step, while baseline instructions and tool definitions stay stable so prompt caching still hits. This effectively resolves a long-standing tension: inserting new system instructions into a multi-turn conversation breaks the cache prefix, whereas the new implementation makes instruction positions explicit, balancing flexibility with cache efficiency.

The other two changes are more defensive: adding HARM_CATEGORY_JAILBREAK and HARM_CATEGORY_IMAGE_* categories to safetySettings[].category; and declaring deprecated models directly in catalog entries, replacing the previous scattered lists of model IDs or comments, while retaining historical capabilities and ID compatibility. The same "inline model catalog declaration" change also appears in @ai-sdk/openai and @ai-sdk/mistral, which can be seen as a unified cleanup of model metadata management across the SDK.

Prompt caching and system instruction placement: Google Gemini's context caching relies on a stable prefix—once system instructions or tool definitions change mid-conversation, the cache key is invalidated and subsequent requests are billed again. The traditional approach pins system instructions at the start of the conversation, but in multi-turn dialogue a user may ask to temporarily change roles or rules. The Google Interactions API's system_input step allows system messages to be inserted mid-conversation while explicitly keeping baseline instructions and tool definitions unchanged, so the cache prefix remains stable and only the newly added portion is billed. The AI SDK's support for this mechanism gives developers the flexibility of dynamic instructions while maintaining cache hit rates.

OpenAI-compatible layer: billing attribution for cache write tokens

@ai-sdk/openai-compatible@3.0.100 corrects the mapping of prompt_tokens_details.cache_write_tokens: it now maps to inputTokens.cacheWrite and is deducted from inputTokens.noCache. This is a classic usage-accounting correctness issue. In some compatible implementations, cache write tokens get double-counted as non-cached input, inflating cost estimates. For teams doing token metering, bill allocation, or cost monitoring, this kind of mapping error shows up directly in reconciliation data.

Cache write tokens and billing mapping: OpenAI-compatible APIs distinguish cached_tokens (cache-hit reads) from cache_write_tokens (writes into cache) in prompt_tokens_details. The former is typically billed at a discount, while the latter may be billed at the regular input rate or a separate rate. If the compatibility layer counts cache_write_tokens as noCache (non-cached input) as well, total input tokens are inflated and cost estimates run high. The AI SDK now maps them to inputTokens.cacheWrite and deducts them from noCache, making token metering and bill allocation more accurate. For systems that rely on usage data for cost monitoring, quota management, or multi-tenant reconciliation, this kind of mapping fix directly affects the credibility of financial data.

Workflow: delegating message chunking to the core package

The fix direction in @ai-sdk/workflow@2.0.123 is clear: toUIMessageChunk no longer maintains its own switch branches, but delegates standard stream parts to ai's toUIMessageChunk. This change preserves content that was previously easy to lose—provider custom parts (e.g., openai.compaction), tool result and error metadata (preliminary, providerExecuted, providerMetadata, toolMetadata, dynamic), reasoning-file, tool-approval-response, and citation information.

At the same time, error redaction behavior and the sendSources default (false) are aligned with the core package. toUIMessageChunk and createModelCallToUIChunkTransform now both accept and forward sendReasoning, sendSources, onError, and redactToolErrors. Behind this is an architectural judgment: the format-conversion logic for message chunks should have a single source of truth, and duplicate implementations are a breeding ground for metadata loss.

UIMessageChunk and a single source of truth: UIMessageChunk is a streaming message-chunk format defined by the AI SDK for transporting incremental content between the server and the UI layer, covering text deltas, tool calls, reasoning parts, citations, and errors. Different providers carry custom metadata (such as providerMetadata, providerExecuted, preliminary), and if each adapter package implements chunk conversion on its own, fields are easily missed. The Workflow package now delegates to the core ai package's toUIMessageChunk, centralizing all metadata and error-redaction logic in one place. This follows the architectural principle that "format conversion should have only one implementation," and reduces the risk of data loss when downstream packages fail to keep up with new provider features.

The maintenance cadence behind the version numbers

This update illustrates the AI SDK's release structure: the core ai package and dozens of provider packages, framework adapters, and tooling packages are versioned independently, with Changesets automatically generating PRs and publishing to npm. High-frequency small version numbers like @ai-sdk/tui@1.0.192 reflect continuous patch-level delivery rather than the accumulation of major feature milestones.

The practical advice for users: if your project relies on Anthropic streaming resume, Google mid-conversation system instructions, or the OpenAI-compatible layer for cost accounting, this patch is worth following. If you only use basic text generation, the marginal benefit of upgrading is limited. Either way, pay attention to dependency coupling between provider packages—upgrading ai often requires upgrading the upper-layer adapter packages in tandem to get all the fixes.

One-line Summary

AI SDK ships a broad patch update fixing Anthropic streaming resume, Google mid-conversation instructions, and OpenAI-compatible billing mapping.

Paragraph Summary

The AI SDK released a wide-ranging patch update, bumping the core ai package to 7.1.1 and adding a read-only settings getter to ToolLoopAgent, which cascaded to React, Vue, Svelte, RSC, LangChain, and other integration packages. The update addresses several production issues: the Anthropic provider fixes streaming failures caused by server tool results in message_start during resumed responses; the Google provider supports mid-conversation system instructions via system_input while keeping prompt caching stable, and expands safety categories; the OpenAI-compatible layer corrects cache_write_tokens mapping to avoid double-counting cache write tokens as non-cached input; and the Workflow package's toUIMessageChunk now delegates to the core implementation, preserving custom parts and tool metadata. The article advises that projects relying on these scenarios should follow the update, while those using only basic text generation see limited marginal benefit—but in all cases, note the dependency coupling between provider packages.

#AI SDK#ToolLoopAgent#Anthropic streaming#prompt caching#OpenAI-compatible
Share:

Related articles