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

Aperta
#2,085 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
43/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?
Lingua principale
Python
Stelle
4.1k
Fork
915
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di anthropics/anthropic-sdk-python

Tutte le issue di anthropics/anthropic-sdk-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.