llamaIndex - 💡(How to fix) Fix [Bug]: Missing AgentStream.thinking_delta when using Anthropic LLM with FunctionAgent [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
run-llama/llama_index#21408Fetched 2026-04-18 05:51:54
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Timeline (top)
labeled ×2commented ×1

Root Cause

With Anthropic streaming (thinking blocks/deltas), AgentStream.thinking_delta remains empty/missing in FunctionAgent output because Anthropic package does not set ChatResponse.additional_kwargs["thinking_delta"].

RAW_BUFFERClick to expand / collapse

Bug Description

FunctionAgent / AgentWorkflow streaming only forwards thinking content from:

  • ChatResponse.additional_kwargs["thinking_delta"]

This causes missing AgentStream.thinking_delta when a provider emits reasoning/thinking deltas in provider-native fields/blocks but does not normalize them into ChatResponse.additional_kwargs.

Observed Behavior

With Anthropic streaming (thinking blocks/deltas), AgentStream.thinking_delta remains empty/missing in FunctionAgent output because Anthropic package does not set ChatResponse.additional_kwargs["thinking_delta"].

Expected Behavior

For all LLM providers that support reasoning/thinking streaming, FunctionAgent should reliably receive thinking chunks in AgentStream.thinking_delta.

Why this happens

Workflow code is provider-agnostic but assumes one normalized location: ChatResponse.additional_kwargs["thinking_delta"].

If an integration emits thinking elsewhere (e.g., block-specific fields) and does not mirror into additional_kwargs, thinking is dropped from workflow event stream.

Suggested Fix

In Anthropic streaming integration (and any other provider with reasoning streams), normalize each thinking chunk into:

  • ChatResponse.additional_kwargs["thinking_delta"] = <chunk>

Optionally, as defense-in-depth in workflow layer:

  • fallback extraction from message blocks when additional_kwargs["thinking_delta"] is absent.

Version

0.14.20

Steps to Reproduce

  1. Create a FunctionAgent(streaming=True) with Anthropic model that emits thinking deltas.
  2. Stream agent events.
  3. Observe AgentStream.delta and final response are present.
  4. Observe AgentStream.thinking_delta missing/empty for all chunks.

Relevant Logs/Tracebacks

extent analysis

TL;DR

Normalize thinking chunks into ChatResponse.additional_kwargs["thinking_delta"] for all LLM providers that support reasoning/thinking streaming.

Guidance

  • Update the Anthropic streaming integration to set ChatResponse.additional_kwargs["thinking_delta"] for each thinking chunk.
  • Consider adding a fallback extraction mechanism in the workflow layer to extract thinking deltas from message blocks when additional_kwargs["thinking_delta"] is absent.
  • Verify that AgentStream.thinking_delta is populated correctly after implementing the suggested fix.
  • Review other LLM provider integrations to ensure they also normalize thinking chunks into ChatResponse.additional_kwargs["thinking_delta"].

Example

# Example of normalizing thinking chunks in Anthropic streaming integration
def anthropic_streaming_integration(thinking_chunk):
    chat_response = ChatResponse()
    chat_response.additional_kwargs["thinking_delta"] = thinking_chunk
    return chat_response

Notes

This fix assumes that all LLM providers can be updated to normalize thinking chunks into ChatResponse.additional_kwargs["thinking_delta"]. If some providers cannot be updated, the fallback extraction mechanism in the workflow layer may be necessary.

Recommendation

Apply workaround by normalizing thinking chunks into ChatResponse.additional_kwargs["thinking_delta"] for all LLM providers, as this will ensure that FunctionAgent reliably receives thinking chunks in AgentStream.thinking_delta.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

llamaIndex - 💡(How to fix) Fix [Bug]: Missing AgentStream.thinking_delta when using Anthropic LLM with FunctionAgent [1 comments, 2 participants]