diff --git a/agent/tools/definitions.py b/agent/tools/definitions.py index 0a91c33..29788cf 100644 --- a/agent/tools/definitions.py +++ b/agent/tools/definitions.py @@ -5,12 +5,16 @@ from typing import Any +MAX_STRICT_TOOLS = 20 # the Claude API refuses a request with more strict tools than this + def _tool(name: str, description: str, **properties: dict[str, Any]) -> dict[str, Any]: + """Strict only when it takes inputs: strict checks the inputs, and the API allows at most + MAX_STRICT_TOOLS strict tools per request.""" return { "name": name, "description": description, - "strict": True, + "strict": bool(properties), "input_schema": { "type": "object", "properties": properties, diff --git a/tests/test_tool_definitions.py b/tests/test_tool_definitions.py new file mode 100644 index 0000000..98cebed --- /dev/null +++ b/tests/test_tool_definitions.py @@ -0,0 +1,12 @@ +"""The agent's tools are a request the Claude API accepts: on 2026-10-14 a 21st strict tool made +every session fail with 'Too many strict tools'.""" + +from agent.tools.definitions import MAX_STRICT_TOOLS, TOOLS + + +def test_no_more_strict_tools_than_the_api_accepts(): + assert sum(1 for t in TOOLS if t["strict"]) <= MAX_STRICT_TOOLS + + +def test_every_tool_with_inputs_is_strict(): + assert all(t["strict"] for t in TOOLS if t["input_schema"]["properties"])