Stop appending unverified search citations to synthesized answers

This commit is contained in:
pewdiepie-archdaemon
2026-09-17 20:32:46 +00:00
parent 87b6a37885
commit 39a6a49664
4 changed files with 101 additions and 14 deletions
+49
View File
@@ -1,5 +1,54 @@
from src.clean_agent_preview import preview_tool_result_text
from src.clean_agent_preview import preserve_requested_web_recency
import json
import pytest
@pytest.mark.asyncio
async def test_runtime_does_not_append_unverified_search_result_as_citation(monkeypatch):
import src.clean_agent_preview as runtime
from src.tool_schemas import FUNCTION_TOOL_SCHEMAS
from src.tool_policy import ToolPolicy
from src.turn_contract import resolve_full_inventory_contract
answer = 'The retrieved page describes an older version; it does not establish the latest release.'
packets = iter([
{'choices': [{'delta': {'tool_calls': [{'index': 0, 'id': 'lookup', 'function': {
'name': 'web_search', 'arguments': '{"query":"latest Python official source"}',
}}]}}]},
{'choices': [{'delta': {'content': answer}}]},
])
class Response:
def __init__(self, payload): self.payload = payload
async def __aenter__(self): return self
async def __aexit__(self, *args): pass
def raise_for_status(self): pass
async def aiter_lines(self):
yield 'data: ' + json.dumps(self.payload)
yield 'data: [DONE]'
class Client:
def __init__(self, **kwargs): pass
async def __aenter__(self): return self
async def __aexit__(self, *args): pass
def stream(self, *args, **kwargs): return Response(next(packets))
async def execute(block, **kwargs):
return 'web_search', {'output': '[1] Old Python release\n https://python.org/old-release/',
'exit_code': 0, 'evidence_status': 'available'}
monkeypatch.setattr(runtime.httpx, 'AsyncClient', Client)
monkeypatch.setattr(runtime, 'execute_tool_block', execute)
schemas = [s for s in FUNCTION_TOOL_SCHEMAS if s['function']['name'] == 'web_search']
contract = resolve_full_inventory_contract(schemas=schemas, policy=ToolPolicy())
raw = [chunk async for chunk in runtime.stream_preview(
endpoint_url='http://test', model='test',
messages=[{'role': 'user', 'content': 'latest Python version? official source please'}],
headers={}, turn_contract=contract, session_id='test', owner='test',
disabled_tools=set(), tool_policy=ToolPolicy(), max_rounds=3,
)]
events = [json.loads(chunk[6:]) for chunk in raw if '[DONE]' not in chunk]
final = ''.join(event.get('delta', '') for event in events)
assert answer in final
assert 'old-release' not in final
assert '[Source:' not in final
assert not any(event.get('type') == 'error' for event in events)
def test_news_intent_survives_query_rewording_without_changing_other_fresh_queries():