okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-141-fixb: Python, docs and bench fixes and portsef8071303

main
1.8 KiB46 linesraw
1"""serve/test_tool_name_space.py - a tool call written `<function= NAME>` (a space after the `=`) is the call NAME.
2
3Seen live (Qwen3.8-Flash-Next IQ2_XS, Zed's agent panel): the model wrote `<function= capture>` inside its thinking;
4the name was read as " capture", matched no declared tool, stayed reasoning text (#804), and the turn ended with no
5call, so the agent stopped.  After the thinking the same call came out named " capture", and its arguments were
6typed without the tool's schema.
7
8    python -m unittest serve.test_tool_name_space -v
9"""
10import sys
11import unittest
12from pathlib import Path
13
14sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
15
16from serve.frontend import OutputParser  # noqa: E402
17
18# "42" for a string parameter stays a string only when the call finds its tool's schema
19SCHEMA = [{"name": "capture", "parameters": {"properties": {"content": {"type": "string"}}}}]
20CALL = "<tool_call>\n<function= capture>\n<parameter=content>\n42\n</parameter>\n</function>\n</tool_call>"
21
22
23def calls(text, stream_tools):
24    p = OutputParser(thinking=True, tools=SCHEMA, stream_tools=stream_tools)
25    evs = []
26    for i in range(0, len(text), 3):                   # fed in small pieces, as a stream arrives
27        evs += p.feed(text[i:i + 3])
28    evs += p.finish("stop")
29    return [(e.call.name, e.call.arguments) for e in evs if e.kind == "tool_call"]
30
31
32class SpacedName(unittest.TestCase):
33    def check(self, text):
34        for stream_tools in (False, True):
35            with self.subTest(stream_tools=stream_tools):
36                self.assertEqual(calls(text, stream_tools), [("capture", {"content": "42"})])
37
38    def test_inside_the_thinking(self):
39        self.check("Let me save this.\n" + CALL + "\n")
40
41    def test_after_the_thinking(self):
42        self.check("Saving it.</think>\n\n" + CALL)
43
44
45if __name__ == "__main__":
46    unittest.main()