anthropics / anthropics/claude-agent-sdk-python
Streaming is required for operations that may take longer than 10 minutes
- 主要语言
- Python
- 星标
- 8.1k
- 派生
- 1.3k
- 平均合并
- 2 天 31 分钟
- 30 天内合并 PR
- 1
描述
```python
prompt = _build_prompt(incoming_text, files)
try:
async for message in query(prompt=prompt, options=options):
self._remember_session(thread_id, getattr(message, "session_id", None))
_handle_message_for_progress(
message=message,
progress_callback=progress_callback,
seen_tool_use_ids=seen_tool_use_ids,
seen_thinking_message_ids=seen_thinking_message_ids,
)
if isinstance(message, AssistantMessage):
_accumulate_assistant_usage(
message=message,
seen_message_ids=seen_assistant_message_ids,
totals=assistant_usage_totals,
)
text = _assistant_text(message)
if text:
assistant_text = text
continue
if isinstance(message, ResultMessage):
result_message = message
except Exception as exc:
...
```
```python
def _build_prompt(
incoming_text: str,
files: list[IncomingFileEvent],
) -> AsyncIterator[dict[str, Any]]:
image_files = [f for f in files if f.download_url and _image_mime(f.file_name)]
content: list[dict[str, Any]] | str
if not image_files:
content = incoming_text
else:
parts: list[dict[str, Any]] = []
for f in image_files:
mime = _image_mime(f.file_name)
data = _download_image_bytes(f.download_url)
if data is None:
raise RuntimeError(f"Failed to download image: {f.file_name}")
parts.append({
"type": "image",
"source": {
"type": "base64",
"media_type": mime,
"data": base64.standard_b64encode(data).decode("ascii"),
},
})
parts.append({"type": "text", "text": incoming_text})
content = parts
async def _stream() -> AsyncIterator[dict[str, Any]]:
yield {
"type": "user",
"message": {"role": "user", "content": content},
"parent_tool_use_id": None,
"session_id": None,
}
return _stream()
```
just input short message but got:
Streaming is required for operations that may take longer than 10 minutes.
贡献指南
这个仓库没有索引到贡献指南
调研方向
Start at the shown query(...) async iteration and _build_prompt entry points, then trace why the short-message example still raises the ten-minute streaming error. Reproduce the reported case and inspect the existing tests around long-running operations; done means the request no longer raises this error when handled through the intended streaming path.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 50/100