Skip to content

fix(bedrock): return native tool calls from streaming when no available_functions - #7439

Open
alanhuangyoo wants to merge 1 commit into
crewAIInc:mainfrom
alanhuangyoo:fix/bedrock-streaming-returns-tool-calls
Open

alanhuangyoo wants to merge 1 commit into
crewAIInc:mainfrom
alanhuangyoo:fix/bedrock-streaming-returns-tool-calls

Conversation

@alanhuangyoo

Copy link
Copy Markdown

Related issue

Fixes #7438

Summary

With stream=True, Bedrock drops native tool calls: the tool never runs and the task answer is the "I apologize, but I couldn't generate a response" fallback.

The agent executor calls the LLM with available_functions=None and executes the returned tool calls itself. _handle_converse returns the tool uses in that case (completion.py:741-752). Both streaming handlers only used a tool call when available_functions was set and otherwise discarded it, so the stream ended with no text and returned the fallback.

The streaming handlers now collect the parsed tool uses when available_functions is empty (skipping the structured-output tool, as the non-streaming path does) and return them after the stream, with the same TOOL_CALL completed event. Streams that call tools with available_functions set, or return text, are unchanged.

Verification

  • Tests added or updated for the changed behavior

  • Relevant tests and quality checks pass locally

  • Two new tests in tests/llms/bedrock/test_bedrock_streaming_tool_args.py (sync and async) call the streaming handler without available_functions and expect the tool use back. Both fail on main. I moved the async stream helper to module level so both async tests share it.

  • tests/llms/bedrock: 39 passed, 8 skipped.

  • A crew run with a mocked converse_stream now runs the tool with stream=True (tool ran with=['Paris']), the same as stream=False.

  • ruff 0.15.1 with the repo config passes. mypy reports the same errors for completion.py before and after (local stubs).

Additional context

The OpenAI Responses API streaming handler has the same gap (_handle_streaming_responses only uses collected tool calls when available_functions is set). I left it out to keep this PR to one provider.

This PR was written with AI assistance (Claude Code). I can't add the llm-generated label as an outside contributor; could a maintainer add it?

🤖 Generated with Claude Code

…le_functions

The agent executor calls the LLM with available_functions=None and runs the
returned tool calls itself. The non-streaming Converse path returns them, but
both streaming handlers dropped the call and returned the empty-content
fallback, so with stream=True the tool never ran. Collect the tool uses and
return them after the stream, as the non-streaming path does.

Fixes crewAIInc#7438

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: ccf69d4d-0f41-4542-a59d-f6f13fab02e8

📥 Commits

Reviewing files that changed from the base of the PR and between 894898f and f46ae09.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/llms/providers/bedrock/completion.py
  • lib/crewai/tests/llms/bedrock/test_bedrock_streaming_tool_args.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Bedrock synchronous and asynchronous streaming handlers now preserve native tool calls when available_functions is absent. New regression tests verify that both handlers return the streamed tool calls.

Changes

Bedrock streaming tool calls

Layer / File(s) Summary
Preserve streamed tool calls
lib/crewai/src/crewai/llms/providers/bedrock/completion.py
The synchronous and asynchronous handlers collect completed tool uses, emit TOOL_CALL completion events, and return the collected calls when available_functions is absent.
Cover missing available_functions
lib/crewai/tests/llms/bedrock/test_bedrock_streaming_tool_args.py
The tests share an async stream helper and verify synchronous and asynchronous tool-call returns without available_functions.

Suggested reviewers: kimnamu

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to f46ae

Streaming Bedrock tool calls without configured functions are now returned to the executor rather than replaced by a fallback response. The change includes sync and async regression coverage and has no remaining actionable merge risk.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: returning native Bedrock tool calls during streaming when no available functions are provided.
Description check ✅ Passed The description includes the related issue, explains the root cause and solution, documents verification results, and provides additional context about scope and follow-up work.
Linked Issues check ✅ Passed The change satisfies issue #7438. Both sync and async streaming handlers collect native tool uses when available_functions is not provided. They exclude STRUCTURED_OUTPUT_TOOL_NAME, emit the `LLMC…
Out of Scope Changes check ✅ Passed The changes stay within issue #7438. Production changes are limited to preserving native Bedrock streaming tool calls in the sync and async handlers. Test changes add coverage for both handlers and mo…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Bedrock streaming drops native tool calls, so the tool never runs

1 participant