fix(provider): preserve Bedrock tool config for history
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
Xubin Ren
co-authored by
Cursor
parent
ef268f47d2
commit
07f9ab580a
@@ -106,6 +106,7 @@ def test_generic_bedrock_model_keeps_temperature_and_skips_anthropic_thinking()
|
||||
assert kwargs["modelId"] == "amazon.nova-lite-v1:0"
|
||||
assert kwargs["inferenceConfig"] == {"maxTokens": 1024, "temperature": 0.3}
|
||||
assert "additionalModelRequestFields" not in kwargs
|
||||
assert "toolConfig" not in kwargs
|
||||
|
||||
|
||||
def test_build_kwargs_converts_messages_tools_and_tool_results() -> None:
|
||||
@@ -160,6 +161,39 @@ def test_build_kwargs_converts_messages_tools_and_tool_results() -> None:
|
||||
assert kwargs["toolConfig"]["toolChoice"] == {"any": {}}
|
||||
|
||||
|
||||
def test_build_kwargs_keeps_tool_config_for_historical_tool_blocks_without_tools() -> None:
|
||||
provider = BedrockProvider(region="us-east-1", client=FakeClient())
|
||||
messages = [
|
||||
{"role": "user", "content": "read x"},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": "",
|
||||
"tool_calls": [{
|
||||
"id": "toolu_1",
|
||||
"type": "function",
|
||||
"function": {"name": "read_file", "arguments": '{"path": "x"}'},
|
||||
}],
|
||||
},
|
||||
{"role": "tool", "tool_call_id": "toolu_1", "name": "read_file", "content": "ok"},
|
||||
{"role": "user", "content": "continue"},
|
||||
]
|
||||
|
||||
kwargs = provider._build_kwargs(
|
||||
messages=messages,
|
||||
tools=[],
|
||||
model="bedrock/anthropic.claude-opus-4-7",
|
||||
max_tokens=1024,
|
||||
temperature=0.7,
|
||||
reasoning_effort=None,
|
||||
tool_choice=None,
|
||||
)
|
||||
|
||||
assert any("toolUse" in block for msg in kwargs["messages"] for block in msg["content"])
|
||||
assert any("toolResult" in block for msg in kwargs["messages"] for block in msg["content"])
|
||||
assert kwargs["toolConfig"]["tools"][0]["toolSpec"]["name"] == "nanobot_noop"
|
||||
assert "toolChoice" not in kwargs["toolConfig"]
|
||||
|
||||
|
||||
def test_parse_response_maps_text_tools_reasoning_usage_and_stop_reason() -> None:
|
||||
response = {
|
||||
"output": {
|
||||
|
||||
Reference in New Issue
Block a user