Skip to content

Bug: converse-stream contentBlockDelta.delta contains invalid type field, causing ResponseParserError #165

@KMiya84377

Description

@KMiya84377

Environment

  • aimock: 1.19.2
  • strands-agents: 1.38.0
  • Python: 3.13
  • boto3 / botocore: 1.43.6

Steps to reproduce

1. Create a fixture file

// fixtures/agent.json
{
  "fixtures": [
    {
      "match": { "userMessage": "hello" },
      "response": { "content": "Hello! How can I help you today?" }
    }
  ]
}

2. Start aimock

npx -p @copilotkit/aimock@1.19.2 llmock -f ./fixtures --port 4010

3. Run the agent

# main.py
from strands import Agent
from strands.models import BedrockModel

model = BedrockModel(endpoint_url="http://localhost:4010")
agent = Agent(model=model)
agent("hello")
uv run main.py

Actual output:

botocore.parsers.ResponseParserError: Invalid service response:
ContentBlockDelta must have one and only one member set.

Expected output:

The agent runs without error and returns a response.

Root cause

In src/bedrock-converse.ts, the contentBlockDelta event's delta field includes a type field that belongs to the Claude Messages API format, not the Converse API format:

// aimock が送っている delta(誤り)
{ "type": "text_delta", "text": "Hello" }

Strands Agents uses boto3 internally to call Bedrock. The problem unfolds as follows:

  1. aimock sends a contentBlockDelta event with delta: { "type": "text_delta", "text": "Hello" }
  2. botocore parses delta as a tagged union (ContentBlockDelta.delta) — exactly one member must be set
  3. botocore's _has_unknown_tagged_union_member (botocore/parsers.py) finds two keys (type and text):
    if len(cleaned_value) != 1:
        raise ResponseParserError(
            "Invalid service response: %s must have one and only one member set."
            % shape.name
        )
  4. len(cleaned_value) == 2ResponseParserError

The type field ("text_delta", "thinking_delta") is from the Claude Messages API format and does not exist in the Converse API's ContentBlockDelta.delta union.

Per the AWS API reference for ContentBlockDelta:

Important: This data type is a UNION, so only one of the following members can be specified when used or returned.

  • text (String)
  • toolUse (ToolUseBlockDelta)
  • reasoningContent (ReasoningContentBlockDelta)
  • image (ImageBlockDelta)
  • citation (CitationsDelta)
  • toolResult (ToolResultBlockDelta)

type is not a member of this union.

Suggested fix

In src/bedrock-converse.ts, buildBedrockStreamTextEvents, remove the type field from delta:

// before (incorrect)
delta: { type: "text_delta", text: content.slice(i, i + chunkSize) }

// after (correct)
delta: { text: content.slice(i, i + chunkSize) }

buildBedrockStreamContentWithToolCallsEvents delegates to buildBedrockStreamTextEvents, so fixing the latter fixes both. buildBedrockStreamToolCallEvents is unaffected (its delta already uses { toolUse: { input: ... } } which is correct).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions