fix(providers): tighten tool calls and compatibility fallbacks
Require structured tool calls and explicit unsupported-feature errors. Preserve supported SDK compaction requests and add compatibility coverage. Co-authored-by: Xubin Ren <52506698+Re-bin@users.noreply.github.com>
This commit is contained in:
1 parent
3e40684112
commit
8b37976d36
16 files changed
+406
-168
No files matched your search
@@ -52,29 +52,6 @@ def test_custom_provider_parse_accepts_dict_response() -> None:
|
||||
assert result.usage.total_tokens == 3
|
||||
|
||||
|
||||
def test_custom_provider_parse_normalizes_text_tool_call() -> None:
|
||||
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
|
||||
provider = OpenAICompatProvider()
|
||||
|
||||
result = provider._parse({
|
||||
"choices": [{
|
||||
"message": {
|
||||
"content": (
|
||||
"I'll inspect it.\n"
|
||||
'<tool_call>{"name":"read_file","arguments":{"path":"README.md"}}'
|
||||
"</tool_call>"
|
||||
),
|
||||
},
|
||||
"finish_reason": "stop",
|
||||
}],
|
||||
})
|
||||
|
||||
assert result.content == "I'll inspect it."
|
||||
assert len(result.tool_calls) == 1
|
||||
assert result.tool_calls[0].name == "read_file"
|
||||
assert result.tool_calls[0].arguments == {"path": "README.md"}
|
||||
|
||||
|
||||
def test_custom_provider_parse_keeps_structured_tool_call_over_text_markup() -> None:
|
||||
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
|
||||
provider = OpenAICompatProvider()
|
||||
@@ -104,22 +81,6 @@ def test_custom_provider_parse_chunks_accepts_plain_text_chunks() -> None:
|
||||
assert result.content == "hello world"
|
||||
|
||||
|
||||
def test_custom_provider_parse_chunks_normalizes_split_text_tool_call() -> None:
|
||||
chunks = [
|
||||
{"choices": [{"delta": {"content": "<tool_call>"}}]},
|
||||
{"choices": [{"delta": {"content": '{"name":"list_dir",'}}]},
|
||||
{"choices": [{"delta": {"content": '"arguments":{"path":"."}}</tool_call>'}}]},
|
||||
{"choices": [{"finish_reason": "stop", "delta": {}}]},
|
||||
]
|
||||
|
||||
result = OpenAICompatProvider._parse_chunks(chunks)
|
||||
|
||||
assert result.content is None
|
||||
assert len(result.tool_calls) == 1
|
||||
assert result.tool_calls[0].name == "list_dir"
|
||||
assert result.tool_calls[0].arguments == {"path": "."}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("as_sdk", [False, True], ids=["dict", "sdk"])
|
||||
def test_custom_provider_parse_chunks_deduplicates_parallel_tool_call_ids(as_sdk: bool) -> None:
|
||||
chunks = [{
|
||||
|
||||
Reference in new issue
Block a user