Issue: Bedrock provider throws on unknown assistant/user content types (other providers skip)
Summary
amazon-bedrock.js in convertMessages() throws Error("Unknown assistant content type") / Error("Unknown user content type") when encountering any content block type outside the recognized set (text/image for user, text/toolCall/thinking for assistant).
This causes entire agent runs to crash when context history contains blocks from newer API features (e.g., redacted thinking replay, structured output blocks, provider-specific extensions) that the Bedrock provider doesn't yet handle.
Other providers in the same codebase handle this gracefully:
anthropic.js: uses if/else if and simply doesn't push unrecognized blocks (silently skips)
openai-*.js / google.js: similar forgiving behavior
Reproduction
- Use Bedrock provider with Claude Opus/Sonnet via
amazon-bedrock API
- Have conversation history that includes a non-standard content block (e.g., a
redacted thinking block, an image block in assistant role, or any future block type)
- On the next turn,
convertMessages() hits the default: branch and throws
Impact
- Agent runs crash with no recovery (the error is unhandled)
- Users on Bedrock have worse reliability than users on the direct Anthropic API for the same models
- As new block types are added upstream, Bedrock users will hit this more often
Suggested fix
Minimum: Replace throw with skip behavior, matching the anthropic provider:
// User branch (inside .map callback):
default:
return null; // skip unknown
// ... then .filter(Boolean) on the map result
// + guard: if (content.length === 0) continue;
// Assistant branch (inside for...of loop):
default:
continue; // skip unknown
Better: Add a console.warn or debug log when skipping, so users know context was dropped:
default:
console.warn(`[bedrock] skipping unknown ${m.role} content type: ${c.type}`);
return null; // or continue
Best: Handle all known pi-ai content types (text, image, thinking, toolCall, redacted, etc.) explicitly, and only skip truly unknown ones.
Additional context
- Affected versions: at least 0.66 through 0.73 (latest at time of writing)
- File:
packages/ai/src/providers/amazon-bedrock.ts → convertMessages() function
- The anthropic provider in the same repo already demonstrates the correct pattern
- We're currently running a local patch on our deployment; happy to submit a PR if maintainers agree with the approach
Environment
- pi-ai 0.71.1 (bundled with OpenClaw 2026.5.2)
- amazon-bedrock provider, models: claude-opus-4-7, claude-sonnet-4-6
- Node.js v24.13.0
Issue: Bedrock provider throws on unknown assistant/user content types (other providers skip)
Summary
amazon-bedrock.jsinconvertMessages()throwsError("Unknown assistant content type")/Error("Unknown user content type")when encountering any content block type outside the recognized set (text/image for user, text/toolCall/thinking for assistant).This causes entire agent runs to crash when context history contains blocks from newer API features (e.g., redacted thinking replay, structured output blocks, provider-specific extensions) that the Bedrock provider doesn't yet handle.
Other providers in the same codebase handle this gracefully:
anthropic.js: usesif/else ifand simply doesn't push unrecognized blocks (silently skips)openai-*.js/google.js: similar forgiving behaviorReproduction
amazon-bedrockAPIredactedthinking block, an image block in assistant role, or any future block type)convertMessages()hits thedefault:branch and throwsImpact
Suggested fix
Minimum: Replace
throwwith skip behavior, matching the anthropic provider:Better: Add a
console.warnor debug log when skipping, so users know context was dropped:default: console.warn(`[bedrock] skipping unknown ${m.role} content type: ${c.type}`); return null; // or continueBest: Handle all known pi-ai content types (text, image, thinking, toolCall, redacted, etc.) explicitly, and only skip truly unknown ones.
Additional context
packages/ai/src/providers/amazon-bedrock.ts→convertMessages()functionEnvironment