Messages API: text after a tool_result is held for several seconds, then sent in one burst (claude-sonnet-5-5)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start by running the provided MRE with anthropic 1.5.0 and compare cases A–D using claude-sonnet-5-5 and claude-sonnet-5. Investigate whether the Messages API or client.messages.stream() defines different streaming behavior after a tool_result. Done means confirming whether the delay is intended and identifying a request option or documented workaround if one exists.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug description
On claude-sonnet-5-5, when the latest content in the conversation is a tool_result, the reply isn't streamed as it's generated. Nothing arrives for several seconds, then the first ~2,000 characters arrive in one burst and the rest streams normally. claude-sonnet-5 streams the same request normally. It happens with default settings and at the lowest thinking setting (between_tools), so there's no way to turn it off.
It's reported in more detail, with raw-HTTP repros, on anthropics/claude-code#96439. I'm opening it here as well because it's Messages API behaviour rather than a Claude Code bug.
Evidence
One run each of the MRE below (client.messages.stream(), default settings, one client tool):
| Case | message_start |
Text | Request ID |
|---|---|---|---|
A. history ends in a tool_result |
0.8s | all 123 deltas at 5.2s | req_011CfXzBQPKyCY5FsrJh33E1 |
| B. the same tool pair in an earlier, finished turn | 1.5s | streams 1.5s to 4.8s | req_011CfXzBnPeXTrwcmBkcM1be |
C. tool_result, then the question as a text block |
1.0s | all 137 deltas at 5.7s | req_011CfXzC8njjPwkQKLCKWf4P |
| D. the same information as plain text, no tool pair | 0.8s | streams 0.8s to 4.8s | req_011CfXzCZFuHYkNy8VBXh9tz |
A on claude-sonnet-5 |
0.8s | streams 1.1s to 6.4s | req_011CfXzCur9SX5fwjor1wJmU |
What we found about the trigger:
- It only applies while the
tool_resultis in the current, open turn (A vs B). Adding the user's question after it in the same message doesn't help (C). - The memory tool triggers it on every first reply. With
memory_20250818, Claude views/memoriesbefore answering even when nothing there is relevant, and the answer that follows is held (4.8s and 5.1s:req_011CfXyopdUXpQokJTB7wqic,req_011CfXypFvjxkQpGsQ9J7kJZ). - Context the app fetches itself can avoid it by being sent as plain text instead of a synthetic tool pair (D).
message_startis sometimes held too (5.2s in one run of case A, 0.9s in another, same request).
Impact
In a chat UI, every answer that follows a tool call looks stalled for several seconds and then appears all at once. With the memory tool, that includes the first reply of every conversation.
Question
Is this intended? The thinking docs mention "a pause of several seconds before a progress-update block opens", but not that the final answer itself is held. If it is intended, is there a request option to stream the final answer as it's generated?
MRE
"""pip install anthropic; export ANTHROPIC_API_KEY=...; python mre.py"""
import time
import anthropic
client = anthropic.Anthropic()
ASK = "Write about 200 words on what to pack for a day of sightseeing in Paris."
TOOL = {
"name": "get_weather",
"description": "Get the current weather for a city.",
"input_schema": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]},
}
USE = {"type": "tool_use", "id": "toolu_01", "name": "get_weather", "input": {"city": "Paris"}}
RESULT = {"type": "tool_result", "tool_use_id": "toolu_01", "content": "14C, light rain until 2pm."}
CASES = {
"A: history ends in tool_result": [
{"role": "user", "content": "Check the weather in Paris. " + ASK},
{"role": "assistant", "content": [USE]},
{"role": "user", "content": [RESULT]},
],
"B: same pair in an earlier, finished turn": [
{"role": "user", "content": "Check the weather in Paris."},
{"role": "assistant", "content": [USE]},
{"role": "user", "content": [RESULT]},
{"role": "assistant", "content": "It's 14C with light rain until 2pm."},
{"role": "user", "content": ASK},
],
"C: tool_result, then the question as text": [
{"role": "user", "content": "Check the weather in Paris."},
{"role": "assistant", "content": [USE]},
{"role": "user", "content": [RESULT, {"type": "text", "text": ASK}]},
],
"D: same information as plain text": [
{"role": "user", "content": "Weather in Paris: 14C, light rain until 2pm. " + ASK},
],
}
def run(model, name, messages):
t0 = time.monotonic()
message_start = first = last = None
deltas = 0
with client.messages.stream(model=model, max_tokens=800, tools=[TOOL], messages=messages) as stream:
for event in stream:
t = time.monotonic() - t0
if event.type == "message_start" and message_start is None:
message_start = t
if event.type == "content_block_delta" and event.delta.type == "text_delta":
deltas += 1
first = first or t
last = t
request_id = stream.response.headers.get("request-id")
print(f"{model:18} {name:44} message_start {message_start:4.1f}s "
f"text {first:4.1f}s to {last:4.1f}s ({deltas} deltas) {request_id}")
for name, messages in CASES.items():
run("claude-sonnet-5-5", name, messages)
run("claude-sonnet-5", "A: history ends in tool_result", CASES["A: history ends in tool_result"])
Environment
anthropic1.5.0, Python 3.13.9, macOS 15.6claude-sonnet-5-5, default settings (also reproduces withthinking: {"type": "between_tools"})client.messages.stream()
- Ngôn ngữ chính
- Python
- Star
- 4.1k
- Fork
- 915
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của anthropics/anthropic-sdk-python
-
beta_tool validation errors reach the model as "Invalid arguments for function X" with no detailCó thể đã có người làm @mangeshraut712 đã nhận 32 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
anthropics/anthropic-sdk-python#2033 · 3 bình luận ·
-
`AnthropicBedrock` 2.x sends `anthropic_version: 2026-10-21`, which Bedrock rejects for Claude Sonnet 4.5, Opus 4.5 and Opus 4.6Có thể đã có người làm @charan-rathore đã nhận 36 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
anthropics/anthropic-sdk-python#2031 · 1 bình luận ·
-
Three symlink tests in test_agent_toolset.py are missing the needs_symlinks markerCó thể đã có người làm @okxint đã nhận 82 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
anthropics/anthropic-sdk-python#1915 · 3 bình luận ·
-
Messages.parse (and AsyncMessages.parse) don't take cache_control?Có thể đã có người làm @AlphaFDE đã nhận 86 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
anthropics/anthropic-sdk-python#1907 · 2 bình luận ·
-
Windows: os.fchmod in credential write-back bricks the OAuth refresh tokenCó thể đã có người làm @OllieinCanada đã nhận 99 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
anthropics/anthropic-sdk-python#1868 · 1 bình luận ·
Tất cả issue của anthropics/anthropic-sdk-python
Issue tương tự
-
bug harness
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mruangutai/harness#2687 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
modal-labs/modal-client#4158 ·
-
good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
The-Swarm-Corporation/swarms-rs#168 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] SMTP listener now binds to EMAIL_PORT instead of 2525 since the gunicorn switch 5.0.3-ls373Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
linuxserver/docker-healthchecks#137 · 1 bình luận ·