oclaw/tests/test_tool_batch_partition.py
oliver ba3836f00f 初始化:独立 oclaw 仓库首提交
- 在 oclaw/ 下重新初始化 Git 仓库
- 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等)
- 提交当前工程代码与配置

Made-with: Cursor
2026-04-24 22:31:22 +08:00

39 lines
1.4 KiB
Python

from __future__ import annotations
from oclaw.chat.tool_runtime import partition_tool_use_batches
from oclaw.platform.llm.chat_models import LLMToolCall
from oclaw.tools.base import ToolRegistry, ToolSpec
def _spec(name: str, *, read_only: bool) -> ToolSpec:
return ToolSpec(
name=name,
description="t",
parameters={"type": "object", "properties": {}},
handler=lambda _a: {"ok": True},
read_only=read_only,
)
def test_partition_merges_consecutive_read_only() -> None:
reg = ToolRegistry([_spec("a", read_only=True), _spec("b", read_only=True), _spec("c", read_only=False)])
calls = [
LLMToolCall(id="1", name="a", arguments={}),
LLMToolCall(id="2", name="b", arguments={}),
LLMToolCall(id="3", name="c", arguments={}),
LLMToolCall(id="4", name="a", arguments={}),
]
batches = partition_tool_use_batches(calls, reg)
assert [len(b) for b in batches] == [2, 1, 1]
assert [tc.id for b in batches for tc in b] == ["1", "2", "3", "4"]
def test_partition_unknown_tool_is_sequential_only() -> None:
reg = ToolRegistry([_spec("a", read_only=True)])
calls = [
LLMToolCall(id="1", name="a", arguments={}),
LLMToolCall(id="2", name="missing", arguments={}),
LLMToolCall(id="3", name="a", arguments={}),
]
batches = partition_tool_use_batches(calls, reg)
assert [len(b) for b in batches] == [1, 1, 1]