Streaming a reply with both a text block and a tool_use block

CCDV-F Applications & Integration Medium Question 96 of 105

A streamed Claude response contains a text block and a tool_use block. Text fragments and tool-argument fragments arrive as content_block_delta events.

How should the client assemble them?

Show answer and explanation

ABuffer each delta under its block index and parse at content_block_stop

Every content_block_delta carries an index tying it to one block, and the arguments are complete when content_block_stop arrives for that index. The tool_use id appears once, on content_block_start, and never on a delta, so there is nothing on the delta to key a buffer on. A tolerant parse of a fragment such as {"location": returns a half-filled input that looks like a success. content_block_start announces the tool with an empty input, so dispatching there calls it with no arguments.

Source: platform.claude.com/docs/en/build-with-claude/streaming

Anonymous, no account needed. Your tally stays in this browser.

Next question Start 5 timed questions Browse all 105 original CCDV-F practice questions