Skip to content

Self-hosted AI workspace.

Python

require domain evidence for official source shortcut

pewdiepie-archdaemon566202dcad02
diff --git a/src/clean_agent_preview.py b/src/clean_agent_preview.py
index 1c14b61de..d44f0f385 100644
--- a/src/clean_agent_preview.py
+++ b/src/clean_agent_preview.py
@@ -3251,17 +3251,7 @@ def web_source_links(raw, *, max_items=1, prefer_official=False, query=''):
host == domain or host.endswith('.' + domain)
for domain in official_domains
)
- direct_document = bool(re.search(
- r'\.(?:pdf|docx?|xlsx?|pptx?)(?:$|[?#])', row[1], re.I,
- ))
- query_tokens_in_url = any(
- token in row[1].casefold()
- for token in query_tokens
- if len(token) >= 4
- )
- if query_host_match or (
- not official_domains and direct_document and query_tokens_in_url
- ):
+ if query_host_match:
primary.append(row)
rows = primary
links = []
@@ -5185,10 +5175,14 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac
and requested_web_source_links(direct_user_text)
):
requested_links = requested_web_link_limit(direct_user_text)
+ official_requested = bool(re.search(r'\bofficial\b', direct_user_text, re.I))
+ known_official_domains = official_domains_for_text(
+ direct_user_text + ' ' + str(args.get('query', ''))
+ )
source_links = web_source_links(
output,
max_items=requested_links or 1,
- prefer_official=bool(re.search(r'\bofficial\b', direct_user_text, re.I)),
+ prefer_official=official_requested,
query=args.get('query', ''),
)
source_only_request = not re.search(
@@ -5203,7 +5197,7 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac
link for _, link in source_links[:requested_links]
)
elif (requested_links and not source_links
- and re.search(r'\bofficial\b', direct_user_text, re.I)):
+ and official_requested and known_official_domains):
if not official_source_retry_attempted and round_number < round_limit:
official_source_retry_attempted = True
force_web_search_next_round = True
diff --git a/tests/test_clean_agent_preview.py b/tests/test_clean_agent_preview.py
index 717f78d34..51727750a 100644
--- a/tests/test_clean_agent_preview.py
+++ b/tests/test_clean_agent_preview.py
@@ -2012,7 +2012,7 @@ def test_official_manual_does_not_invent_pdf_requirement():
assert explicit['query'].endswith('filetype:pdf')
-def test_unknown_official_domain_rejects_reseller_but_accepts_direct_document():
+def test_unknown_official_domain_cannot_be_proven_by_pdf_suffix():
raw = '''
[1] WIKING Miro 4 Wood Burning Stove
https://scottishstovecentre.co.uk/product/wiking-miro-4/
@@ -2025,11 +2025,9 @@ def test_unknown_official_domain_rejects_reseller_but_accepts_direct_document():
query='WIKING Miro stove manual official source filetype:pdf',
)
- assert links == [(
- 'https://www.hwam.com/pub/media/wiking/53-0756_Miro_EN.pdf',
- '[Source: WIKING Miro Installation and User Manual]'
- '(https://www.hwam.com/pub/media/wiking/53-0756_Miro_EN.pdf)',
- )]
+ assert links == []
+ # Candidates remain in the full tool output for the model to inspect.
+ assert len(web_source_links(raw, max_items=2, query='WIKING Miro')) == 2
def test_web_fetch_collapses_single_and_batch_url_fields_without_losing_targets():
@@ -2044,7 +2042,7 @@ def test_web_fetch_collapses_single_and_batch_url_fields_without_losing_targets(
}
-def test_manual_locator_prefers_manufacturer_link_and_requests_one_result():
+def test_manual_locator_requests_one_result_but_needs_manufacturer_evidence():
from src.clean_agent_preview import (
requested_web_link_limit, requested_web_source_links, web_source_links,
)
@@ -2061,12 +2059,7 @@ def test_manual_locator_prefers_manufacturer_link_and_requests_one_result():
assert requested_web_link_limit(prompt) == 1
assert web_source_links(
raw, max_items=1, prefer_official=True, query=prompt,
- ) == [
- (
- 'https://www.hwam.com/media/wiking/miro-en.pdf',
- '[Source: WIKING Miro English manual PDF](https://www.hwam.com/media/wiking/miro-en.pdf)',
- )
- ]
+ ) == []
def test_preview_allows_only_reversible_client_local_ui_control():