Skip to content

Self-hosted AI workspace.

Python

Require explicit initial search queries rather than copying whole requests

pewdiepie-archdaemon40edb5986442
diff --git a/src/clean_agent_preview.py b/src/clean_agent_preview.py
index bafb35a88..840b674b0 100644
--- a/src/clean_agent_preview.py
+++ b/src/clean_agent_preview.py
@@ -3460,15 +3460,13 @@ def preserve_requested_web_recency(name, args, *, user_text='', prior_search_int
user = str(user_text or '')
query = str(args.get('query') or '').strip()
if not query:
- if prior_search_intents:
- raise ValueError(
- 'web_search requires an explicit query for a follow-up. Supply a '
- 'specific missing fact, entity, or corroboration question based on '
- 'the evidence already returned; do not repeat the original query.'
- )
- query = re.sub(r'\s+', ' ', user).strip().rstrip('?.!')
- if not query:
- return args
+ raise ValueError(
+ 'web_search requires an explicit nonempty query. '
+ + ('Supply a specific missing fact, entity, or corroboration question '
+ 'based on the evidence already returned; do not repeat the original query.'
+ if prior_search_intents else
+ 'Supply the subject to search for, not the full conversation or answer-format instructions.')
+ )
normalized = dict(args)
# Keep the user's explicit news intent when a model rewrites it to a
# subject plus "today". Freshness alone does not select the news vertical.
diff --git a/tests/test_clean_agent_preview.py b/tests/test_clean_agent_preview.py
index 13a1034ff..6639d5fe4 100644
--- a/tests/test_clean_agent_preview.py
+++ b/tests/test_clean_agent_preview.py
@@ -2018,12 +2018,13 @@ def test_current_search_arguments_repair_stale_year_and_add_freshness():
@pytest.mark.parametrize('missing_query', [{}, {'query': ''}, {'query': ' ', 'time_filter': 'day'}])
-def test_missing_refinement_query_is_not_fabricated(missing_query):
- with pytest.raises(ValueError, match='explicit query for a follow-up'):
[email protected]('prior_intents', [[], ['ai news']])
+def test_missing_refinement_query_is_not_fabricated(missing_query, prior_intents):
+ with pytest.raises(ValueError, match='explicit nonempty query'):
preserve_requested_web_recency(
'web_search', missing_query,
user_text='serch latest ai news pls',
- prior_search_intents=['ai news'],
+ prior_search_intents=prior_intents,
)