Filtering Wikipedia Live with a Local Agent in Two Steps

Le brief IA que les pros lisent chaque soir
Les 7 actus IA du jour, décryptées en 5 min. Gratuit.
Inclus dès l'inscription : notre sélection des meilleurs guides & comparatifs IA.
Choisis ton rythme
Gratuit · Pas de spam · Désabonnement en 1 clic
In response to the continuous flow of changes on Wikipedia, a local architecture proposes to massively filter in Python before mobilizing a model via Ollama. This approach, designed for input and output "streaming," avoids resource exhaustion and operates without cloud or authentication.
Filter First, Reason Later with Thresholds and Quotas
The system relies on a two-step funnel. First, simple calculations in Python are executed for each event, including the volume of bytes removed and the number of recent edits per user. The majority of changes are discarded at this stage as they are deemed irrelevant. Next, the local LLM is only engaged for the fraction of events that exceed certain thresholds. This principle borrows from monitoring systems, where inexpensive filters are prioritized upstream before reserving more costly reasoning for selected cases. To keep pace, EditVelocityTracker maintains a sliding window of timestamps per user, purging the oldest entries and evicting data to limit memory when the number of tracked users exceeds a ceiling. Stage1Filter ignores bots, calculates the number of recent edits and bytes removed, and only emits a signal if a threshold of bytes deleted or edit velocity is surpassed, documenting the reason. Most events do not progress beyond step 1; only the survivors are submitted to the local reasoner, where a strict schema and token streaming come into play.
A Public SSE Stream, Unauthenticated, Processed Continuously
Wikipedia edits are broadcast in SSE format over HTTP via a public endpoint. Ingestion requires no key or handshake other than an open GET request. In this setup, the only outgoing connection targets this public service, which does not require authentication. The asynchronous consumer opens an HTTP client, reads the SSE lines from the configured stream URL, and applies filtering based on sets of monitored wikis before converting and emitting internal events. In the event of an HTTP error, a 5-second delay is observed before retrying, with the entire system designed to reconnect in a loop to ensure truly continuous operation.
Anonymity Detection and Normalization of Edit Events
Wikipedia attributes anonymous edits to the editor's IP address, used as a username. Anonymity detection is thus performed by checking if the string resembles an IPv4 or IPv6 address using regular expressions. The SSE parser extracts JSON payloads after the "data:" prefix and ignores non-compliant elements, while a second function discards events that are not of type "edit" before constructing an internal object with the necessary fields, default values in the absence of data (such as "unknown"), and meta-information such as bot status, timestamp, and comment. These functions, written without network dependencies, facilitate unit testing, which helped catch a previous bug in anonymity detection. The normalized events rely on a Pydantic model that also provides a method for calculating the bytes actually removed.
Prerequisites and Local Stack Without Cloud or Keys
The environment is based on Python 3.11+, dependencies like fastapi, uvicorn, httpx, pydantic, ollama, and sse-starlette, and a locally downloaded Ollama model, for example via "ollama pull llama3.1:8b," as long as it supports structured JSON output. No cloud account or API key is required, and no costs are announced beyond the machine's electricity. The project's directory structure isolates each step of the pipeline into dedicated files, an organization designed to make each component easier to understand and test independently.
Two Meanings of "Streaming" and Ambient Agent Framework
Here, "streaming" encompasses both the ingestion of live events and the token-by-token broadcasting of output, two issues that the construction addresses simultaneously. The approach fits within the definition of an ambient agent, which is triggered by the arrival of events rather than the receipt of a human message, as described by LangChain and Google's agent kit from an infrastructure perspective. The use case is concrete: locally monitor the public stream of Wikipedia edits, without an API key, to reason about changes that may be vandalism, all functioning on the machine via Ollama. This organization by filters and thresholds is motivated by the sustained nature of the stream, which can include several edits per second, and by the risks of resource exhaustion and temporal drift if every event were sent to the model.
Brief IA — L'actualité IA en français
L'essentiel de l'actualité de l'intelligence artificielle, décrypté et expliqué chaque jour.