ai-amazon-bedrock: a tool result that isn't a JSON object fails the next request

Đang mở Phù hợp với người mới
#10,766 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@effect-bot đang làm issue này rồi.

Từ ngày 19/11/2026.

  • #10767 của @effect-bot — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
79/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Bắt đầu bằng cách đọc AmazonBedrockLanguageModel.ts và hàm toolResultContent được nêu trong issue. Kiểm tra xem đã có bài kiểm thử nào bao quát kết quả công cụ của Bedrock chưa, rồi so sánh cách @effect/ai-anthropic xử lý các kết quả không phải chuỗi. Hoàn tất khi có thể gửi kết quả công cụ dạng mảng và nguyên thủy trong một yêu cầu Bedrock tiếp theo mà không gặp lỗi xác thực đã báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

What happens

When a tool's result is an array (or a number, boolean or null), the next request to Bedrock fails:

AiError: AmazonBedrockClient.converseStream: Invalid request. ValidationException: The format of the value at messages.6.content.1.toolResult.content.0.json is invalid. Provide a json object for the field and try again.

The result stays in the conversation's history, so every later request in that conversation fails the same way.

Reproduction

import { Effect, Schema } from "effect"
import { LanguageModel, Tool, Toolkit } from "effect/ai"

const Search = Tool.make("search", {
  parameters: Schema.Struct({ query: Schema.String }),
  success: Schema.Array(Schema.String)
})

const Tools = Toolkit.make(Search)

const ToolsLive = Tools.toLayer({ search: () => Effect.succeed([]) })

// With AmazonBedrockLanguageModel (Claude via Converse): the model calls `search`,
// and the request that sends its result back fails with the ValidationException above.

Cause

toolResultContent in AmazonBedrockLanguageModel.ts sends every non-string result as json:

const toolResultContent = (result: unknown) => {
  if (typeof result === "string") return [{ text: result }]
  if (Predicate.isUndefined(result)) return [{ text: "" }]
  return [{ json: result }]
}

Converse only accepts a JSON object in ToolResultContentBlock.json. Tool allows any success schema, and @effect/ai-anthropic already handles this by stringifying non-string results.

Suggested fix

Send only objects as json and stringify everything else:

const toolResultContent = (result: unknown) => {
  if (Predicate.isString(result)) return [{ text: result }]
  if (Predicate.isUndefined(result)) return [{ text: "" }]
  if (Predicate.isObject(result)) return [{ json: result }]
  return [{ text: JSON.stringify(result) }]
}

Version: @effect/ai-amazon-bedrock 4.1.4.

Ngôn ngữ chính
TypeScript
Star
16.7k
Fork
808
Merge trung bình
20 giờ 31 phút
Pull request đã merge (30 ngày)
733

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Effect-TS/effect

Tất cả issue của Effect-TS/effect

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.