Skip to content

🧵 feat: Enable Anthropic Tool Argument Streaming#12962

Merged
danny-avila merged 4 commits into
devfrom
danny-avila/anthropic-fine-grained-tool-streaming
May 6, 2026
Merged

🧵 feat: Enable Anthropic Tool Argument Streaming#12962
danny-avila merged 4 commits into
devfrom
danny-avila/anthropic-fine-grained-tool-streaming

Conversation

@danny-avila

Copy link
Copy Markdown
Owner

Summary

I enabled Anthropic fine-grained tool argument streaming by appending the fine-grained-tool-streaming-2025-05-14 beta header to Anthropic client headers.

  • Added a shared Anthropic beta-header merge helper so existing prompt-cache and web-search beta headers are preserved.
  • Appended the fine-grained tool streaming beta in the Anthropic LLM config path through clientOptions.defaultHeaders.
  • Updated Anthropic endpoint tests to assert the new default beta header and combined beta-header values.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

I validated the behavior with a live Anthropic stream probe for a long single tool argument and confirmed the header causes input_json_delta.partial_json chunks to stream instead of emitting only an empty delta before max_tokens.

I also ran the focused Anthropic endpoint test suite:

NODE_PATH=/Users/danny/Projects/LibreChat/node_modules /Users/danny/Projects/LibreChat/node_modules/.bin/jest --config packages/api/jest.config.mjs packages/api/src/endpoints/anthropic/llm.spec.ts --runInBand

Test Configuration:

  • Anthropic model used for live probe: claude-haiku-4-5-20251001
  • Jest suite: packages/api/src/endpoints/anthropic/llm.spec.ts
  • Result: 89 tests passed

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

Copilot AI review requested due to automatic review settings May 6, 2026 02:09
@danny-avila
danny-avila marked this pull request as ready for review May 6, 2026 02:10
@danny-avila danny-avila changed the title 🧵 fix: Enable Anthropic Tool Argument Streaming 🧵 feat: Enable Anthropic Tool Argument Streaming May 6, 2026
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables Anthropic fine-grained tool argument streaming by ensuring the fine-grained-tool-streaming-2025-05-14 beta value is present in the outgoing anthropic-beta header while preserving any existing beta header values (e.g., prompt-cache related betas).

Changes:

  • Added appendAnthropicBetaHeader() + FINE_GRAINED_TOOL_STREAMING_BETA helper exports for composing anthropic-beta values.
  • Updated Anthropic getLLMConfig() to always append the fine-grained tool streaming beta into clientOptions.defaultHeaders.
  • Updated Anthropic endpoint unit tests to assert the new default/combined anthropic-beta header behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/api/src/endpoints/anthropic/llm.ts Appends the fine-grained tool streaming beta header into Anthropic client default headers.
packages/api/src/endpoints/anthropic/llm.spec.ts Updates assertions to expect the new default and combined anthropic-beta header values.
packages/api/src/endpoints/anthropic/helpers.ts Introduces shared helper + constant for safely composing anthropic-beta header values.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/api/src/endpoints/anthropic/llm.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bbcb2583de

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/endpoints/anthropic/llm.ts Outdated
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-12962 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

1 similar comment
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ab427791f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/endpoints/anthropic/llm.ts
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-12962 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-12962 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-12962 index is now live on the MCP server.
Deploy run

@danny-avila
danny-avila merged commit cf06575 into dev May 6, 2026
15 checks passed
@danny-avila
danny-avila deleted the danny-avila/anthropic-fine-grained-tool-streaming branch May 6, 2026 05:09
fuuuzzy pushed a commit to fuuuzzy/LibreChat that referenced this pull request May 8, 2026
* fix: Enable Anthropic Tool Argument Streaming

* fix: Honor Anthropic clientOptions drops

* fix: Preserve custom Anthropic beta headers

* fix: Enable Bedrock Anthropic Tool Streaming
jcbartle pushed a commit to jcbartle/LibreChat that referenced this pull request May 11, 2026
* fix: Enable Anthropic Tool Argument Streaming

* fix: Honor Anthropic clientOptions drops

* fix: Preserve custom Anthropic beta headers

* fix: Enable Bedrock Anthropic Tool Streaming
inodb added a commit to cBioPortal/LibreChat that referenced this pull request May 17, 2026
Upstream v0.8.6 (danny-avila#12962) auto-applies the
`fine-grained-tool-streaming-2025-05-14` anthropic-beta to all Claude 4+
Bedrock requests. With this header set, the @librechat/agents handler
fails to reassemble the streamed JSON-arg chunks into proper `tool_use`
content blocks for some turns — the raw <function_calls> XML lands in a
plain `text` block in the saved message, and the frontend (correctly)
renders it as text instead of as a tool-call widget.

Observed on cBioDBAgentBeta (us.anthropic.claude-sonnet-4-5-20250929-v1:0)
within minutes of deploying v0.8.6-rc1-custom-v1; tool_call blocks were
the reliable pattern on v0.8.3-rc1-custom-v8 (~10k of them in MongoDB,
two-week sample showed ~190 tool_call blocks vs only 1 XML-in-text).

Workaround: gate the auto-applied beta behind an env var (default off).
Set BEDROCK_FINE_GRAINED_TOOL_STREAMING=true to re-enable once the
agents-SDK reassembly is fixed upstream.
ThomasVuNguyen pushed a commit to ThomasVuNguyen/LibreChat that referenced this pull request Jul 15, 2026
* fix: Enable Anthropic Tool Argument Streaming

* fix: Honor Anthropic clientOptions drops

* fix: Preserve custom Anthropic beta headers

* fix: Enable Bedrock Anthropic Tool Streaming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants