Skip to content

fix(bedrock): JS - record every toolResult block of a Converse message - #4476

Open
chrikrah wants to merge 1 commit into
Arize-ai:mainfrom
chrikrah:chrikrah/bedrock-js-converse-tool-results
Open

chrikrah wants to merge 1 commit into
Arize-ai:mainfrom
chrikrah:chrikrah/bedrock-js-converse-tool-results

Conversation

@chrikrah

Copy link
Copy Markdown
Contributor

Description

Refs #3786, which #3787 fixed in the Python package. In JS, getAttributesFromMessage (attribute-helpers.ts:225) writes each toolResult block's toolUseId to the message-level tool_call_id and records none of the tool output. Two parallel tool results leave one user message with the last id and no content:

# main 2d10c590, toolResult tool_1 "Paris: 18C" and tool_2 "Rome:" + {"temp_c":24} in one message
llm.input_messages.2.message.role         user
llm.input_messages.2.message.tool_call_id tool_2
# this branch
llm.input_messages.2.message.role         tool
llm.input_messages.2.message.tool_call_id tool_1
llm.input_messages.2.message.content      Paris: 18C
llm.input_messages.3.message.role         tool
llm.input_messages.3.message.tool_call_id tool_2
llm.input_messages.3.message.content      Rome:\n\n{"temp_c":24}

Each toolResult becomes its own tool message, in order, as in _converse_attributes.py and the spec's Tool Results, one id per message.tool_call_id. Other content stays in the original message. Image and document blocks inside a result are skipped, as in Python. Changeset included.

The cost: a message with several tool results takes several indices, so later messages shift and a saved query on llm.input_messages.N can hit a different turn.

Verification

$ pnpm test   # js/packages/openinference-instrumentation-bedrock, Node 22.23.3, pnpm 10.29.3
# main 2d10c590, new test kept
FAIL  converse-tool-results.test.ts > records each toolResult block as its own tool message
AssertionError: expected 'user' to be 'tool'
FAIL  converse-tool-results.test.ts > keeps the other content of a message that also carries a toolResult
AssertionError: expected undefined to be 'And tomorrow?'
Tests  2 failed | 151 passed | 1 skipped (154)
# this branch
Tests  153 passed | 1 skipped (154)
Type Errors  no errors
$ npx oxfmt --check .changeset packages/openinference-instrumentation-bedrock   # oxfmt 0.33.0, exit 0
$ npx oxlint packages/openinference-instrumentation-bedrock                     # oxlint 1.74.0, exit 0
$ pnpm run type:check                                                           # exit 0
# not run: a live Bedrock call

Checklist:

  • Follows OpenInference configuration to hide sensitive info
    • The tool messages are input messages, so hideInputMessages and hideInputText cover them.
  • Spans properly inherit from context attributes
    • Not applicable: span creation is unchanged.
  • Properly respects suppress tracing context
    • Not applicable: the instrumentation entry points are unchanged.

InvokeModel keeps each Anthropic tool_result text, but its tool_call_id is last-wins too (invoke-model-request-attributes.ts:146-152). I'd fix that in a follow-up so this stays a port of #3787. @mikeldking, does that split work for you?

getAttributesFromMessage wrote each toolResult block's toolUseId to the
message-level tool_call_id and recorded none of its output, so a message
with parallel tool results kept only the last id and no tool output.
Record each toolResult as its own tool message with its id and its text
and JSON output, as the Python instrumentor does since Arize-ai#3787.

Signed-off-by: Christopher Krah <48338417+chrikrah@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant