登録して招待リンクを共有すると、動画再生報酬と紹介報酬を獲得できます。

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture 投稿は個人の意見です。
参加 May 2026
286 フォロー中    468 ファン
# Useful but Little-Known Features of Claude Agent SDK 🌍 Staring at a blank screen while the agent works? Real-time streaming fixes that! Enable `include_partial_messages` to receive text and tool call chunks as they're generated. 📌 Title: Real-Time Partial Messages 🔗 URL: 🧩 Overview Setting `include_partial_messages` (Python) / `includePartialMessages` (TypeScript) to `true` causes the SDK to emit `StreamEvent` messages alongside regular `AssistantMessage` objects. `StreamEvent` contains raw Claude API streaming events — `text_delta` for text chunks and `input_json_delta` for tool input fragments. This enables responsive UIs with typing-style text display and tool execution status indicators. 🛠 How to Use ```python # Python - Display text chunks in real time from claude_agent_sdk import query, ClaudeAgentOptions from claude_agent_sdk.types import StreamEvent options = ClaudeAgentOptions(include_partial_messages=True) async for message in query(prompt="Explain how databases work", options=options): if isinstance(message, StreamEvent): event = message.event if event.get("type") == "content_block_delta": delta = event.get("delta", {}) if delta.get("type") == "text_delta": print(delta.get("text", ""), end="", flush=True) ``` ```typescript // TypeScript - Stream tool calls with status indicators import { query } from "@anthropic-ai/claude-agent-sdk"; let currentTool: string | null = null; for await (const message of query({ prompt: "Read the README.md file", options: { includePartialMessages: true } })) { if (message.type === "stream_event") { const event = message.event; if (event.type === "content_block_start" && event.content_block.type === "tool_use") { currentTool = event.content_block.name; process.stdout.write(`\n[Using ${currentTool}...]`); } else if (event.type === "content_block_delta" && === "text_delta") { process.stdout.write( } else if (event.type === "content_block_stop" && currentTool) { console.log(" done"); currentTool = null; } } } ``` 🏗 Integration into Production Systems - Append `text_delta` chunks to message bubbles in chat UIs for typing-style rendering - Detect tool names from `content_block_start` (type: `tool_use`) events and show "running..." spinners - Track message boundaries with `message_start`/`message_stop` events - Text deltas must be accumulated manually — prepare an accumulator buffer 💡 Use Cases 💬 Implement ChatGPT-style real-time typing display in custom UIs 🔧 Show the currently active tool name and progress in a status bar 📝 Start displaying long analysis results before the full response is complete ⚠️ Caveats - `StreamEvent` events are raw Claude API events, not accumulated text — you must concatenate text deltas yourself - Structured output (`structured_output`) is not sent as streaming deltas; it only appears in the final `ResultMessage` - UI state management is needed — e.g., pause text streaming while a tool is executing (track an `in_tool` flag) ✨ No more "Processing, please wait..." screens. Partial messages bring users closer to the agent's work in real time! #ClaudeAgentSDK# #AIAgent#
もっと見る