unify broad web briefing semantics

This commit is contained in:
pewdiepie-archdaemon
2026-09-17 18:58:31 +00:00
parent be48da1146
commit 6121442658
3 changed files with 67 additions and 13 deletions
+3 -13
View File
@@ -30,7 +30,8 @@ from src.tool_schemas import (
)
from src.tool_types import ToolBlock
from src.turn_contract import (
FAMILY_TOOLS, required_read_operation_for_request, targets_bound_editor_request,
FAMILY_TOOLS, broad_web_briefing_request, required_read_operation_for_request,
targets_bound_editor_request,
)
from src.prompt_security import untrusted_context_message
from src.model_profiles import (
@@ -890,18 +891,7 @@ def contentless_final_response(content):
def broad_current_web_request(user_text):
"""Whether the user requested a broad current-information briefing."""
request = str(user_text or '')
return bool(
(
re.search(r'\b(?:latest|recent|current|today(?:\'s)?)\b', request, re.I)
and re.search(r'\b(?:info(?:rmation)?|news|nees|updates?)\b', request, re.I)
)
or re.search(
r"\b(?:what(?:'s|\s+is)|anything|something)\s+new\b",
request,
re.I,
)
)
return broad_web_briefing_request(user_text)
def incomplete_broad_web_answer(content, user_text):
+31
View File
@@ -3948,6 +3948,35 @@ def recently_read_gallery(history: Iterable, *, user_turns: int = 4) -> bool:
return False
def broad_web_briefing_request(message: str) -> bool:
"""Recognize requests that need broad, current, multi-source Web evidence."""
text = _normalize_request_lead(message)
if re.search(
r"\b(?:what(?:'s|\s+is)\s+(?:new|happening)|anything\s+new|"
r"catch\s+me\s+up|give\s+me\s+(?:an?\s+)?update|"
r"what\s+should\s+i\s+know)\b",
text,
re.I,
):
return True
if re.search(r"\b(?:news|headlines?|top\s+stories|news\s+roundup)\b", text, re.I):
return True
if (
re.search(r"\b(?:latest|recent|current|today(?:'s)?|right\s+now)\b", text, re.I)
and re.search(
r"\b(?:developments?|updates?|trends?|breakthroughs?|events?|stories|"
r"recommendations?|reviews?|best|compare|comparison)\b",
text,
re.I,
)
):
return True
return bool(
re.search(r"\b(?:recommend|best)\b", text, re.I)
and re.search(r"\b(?:current|latest|today|right\s+now|reviews?)\b", text, re.I)
)
def requested_capabilities(message: str, history: Iterable = (), *, active_document=False, workspace=False) -> frozenset[str]:
"""Classify once; inherit a prior capability only for a referential follow-up."""
raw_text = str(message or "").strip()
@@ -3956,6 +3985,8 @@ def requested_capabilities(message: str, history: Iterable = (), *, active_docum
text = lead["request"].strip()
history = tuple(history)
concrete_urls = re.findall(r"\bhttps?://[^\s<>\"']+", raw_text, re.I)
if broad_web_briefing_request(text):
return frozenset({"search_browser"})
if re.search(r"\b(?:web_search|web_fetch)\b", raw_text, re.I):
# Explicit native-tool requests are stronger than incidental domain
# words in the research subject (for example, Git ``pull`` must not
+33
View File
@@ -19,6 +19,39 @@ from src.turn_contract import (
)
@pytest.mark.parametrize('prompt', [
"What's new in Sweden?",
"What's happening in Sweden?",
'Give me an update on Sweden',
'Catch me up on Sweden',
'What are the top stories in Sweden today?',
'What should I know about Sweden right now?',
'Latest developments in AI',
'Recent AI breakthroughs',
'AI news',
'Compare the latest AI models',
'Best laptops right now',
'Recommend a laptop based on current reviews',
])
def test_broad_web_briefings_share_one_search_semantic(prompt):
from src.turn_contract import broad_web_briefing_request
assert broad_web_briefing_request(prompt)
assert requested_capabilities(prompt) == frozenset({'search_browser'})
@pytest.mark.parametrize('prompt', [
'What is the latest Python version?',
"Who is Sweden's prime minister?",
'Find the WIKING Miro manual online',
'How does Rust ownership work?',
])
def test_narrow_lookups_are_not_misclassified_as_broad_briefings(prompt):
from src.turn_contract import broad_web_briefing_request
assert not broad_web_briefing_request(prompt)
def resolve(capabilities=(), *, schemas=FUNCTION_TOOL_SCHEMAS, policy=None, required_tools=(),
required_capabilities=None, selected_tools=None, warm_tools=()):
return resolve_turn_contract(capabilities=capabilities, schemas=schemas,