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
@@ -16,12 +16,6 @@
extern "C" {
#endif
/*
* Backward compatibility
*/
#define initGenericErrorDefaultFunc(h) \
xmlSetGenericErrorFunc(NULL, (h) ? *((xmlGenericErrorFunc *) (h)) : NULL)
/**
* xmlErrorLevel:
*
@@ -217,11 +211,6 @@ typedef enum {
XML_ERR_USER_STOP, /* 111 */
XML_ERR_COMMENT_ABRUPTLY_ENDED, /* 112 */
XML_WAR_ENCODING_MISMATCH, /* 113 */
XML_ERR_RESOURCE_LIMIT, /* 114 */
XML_ERR_ARGUMENT, /* 115 */
XML_ERR_SYSTEM, /* 116 */
XML_ERR_REDECL_PREDEF_ENTITY, /* 117 */
XML_ERR_INT_SUBSET_NOT_FINISHED, /* 118 */
XML_NS_ERR_XML_NAMESPACE = 200,
XML_NS_ERR_UNDEFINED_NAMESPACE, /* 201 */
XML_NS_ERR_QNAME, /* 202 */
@@ -484,7 +473,6 @@ typedef enum {
XML_IO_EADDRINUSE, /* 1554 */
XML_IO_EALREADY, /* 1555 */
XML_IO_EAFNOSUPPORT, /* 1556 */
XML_IO_UNSUPPORTED_PROTOCOL, /* 1557 */
XML_XINCLUDE_RECURSION=1600,
XML_XINCLUDE_PARSE_VALUE, /* 1601 */
XML_XINCLUDE_ENTITY_DEF_MISMATCH, /* 1602 */
@@ -871,20 +859,23 @@ typedef void (*xmlGenericErrorFunc) (void *ctx,
typedef void (*xmlStructuredErrorFunc) (void *userData, const xmlError *error);
/** DOC_DISABLE */
XML_DEPRECATED
XMLPUBFUN const xmlError *__xmlLastError(void);
#define XML_GLOBALS_ERROR \
XML_OP(xmlLastError, xmlError, XML_DEPRECATED) \
XML_OP(xmlGenericError, xmlGenericErrorFunc, XML_NO_ATTR) \
XML_OP(xmlGenericErrorContext, void *, XML_NO_ATTR) \
XML_OP(xmlStructuredError, xmlStructuredErrorFunc, XML_NO_ATTR) \
XML_OP(xmlStructuredErrorContext, void *, XML_NO_ATTR)
XMLPUBFUN xmlGenericErrorFunc *__xmlGenericError(void);
XMLPUBFUN void **__xmlGenericErrorContext(void);
XMLPUBFUN xmlStructuredErrorFunc *__xmlStructuredError(void);
XMLPUBFUN void **__xmlStructuredErrorContext(void);
#define XML_OP XML_DECLARE_GLOBAL
XML_GLOBALS_ERROR
#undef XML_OP
#ifndef XML_GLOBALS_NO_REDEFINITION
#define xmlLastError (*__xmlLastError())
#define xmlGenericError (*__xmlGenericError())
#define xmlGenericErrorContext (*__xmlGenericErrorContext())
#define xmlStructuredError (*__xmlStructuredError())
#define xmlStructuredErrorContext (*__xmlStructuredErrorContext())
#if defined(LIBXML_THREAD_ENABLED) && !defined(XML_GLOBALS_NO_REDEFINITION)
#define xmlLastError XML_GLOBAL_MACRO(xmlLastError)
#define xmlGenericError XML_GLOBAL_MACRO(xmlGenericError)
#define xmlGenericErrorContext XML_GLOBAL_MACRO(xmlGenericErrorContext)
#define xmlStructuredError XML_GLOBAL_MACRO(xmlStructuredError)
#define xmlStructuredErrorContext XML_GLOBAL_MACRO(xmlStructuredErrorContext)
#endif
/** DOC_ENABLE */
@@ -895,15 +886,16 @@ XMLPUBFUN void **__xmlStructuredErrorContext(void);
XMLPUBFUN void
xmlSetGenericErrorFunc (void *ctx,
xmlGenericErrorFunc handler);
XML_DEPRECATED
XMLPUBFUN void
xmlThrDefSetGenericErrorFunc(void *ctx,
xmlGenericErrorFunc handler);
XML_DEPRECATED
XMLPUBFUN void
initGenericErrorDefaultFunc (xmlGenericErrorFunc *handler);
XMLPUBFUN void
xmlSetStructuredErrorFunc (void *ctx,
xmlStructuredErrorFunc handler);
XML_DEPRECATED
XMLPUBFUN void
xmlThrDefSetStructuredErrorFunc(void *ctx,
xmlStructuredErrorFunc handler);
@@ -927,17 +919,11 @@ XMLPUBFUN void
xmlParserValidityWarning (void *ctx,
const char *msg,
...) LIBXML_ATTR_FORMAT(2,3);
/** DOC_DISABLE */
struct _xmlParserInput;
/** DOC_ENABLE */
XMLPUBFUN void
xmlParserPrintFileInfo (struct _xmlParserInput *input);
XMLPUBFUN void
xmlParserPrintFileContext (struct _xmlParserInput *input);
XMLPUBFUN void
xmlFormatError (const xmlError *err,
xmlGenericErrorFunc channel,
void *data);
/*
* Extended error information routines