Skip to content

Conversation

@dpernes
Copy link
Contributor

@dpernes dpernes commented May 19, 2025

Description

In the astream_chat and stream_chat functions in llama_index/llms/bedrock_converse/base.py, a ChatResponse was yielded before the LLM finished streaming, resulting in a missing input field in the generated tool call.

Now, when the LLM starts a tool call, we check if it is complete before yielding the ChatResponse.

Fixes # 18775.

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran uv run make format; uv run make lint to appease the lint gods

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 19, 2025

# If no region prefix, return the original model name
if not any(model_name.startswith(prefix) for prefix in REGION_PREFIXES):
if not any(prefix in model_name for prefix in REGION_PREFIXES):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sneaking in this fix, when prefixing with arn:..., the startswith assumption breaks down

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels May 19, 2025
@logan-markewich logan-markewich merged commit 0524109 into run-llama:main May 19, 2025
9 of 10 checks passed
# handle empty inputs
argument_dict = {}
if tool_call["input"] and isinstance(tool_call["input"], str):
if tool_call.get("input", False) and isinstance(tool_call["input"], str):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails when the tool has no inputs, because tool_call.get("input", False) returns an empty string (""), which evaluates to False. As a result, we fall into the else branch and skip the tool call.

To fix this, we should use if "input" in tool_call instead of if tool_call.get("input", False). I'll open a new PR with this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, the change you propose sounds good, but isn't it pretty much similar to what we already do?
If "input" is not in tool_call, we should get False from both the conditional statements (the one you propose and the one we are already using)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you are proposing a higher level conditional change, like:

if "input" in tool_call:
    if isinstance(tool_call["input], str):
      # do something 
   elif isinstance(tool_call["input"], dict):
     # do something else
else:
     continue 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for the quick reply.

isn't it pretty much similar to what we already do?

Not really. The issue happens when "input" exists in tool_call but tool_call["input"] == "". In this case, tool_call.get("input", False) will return "", which evaluates to False.

E.g., try running:

tool_call = {"input": ""}

if tool_call.get("input", False):
  print("This will NOT be printed")

if "input" in tool_call:
  print("This will be printed")

Copy link
Member

@AstraBert AstraBert May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, sorry for the oversight!
Yeah, then please go ahead with the PR or I could also do that :),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already did: PR #18786 :)

dpernes added a commit to dpernes/llama_index that referenced this pull request May 20, 2025
AstraBert pushed a commit that referenced this pull request May 20, 2025
)

* Fix yielding incomplete tool calls

Fix for issue [18775](#18775 (comment))

* small fix for getting model name when arn is prefixed

* apply Clelia's fix

* vbump

* revert original PR changes

* Bug fix: Calling tool with empty arguments

See [this comment](#18781 (comment)).

* Bumped to v0.5.5

---------

Co-authored-by: Logan Markewich <[email protected]>
@colca colca mentioned this pull request Jun 9, 2025
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants