Skip to content

Add tool call IDs and a first-class tool-result event to the streaming Chunk type #122

@smorimoto

Description

@smorimoto

Problem

The Chunk union's tool-call variant currently carries only toolName and input:

{
  type: "tool-call";
  toolName: string;
  input: Record<string, unknown>;
}

There is no toolCallId (or equivalent identifier) that links a tool invocation to its result, and tool_result is not a first-class event — it arrives as { type: "unknown"; event: "tool_result"; data: unknown }.

This causes two concrete issues:

1. Parallel tool calls produce incorrect result matching

Claude Code (and other agents built on the Anthropic SDK) routinely execute multiple tool calls in a single turn. Because there is no identifier tying a result back to its originating call, consumers are forced to use a fragile heuristic — typically "assign the result to the first tool call that has no result yet." When two or more calls are in flight simultaneously, results can be attributed to the wrong call.

2. Tool results cannot be given a structured type

Without a discriminant linking a result to a known tool name, the result payload cannot be narrowed to the tool-specific output schema (e.g. FileReadOutput, BashOutput). Consumers must treat every result as unknown or string, losing the type safety that the Anthropic Agent SDK otherwise provides.

Proposed changes

a. Add toolCallId to the tool-call chunk

{
  type: "tool-call";
  toolCallId: string;   // new
  toolName: string;
  input: Record<string, unknown>;
}

b. Add a first-class tool-result chunk

{
  type: "tool-result";
  toolCallId: string;
  output: unknown;       // or a structured union
}

This removes the need for consumers to intercept type: "unknown" events and parse tool_result manually.

Context

  • @upstash/box version: 0.1.31
  • The Anthropic Agent SDK's own streaming format already includes a tool_use_id that uniquely identifies each tool invocation. Surfacing this through the Box SDK would bring parity with the upstream protocol.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions