Sonnet 5.5 / Opus 5.5: streamed text after a tool_result arrives in one burst at the end of the turn

未关闭
#2,085 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
43/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api

调研方向

Start with the messages.stream event handling and tests for content_block_delta in this SDK, then compare the captured event timings for Sonnet 5.5 and Sonnet 5. The reproduction script and request IDs are provided in the issue. Done means determining whether the SDK changes or delays these events and documenting or fixing the behavior supported by the evidence.

由索引模型根据 Issue 内容生成。

描述

Summary

With claude-sonnet-5-5 (and claude-opus-5-5), when a turn follows a tool_result, all of its text_delta events arrive within a few milliseconds of each other at the end of the turn. They are not streamed while the text is generated. The same turn on claude-sonnet-5 streams normally, and so does Sonnet 5.5 when no tool result precedes the turn. For a chat interface this means several seconds of blank screen before every answer that uses a tool.

We couldn't find a setting in the docs that changes this. Anthropic's support chat could neither confirm whether it is intended nor pass it on, so we're raising it here. If this repo is the wrong place for API behaviour, please point us to the right one.

Environment

  • anthropic Python SDK 1.8.0, Python 3.12, macOS
  • messages.stream with one client tool, output_config.effort: "medium", adaptive thinking (the default)

Measurements

Timings are from the request start to each text_delta, for a ~150-word answer:

Request Text deltas First text First to last
Sonnet 5.5, no tools in the request 120 0.93 s 4.1 s
Sonnet 5.5, tools present, answered without a tool 80 1.03 s 2.7 s
Sonnet 5.5, turn after a tool_result 78-105 3.2-4.3 s 3-6 ms
... with thinking.display: "updates" (beta) 95 3.8 s 5 ms
... with thinking: {type: "between_tools"} 86 3.8 s 6 ms
... with tool_choice: {type: "none"} 88 5.6 s 6 ms
... through beta.messages.tool_runner(..., stream=True) 107 6.3 s 5 ms
Opus 5.5, turn after a tool_result 65 5.2 s 5 ms
Sonnet 5, turn after a tool_result 71-83 0.47-0.72 s 3.5-4.1 s

Request IDs (26 Nov 2026, about 13:12 UTC; same prompt, tool and tool result):

  • Sonnet 5.5, burst: answer turn req_011ChRbaHRkLM7bHj6jPWq36 (78 deltas, first at 3.21 s, all within 5 ms); tool turn req_011ChRbaEF1ZaodZwXc15MKu.
  • Sonnet 5, streams: answer turn req_011ChRbaaj4ibt2FetmyJ9iG (71 deltas, first at 0.72 s, spread over 3.54 s); tool turn req_011ChRbaXFhozQVeET8t265a.

Our guess is that the API holds post-tool text until it knows whether the text is a progress update (returned as a thinking block on these models) or the final answer. If so, it would be useful to stream the text once that is decided, or to have a request setting for interfaces where a person watches the answer arrive.

Reproduction

import json, time, anthropic

c = anthropic.Anthropic()
tools = [{"name": "get_rate", "description": "Induction of labour rate for an NHS trust.",
          "input_schema": {"type": "object", "properties": {"trust": {"type": "string"}}, "required": ["trust"]}}]
Q = "What is Southampton's induction of labour rate? Use the tool, then explain it in about 150 words."

def run(model, msgs):
    t0, marks = time.monotonic(), []
    with c.messages.stream(model=model, max_tokens=4000, output_config={"effort": "medium"},
                           tools=tools, messages=msgs) as s:
        for ev in s:
            if ev.type == "content_block_delta" and ev.delta.type == "text_delta":
                marks.append(round((time.monotonic() - t0) * 1000))
        return s.get_final_message(), marks

for model in ("claude-sonnet-5-5", "claude-sonnet-5"):
    msgs = [{"role": "user", "content": Q}]
    m, _ = run(model, msgs)
    tu = next(b for b in m.content if b.type == "tool_use")
    msgs += [{"role": "assistant", "content": m.content},
             {"role": "user", "content": [{"type": "tool_result", "tool_use_id": tu.id,
                                           "content": json.dumps({"rate": 25.8, "births": 5550})}]}]
    m2, marks = run(model, msgs)
    print(model, "deltas", len(marks), "first_ms", marks[0], "spread_ms", marks[-1] - marks[0])

Expected: the deltas on the answer turn are spread over the generation time (as on claude-sonnet-5).
Actual on claude-sonnet-5-5: the spread is about 5 ms, at the end of the turn.

Questions

  1. Is this intended on Sonnet 5.5 and Opus 5.5?
  2. Is a setting planned, or available, that streams the final answer's text as it is generated after a tool call?
主要语言
Python
星标
4.1k
派生
915
PR 合并指标
30 天内没有已合并 PR

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

anthropics/anthropic-sdk-python 的其他 Issue

查看 anthropics/anthropic-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。