fix(copilot): address autogpt-reviewer should-fix items from PR #12398 review

- run_block.py: mark block_name as optional in description
- web_fetch.py: restore SSRF hint "Public URLs only — internal addresses blocked"
- agent_output.py: restore "Returns current state on timeout" to wait_if_running;
  trim run_time description from ~140 chars to ~75 chars
- workspace_files.py: add trailing period to filename description
- tool_schema_test.py: add token budget regression test (assert < 8000 tokens,
  current baseline ~5200 tokens) to lock in the 34% token reduction
This commit is contained in:
Zamil Majdy
2026-03-15 22:18:43 +07:00
parent f0c3eb87d1
commit 3bc8db491f
5 changed files with 28 additions and 5 deletions

View File

@@ -138,11 +138,11 @@ class AgentOutputTool(BaseTool):
},
"run_time": {
"type": "string",
"description": "Time filter: 'latest', relative ranges (e.g., today/yesterday/last week/last 7 days/last month/last 30 days), 'YYYY-MM-DD', or ISO datetime.",
"description": "Time filter: 'latest', today/yesterday/last week/last 30 days, 'YYYY-MM-DD', or ISO datetime.",
},
"wait_if_running": {
"type": "integer",
"description": "Max seconds to wait if still running (0-300).",
"description": "Max seconds to wait if still running (0-300). Returns current state on timeout.",
},
},
"required": [],

View File

@@ -61,7 +61,7 @@ class RunBlockTool(BaseTool):
},
"block_name": {
"type": "string",
"description": "Block name for UI display.",
"description": "Block name for UI display (optional).",
},
"input_data": {
"type": "object",

View File

@@ -4,12 +4,18 @@ Validates that every tool in TOOL_REGISTRY produces a well-formed schema:
- description is non-empty
- all `required` fields exist in `properties`
- every property has a `type` and `description`
- total token budget does not regress past 8000 tokens
"""
import json
import pytest
import tiktoken
from backend.copilot.tools import TOOL_REGISTRY
_TOKEN_BUDGET = 8_000
def _get_all_tool_schemas() -> list[tuple[str, object]]:
"""Return (tool_name, openai_schema) pairs for every registered tool."""
@@ -52,3 +58,20 @@ class TestToolSchema:
assert (
"description" in prop_def
), f"Tool '{tool_name}', property '{prop_name}' is missing 'description'"
def test_total_schema_token_budget() -> None:
"""Assert total tool schema size stays under the token budget.
This locks in the 34% token reduction from #12398 and prevents future
description bloat from eroding the gains. Budget is set to 8000 tokens
(current baseline is ~5200 tokens, giving ~54% headroom).
"""
schemas = [tool.as_openai_tool() for tool in TOOL_REGISTRY.values()]
serialized = json.dumps(schemas)
enc = tiktoken.get_encoding("cl100k_base")
total_tokens = len(enc.encode(serialized))
assert total_tokens < _TOKEN_BUDGET, (
f"Tool schemas use {total_tokens} tokens, exceeding budget of {_TOKEN_BUDGET}. "
f"Description bloat detected — trim descriptions or raise the budget intentionally."
)

View File

@@ -59,7 +59,7 @@ class WebFetchTool(BaseTool):
@property
def description(self) -> str:
return "Fetch a public web page. Returns readable text from HTML by default."
return "Fetch a public web page. Public URLs only — internal addresses blocked. Returns readable text from HTML by default."
@property
def parameters(self) -> dict[str, Any]:

View File

@@ -632,7 +632,7 @@ class WriteWorkspaceFileTool(BaseTool):
"properties": {
"filename": {
"type": "string",
"description": "Filename (e.g. 'report.pdf')",
"description": "Filename (e.g. 'report.pdf').",
},
"content": {
"type": "string",