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

オープン 初心者向け
#10,766 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@effect-bot がすでに取り組んでいます。

2026年11月19日 から。

  • #10767 @effect-bot による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
79/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

まず AmazonBedrockLanguageModel.ts と、issue で特定された toolResultContent 関数を読みます。Bedrock のツール結果を対象とする既存のテストを確認し、@effect/ai-anthropic が文字列以外の結果をどのように処理するかを比較します。報告された検証エラーを発生させずに、配列およびプリミティブ型のツール結果を後続の Bedrock リクエストで送信できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
16.7k
フォーク
808
平均マージ
20時間 31分
マージ済み PR(30日)
733

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Effect-TS/effect のほかの issue

Effect-TS/effect の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。