mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
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:
@@ -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": [],
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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."
|
||||
)
|
||||
|
||||
@@ -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]:
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user