mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-25 08:04:57 +08:00
test/tools: catalog, grants, and async tool helpers
This commit is contained in:
@@ -9,13 +9,13 @@ if TYPE_CHECKING:
|
||||
from collections.abc import Mapping
|
||||
|
||||
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def delete_path(path: str, *, recursive: bool = False) -> str:
|
||||
del recursive
|
||||
return f"deleted {path}"
|
||||
|
||||
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def read_file(path: str) -> str:
|
||||
return f"read {path}"
|
||||
|
||||
|
||||
@@ -268,7 +268,7 @@ async def test_chat_agent_accumulates_session_usage() -> None:
|
||||
async def test_chat_agent_turn_usage_sums_tool_rounds() -> None:
|
||||
"""Multi-round tool loop: turn usage is billing sum; last_request is final call."""
|
||||
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def ping() -> str:
|
||||
return "pong"
|
||||
|
||||
@@ -437,7 +437,7 @@ async def test_non_stream_yields_reasoning() -> None:
|
||||
|
||||
|
||||
async def test_run_chat_loop_with_tools() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def add(a: int, b: int) -> int:
|
||||
return a + b
|
||||
|
||||
@@ -470,7 +470,7 @@ async def test_run_chat_loop_with_tools() -> None:
|
||||
|
||||
|
||||
async def test_max_rounds() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def ping() -> str:
|
||||
return "pong"
|
||||
|
||||
@@ -494,7 +494,7 @@ async def test_max_rounds() -> None:
|
||||
|
||||
|
||||
async def test_max_rounds_continue_hook() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def ping() -> str:
|
||||
return "pong"
|
||||
|
||||
@@ -537,7 +537,7 @@ async def test_max_rounds_continue_hook() -> None:
|
||||
|
||||
|
||||
async def test_max_rounds_async_continue_hook() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def ping() -> str:
|
||||
return "pong"
|
||||
|
||||
@@ -721,7 +721,7 @@ async def test_retry_keeps_committed_tools_after_second_round_fails() -> None:
|
||||
session = await store.create_session(name="t")
|
||||
calls: list[str] = []
|
||||
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def side_effect() -> str:
|
||||
calls.append("ran")
|
||||
return "done-once"
|
||||
@@ -809,7 +809,7 @@ async def test_chat_agent_system_prompt_prepended() -> None:
|
||||
|
||||
|
||||
async def test_tool_result_char_budget() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def big() -> str:
|
||||
return "x" * 100
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ async def test_parallel_tool_calls_run_concurrently() -> None:
|
||||
gate = asyncio.Event()
|
||||
wait_timeout = 2.0
|
||||
|
||||
@tool
|
||||
@tool(register=False)
|
||||
async def slow_a() -> str:
|
||||
nonlocal started
|
||||
started += 1
|
||||
@@ -135,7 +135,7 @@ async def test_parallel_tool_calls_run_concurrently() -> None:
|
||||
_ = await asyncio.wait_for(gate.wait(), timeout=wait_timeout)
|
||||
return "a"
|
||||
|
||||
@tool
|
||||
@tool(register=False)
|
||||
async def slow_b() -> str:
|
||||
nonlocal started
|
||||
started += 1
|
||||
|
||||
@@ -4,7 +4,7 @@ from plyngent.agent import ToolRegistry, schema_from_callable, tool
|
||||
|
||||
|
||||
def test_tool_decorator_infers_schema() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def add(a: int, b: int = 0) -> int:
|
||||
"""Add two numbers."""
|
||||
return a + b
|
||||
@@ -18,7 +18,7 @@ def test_tool_decorator_infers_schema() -> None:
|
||||
|
||||
|
||||
def test_tool_decorator_overrides() -> None:
|
||||
@tool(name="ping", description="health")
|
||||
@tool(name="ping", description="health", register=False)
|
||||
def health() -> str:
|
||||
return "ok"
|
||||
|
||||
@@ -36,11 +36,11 @@ def test_schema_from_callable_optional() -> None:
|
||||
|
||||
|
||||
async def test_registry_execute_sync_and_async() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def echo(text: str) -> str:
|
||||
return text
|
||||
|
||||
@tool
|
||||
@tool(register=False)
|
||||
async def upper(text: str) -> str:
|
||||
return text.upper()
|
||||
|
||||
@@ -50,7 +50,7 @@ async def test_registry_execute_sync_and_async() -> None:
|
||||
|
||||
|
||||
async def test_registry_unknown_and_bad_json() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def noop() -> str:
|
||||
return "ok"
|
||||
|
||||
@@ -60,7 +60,7 @@ async def test_registry_unknown_and_bad_json() -> None:
|
||||
|
||||
|
||||
async def test_registry_handler_error() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def boom() -> str:
|
||||
msg = "nope"
|
||||
raise RuntimeError(msg)
|
||||
@@ -71,7 +71,7 @@ async def test_registry_handler_error() -> None:
|
||||
|
||||
|
||||
def test_tool_items() -> None:
|
||||
@tool
|
||||
@tool(register=False)
|
||||
def f(x: int) -> int:
|
||||
return x
|
||||
|
||||
|
||||
Reference in New Issue
Block a user