feat(agent): scrape linked pages to ground answers in real content

Adds `_fetch_page_content()`, which downloads a URL with a
browser-like User-Agent and uses BeautifulSoup with the lxml
parser to strip scripts, navigation, and other non-content
markup, returning up to 3000 characters of readable text.

The response validator now also compares generated replies
against this scraped text, flagging named entities and claims
that do not appear in the retrieved page content.

Dependencies: adds beautifulsoup4==4.12.3 and pins lxml==5.3.0
for parser compatibility.
This commit is contained in:
2026-10-26 16:48:29 -03:00
parent 9eed02645b
commit 723ca1506b
231 changed files with 20508 additions and 5330 deletions
@@ -45,13 +45,6 @@ _QName = ET.QName
from functools import partial
try:
from types import GenericAlias as _GenericAlias
except ImportError:
# Python 3.8 - we only need this as return value from "__class_getitem__"
def _GenericAlias(cls, item):
return f"{cls.__name__}[{item.__name__}]"
try:
basestring
except NameError:
@@ -234,10 +227,6 @@ class ElementMaker:
def __getattr__(self, tag):
return partial(self, tag)
# Allow subscripting ElementMaker in type annotations (PEP 560)
def __class_getitem__(cls, item):
return _GenericAlias(cls, item)
# create factory object
E = ElementMaker()