Investigate web search support for AWS Bedrock Claude models
## Context
We'd like to enable web search (`webSearch: true` + `webSearchPrice`) on all AWS Bedrock Sonnet / Opus / Haiku model mappings in `packages/models/src/models/anthropic.ts`, matching the native Anthropic provider mappings.
## Problem
This codebase talks to Bedrock via the Converse API (`packages/actions/src/prepare-request-body.ts`, `case "aws-bedrock"` around line 1400). The Converse API currently does **not** support Anthropic's `web_search_20250305` tool — the API validates tool types against `bash_20250124`, `custom`, and `text_editor_20250124` only. Passing `web_search_20250305` via `toolConfig.tools` or `additionalModelRequestFields` returns a validation error.
References:
- https://repost.aws/questions/QUSd3wAByQTtyzUPzgqss3TQ/web-search-for-anthropic-models-in-bedrock
- https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-anthropic-claude-messages-tool-use.html
## What needs figuring out
Confirm whether any of the following is viable today (or on a known roadmap):
1. Converse API now (or soon) accepts `web_search_20250305` via `additionalModelRequestFields` with a specific `anthropic_beta` header.
2. Switch Bedrock Anthropic calls to `InvokeModel` + raw Anthropic Messages format, where web_search is supported. Significant refactor of Bedrock request/response/streaming paths (`prepare-request-body.ts`, `parse-provider-response.ts`, `transform-streaming-to-openai.ts`, `chat.ts`).
3. Route via Bedrock Agents for web search — separate integration.
If confirmed supported, implementation work includes:
- Flip `webSearch: true` + `webSearchPrice: 0.01` on aws-bedrock provider mappings for Sonnet / Opus / Haiku models in `packages/models/src/models/anthropic.ts`.
- Add request-body handling for the web_search tool in the `aws-bedrock` branch of `prepare-request-body.ts`.
- Parse `web_search_tool_result` blocks + citations in the `aws-bedrock` branch of `parse-provider-response.ts`.
- Add streaming event handling in `transform-streaming-to-openai.ts` and web search counting for cost calculation in `chat.ts`.
## Ask
@rcogal could you look into whether option 1 or 2 is feasible today and share findings? Happy to pair on the implementation once we know which path to take.
4 条评论