Skip to content

Fix #6149: Parse accumulated tool input in Bedrock streaming - #6151

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781357959-fix-bedrock-streaming-tool-args
Open

Fix #6149: Parse accumulated tool input in Bedrock streaming#6151
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781357959-fix-bedrock-streaming-tool-args

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Fixes #6149 — Bedrock streaming tool calls receive empty arguments ({}).

In both _handle_streaming_converse (sync) and _ahandle_streaming_converse (async), the tool input JSON deltas were accumulated into accumulated_tool_input during contentBlockDelta events, but never parsed and stored back into current_tool_use["input"] at contentBlockStop. This caused current_tool_use.get("input", {}) to return {}, so the tool executor received no arguments.

The fix parses accumulated_tool_input via json.loads() and assigns it to current_tool_use["input"] at contentBlockStop, before function_args is read:

# At contentBlockStop, before reading function_args:
if accumulated_tool_input:
    try:
        current_tool_use["input"] = json.loads(accumulated_tool_input)
    except json.JSONDecodeError:
        current_tool_use["input"] = {}

This also ensures the toolUse block appended to messages for the follow-up converse call carries the correct input.

Tests added: 4 new tests covering sync (single-chunk, multi-chunk, split-across-many-chunks) and async streaming tool-call argument parsing. All 39 bedrock tests pass.

Link to Devin session: https://app.devin.ai/sessions/e9f126a256fb489491180316ca156300

In _handle_streaming_converse and _ahandle_streaming_converse, the
accumulated_tool_input string was never folded back into
current_tool_use['input'] at contentBlockStop, causing tool calls to
receive empty arguments ({}).

Parse the accumulated JSON string and assign it to
current_tool_use['input'] before reading function_args.

Co-Authored-By: João <joao@crewai.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

mock_stream.return_value = {"stream": iter(stream_events)}
mock_converse.return_value = final_response

result = llm.call(
mock_stream.return_value = {"stream": iter(stream_events)}
mock_converse.return_value = final_response

result = llm.call(
with patch.object(llm, "_ensure_async_client", side_effect=fake_ensure), \
patch.object(llm, "_ahandle_converse", side_effect=fake_ahandle_converse):
messages = [{"role": "user", "content": "Weather in London?"}]
result = await llm.acall(
@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 45 days with no activity.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bedrock streaming tool calls receive empty arguments ({}) — streaming twin of #4972

0 participants