Skip to main content

Research lifecycle observer

Library users can pass an optional observer to GPTResearcher to receive structured events while sources move through planning, search, and scraping. The observer is disabled by default and does not replace the existing log or WebSocket interfaces.

from gpt_researcher import GPTResearcher


def observe(event, **fields):
print(event, fields)


researcher = GPTResearcher(
query="What changed in the latest release?",
research_observer=observe,
)

An object with an on_event(event, **fields) method can be used instead. Both synchronous and asynchronous handlers are supported. Observer exceptions are suppressed so telemetry cannot interrupt or change a research run.

Events​

EventFieldsMeaning
query_plannedquery, positionA planned query will be researched.
candidate_discoveredquery, provider, url, rankA search provider returned a candidate.
search_emptyquery, providerA provider returned no candidates.
search_failedquery, provider, reason_codeA provider failed and research continued, or an initial planning search failed before being re-raised.
selected_for_fetchquery, urlA candidate passed URL deduplication.
candidate_deduplicatedquery, url, reason_codeA previously visited URL was not fetched again.
content_prefetchedquery, provider, url, rank, content_lengthA provider supplied content that did not require scraping.
fetch_succeededurl, scraper, content_lengthA scraper produced a retained row.
fetch_failedurl, scraper, content_length, reason_codeA scraper failure was observed before the row was discarded.

Event payloads do not contain fetched page bodies, snippets, headers, cookies, or credentials. Query and URL fields can contain user or source information; observers that export or persist events are responsible for applying their own access control, redaction, and retention policy.

Adding an observer does not add searches, fetches, model calls, retries, or filtering decisions. Omitting it preserves the existing research behavior.