Skip to content

fix(core): ensure tool_choice maps to structured object for AWS Bedrock compliance#668

Open
toshalkumbhar8979-design wants to merge 2 commits into
usestrix:mainfrom
toshalkumbhar8979-design:fix/bedrock-validation-patch
Open

fix(core): ensure tool_choice maps to structured object for AWS Bedrock compliance#668
toshalkumbhar8979-design wants to merge 2 commits into
usestrix:mainfrom
toshalkumbhar8979-design:fix/bedrock-validation-patch

Conversation

@toshalkumbhar8979-design

Copy link
Copy Markdown

Description

Ensures that tool_choice is formatted as a structured object ({"type": "auto"}) rather than a raw string when communicating via LiteLLM/Bedrock. This fixes an API validation failure where AWS Bedrock rejects requests with a 400 Bad Request.

Error Log

litellm.exceptions.BadRequestError: BedrockException - {"message":"The model returned the following errors: tool_choice.type: Field required"}

@greptile-apps

greptile-apps Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR normalizes tool_choice before agent execution. The main changes are:

  • Adds a pre-run conversion in strix/core/execution.py.
  • Converts configured tool_choice values to a Bedrock-style object.
  • Applies the conversion inside _run_cycle before Runner.run_streamed.

Confidence Score: 4/5

The Bedrock request path still has cases that can send the raw string, and explicit tool selections can be changed to auto.

  • extra_body == {} skips top-level tool_choice normalization.
  • Any string tool choice is rewritten to automatic selection.
  • The change is localized to the pre-run request setup.

strix/core/execution.py

Important Files Changed

Filename Overview
strix/core/execution.py Adds tool_choice normalization before streamed agent runs.
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
strix/core/execution.py:354-358
**Top-Level Tool Choice Skips Normalization**

When `extra_body` is a dict without its own `tool_choice`, this `elif` skips the top-level `run_config.tool_choice` branch. A Bedrock run with `extra_body == {}` and `tool_choice == "auto"` can still reach `Runner.run_streamed` with the raw string and fail with the same `tool_choice.type` validation error.

```suggestion
            if hasattr(run_config, "extra_body") and isinstance(run_config.extra_body, dict):
                if "tool_choice" in run_config.extra_body:
                    run_config.extra_body["tool_choice"] = {"type": "auto"}
            if hasattr(run_config, "tool_choice") and (run_config.tool_choice == "auto" or isinstance(run_config.tool_choice, str)):
                run_config.tool_choice = {"type": "auto"}
```

### Issue 2 of 2
strix/core/execution.py:357-358
**Explicit Tool Choice Becomes Auto**

The `isinstance(run_config.tool_choice, str)` branch rewrites every string value to `{"type": "auto"}`. If a caller selects a specific tool by name, the request is changed to automatic selection before `Runner.run_streamed`, so the model can skip the required tool or call a different one.

```suggestion
            elif hasattr(run_config, "tool_choice") and run_config.tool_choice == "auto":
                run_config.tool_choice = {"type": "auto"}
```

Reviews (1): Last reviewed commit: "fix(core): ensure tool_choice maps to st..." | Re-trigger Greptile

Comment thread strix/core/execution.py
Comment thread strix/core/execution.py Outdated
Comment on lines +357 to +358
elif hasattr(run_config, "tool_choice") and (run_config.tool_choice == "auto" or isinstance(run_config.tool_choice, str)):
run_config.tool_choice = {"type": "auto"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Explicit Tool Choice Becomes Auto

The isinstance(run_config.tool_choice, str) branch rewrites every string value to {"type": "auto"}. If a caller selects a specific tool by name, the request is changed to automatic selection before Runner.run_streamed, so the model can skip the required tool or call a different one.

Suggested change
elif hasattr(run_config, "tool_choice") and (run_config.tool_choice == "auto" or isinstance(run_config.tool_choice, str)):
run_config.tool_choice = {"type": "auto"}
elif hasattr(run_config, "tool_choice") and run_config.tool_choice == "auto":
run_config.tool_choice = {"type": "auto"}
Prompt To Fix With AI
This is a comment left during a code review.
Path: strix/core/execution.py
Line: 357-358

Comment:
**Explicit Tool Choice Becomes Auto**

The `isinstance(run_config.tool_choice, str)` branch rewrites every string value to `{"type": "auto"}`. If a caller selects a specific tool by name, the request is changed to automatic selection before `Runner.run_streamed`, so the model can skip the required tool or call a different one.

```suggestion
            elif hasattr(run_config, "tool_choice") and run_config.tool_choice == "auto":
                run_config.tool_choice = {"type": "auto"}
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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.

1 participant