Skip to main content Switch to mobile version limen-agents 0.6.5 The AI module of Limen: LLM providers with a budget, faithfulness checks, the chat agents, the one MCP server over the open-data libraries, and an A2A agent
pip install limen-agents==0.6.5 Copy PIP instructions
The AI module of Limen, an open early-warning system for landslides, floods and wildfires in Italy. It contains:
the language model providers behind one interface, with a spending cap;
the checks that keep a model's numbers honest;
the chat agents that put Limen's assessments into words, with the KG grounding of their citations;
the one MCP server of the project;
Limen as an A2A agent.
pip install "limen-agents[mcp]" # the MCP server over the open-data libraries pip install "limen-agents[a2a]" # the A2A agent pip install "limen-agents[providers]" # the Anthropic and OpenAI SDKs pip install "limen-agents[chat]" # the chat agents and the KG grounding Python 3.12+. Apache-2.0.
The project is split by job:
The open-data libraries handle data and nothing else, and none of them has a server of its own. They are dpc-radar, rainfall-thresholds, ispra-idrogeo, ingv-shakemap, glofas-ewds, fwi-chain, effis-client, firms-client, copernicus-ems, egms-client and imageserver-export.
limen-core joins the libraries: scoring, verification, the evidence of a cell. It is the only package that reaches them.
limen-ml trains and serves the models.
limen-agents (this package) is where a language model enters: providers, budget, checks, the chat agents, and the servers for assistants and agents.
Limen is the application: the database, the scheduler, the API, the alerts and the page. It uses limen-core and limen-agents.
limen_agents.chat holds the agents that put the deterministic engine's output into words. None of them is authoritative: they reformulate, never change a score, and each has a deterministic fallback. Their Italian prompts ship in the package (limen_agents.chat.prompts); a hazard gets a narrative by dropping briefing.
RiskAnalystAgent(client).analyse(assessment, evidence=()): a RiskAnalysis JSON (or, with use_tools=True, one whose readings the model chose: below), with one repair retry and a neutral fallback; ungrounded_numbers lists the numbers of its anomalies that are neither in the summary nor in the limen_core.evidence it was given.
BriefingAgent(client, grounding=None, region_code=region_code).brief(assessment, analysis): the Italian story, 220 to 400 words, or deterministic_briefing when the model fails. Its rain numbers are checked against the rain event (limen_core.rain_grounding) and, for landslides, its IFFI numbers against the reliability of the inventory in the region (limen_core.iffi, limen_core.idrogeo_grounding): a number not found becomes a warning, the text is not changed.
StoryTranslator(client).translate(text, anomalies): the English version, accepted only with exactly the same numbers.
rephrase_data_quality(client, lines): the nightly data-quality lines as a paragraph, dropped if it adds a number.
FaithfulnessReviewer and EventExtractor: a second model judging a story against its data, and the events the press headlines tell, both on Anthropic Message Batches (they also need providers).
The analyst that chooses its readings
Off by default. With use_tools=True and a client that can call tools (Anthropic, OpenAI, Azure OpenAI, Claude on Foundry), the analyst lets the model read the open-data sources around the top cells itself, then answers with the same RiskAnalysis:
from limen_core.evidence import Cell, gather, plan from limen_agents.chat import RiskAnalystAgent from limen_agents.llm import ToolLoopLimits analyst = RiskAnalystAgent( factory.create("RiskAnalyst"), use_tools=True, # default False: the analysis of 0.5.0, call for call tool_limits=ToolLoopLimits(max_rounds=3, max_tool_calls=8, total_timeout_s=120), ) cells = [Cell(c.cell_id, *centroids[c.cell_id]) for c in assessment.top_cells] async def phase_one(): # read only if the tool path does not answer return await gather(plan("landslide", cells, at=assessment.valuation_time, bbox=bbox)) run = await analyst.analyse_traced( assessment, phase_one, cells=cells, at=assessment.valuation_time, bbox=bbox ) print(run.path, run.analysis, run.ungrounded, run.fallback_reason) The tools are the readings of limen_core.evidence (limen_agents.evidence_tools), read-only, with the MCP tools' checks (degrees in range, radii up to 50 km, an EMSR code), and no point farther than 50 km from the cells. Each hazard has its own (DEFAULT_TOOLS; tools= changes them).
The loop (run_tool_loop) is bounded: rounds, calls, a timeout per call and one in all, and the budget is checked before every model call. Tool answers go back as data, not instructions, with their attribution; a tool error goes back to the model.
The fallback. A provider without tools (llama.cpp, Ollama, the stub), no centroids, a failed or slow loop, or an answer that is not valid JSON: the analyst takes the evidence path, with the evidence given and what the tools read. run.fallback_reason says why.
The numbers of the anomalies are checked against the summary and the evidence really read (run.ungrounded).
ToolChatClient and run_tool_loop are in limen_agents.llm for any other agent.
They take a ChatClient from limen_agents.llm and log with structlog; the event names (llm.fallback, briefing.length, traduzione.numeri_diversi, …) are the ones Limen's dashboards read.
The application's pieces are passed in. This is how Limen wires them:
from limen_agents.chat import BriefingAgent, EventExtractor from limen_agents.grounding import GroundingService, KgClient kg = KgClient( base_url=settings.kg.base_url, thread_id=settings.kg.thread_id, timeout_seconds=settings.kg.timeout_seconds, api_token=settings.kg.api_token, # a SecretStr, never in a repr enabled=settings.kg.enabled, http_client=await SharedHttpClient.get(), # optional: Limen's pooled client ) grounding = GroundingService( client=kg, cache=postgres_cache, # anything with get_json / set_json(…, ttl_seconds=) enabled=settings.kg.enabled, timeout_seconds=settings.kg.timeout_seconds, cache_ttl_seconds=settings.kg.cache_ttl_seconds, top_k=settings.kg.top_k, ) briefer = BriefingAgent(factory.create("Briefing"), grounding=grounding) extractor = EventExtractor(api_key=key, model=model, max_wait_s=3600) events = await extractor.extract({HazardType.LANDSLIDE: titoli}) # Limen's `Titolo` is a `Headline` The KG client takes its settings as arguments; without http_client it opens its own and aclose() (or async with) closes it.
The cache is a Cache protocol of two methods, get_json(key) and set_json(key, value, *, ttl_seconds): Limen passes its Postgres app_cache.
The headlines are a Headline protocol (titolo, testata, url, pubblicato): a frozen dataclass with those fields fits.
The regions: the IFFI note of a landslide story needs the ISTAT code of the AOI's region. The default reads Limen's regional AOI ids (it-puglia → 16, ITALIAN_REGION_CODES); an application with other ids passes region_code=.
limen_agents.grounding.schema holds the payloads of the KG sidecar (GroundingQuery, GroundingResult, Passage, IngestDocument, IngestRequest), and format_citations the «Fonti» block appended to the story.
limen-agents-mcp # standard input and output limen-agents-mcp --http # Streamable HTTP on 127.0.0.1:8790 claude mcp add limen -- uvx --from "limen-agents[mcp]" limen-agents-mcp Each tool reads a library through limen_core.evidence:
rain_at and storms_now: radar rain and storms in progress (DPC);
landslides_near: landslides of the IFFI inventory (ISPRA);
earthquakes_near: earthquakes and the ground shaking they caused (INGV ShakeMap);
fire_danger: fire danger (EFFIS);
fires_in_area: fires seen from space (NASA FIRMS);
river_discharge: the GloFAS river discharge and forecast peak of the place stored nearest a point (glofas-ewds; reads the store filled beforehand with glofas-ewds, no key);
flood_activations: the Copernicus EMS Rapid Mapping activations of a country over the last days, each with its code (copernicus-ems; public, no key);
flood_activation_summary(code, hazard="flood"): what one activation observed, per product and per area of interest (copernicus-ems; public, no key);
flood_water(code, lon, lat, radius_km=3): the water one activation observed within radius_km (at most 50) of a point, with the share of the observed part of the circle, from the first-issue products only (copernicus-ems; public, no key);
ground_motion: the EGMS ground velocity at a point (egms-client; needs a CLMS service key in EGMS_SERVICE_KEY or EGMS_SERVICE_KEY_FILE, read from the environment only);
ground_motion_before(lon, lat, day, window_days=180, component="U"): how the ground of the 1 km cell around a point moved before a day, from the EGMS time series: the velocity of the window before the day against the longer one, their change and the share of points that changed. A description, not an alert; null is not measured. Offline, from the tile's table fetched once with egms init --tile … --component U --keep tiff --keep csv (about 250 MB, in EGMS_DATA_DIR, else $DATA_ROOT/egms-client, else ~/.cache/egms-client); no key at read time;
evidence: every reading a Limen analyst gets for a hazard on some places;
check_numbers: the numbers of a text that are not in the results.
The instructions the model receives are the ANSWER_RULES of each library, joined, and the rules of the tools that read one thing by name (READING_RULES). Every number must come from a result; null means not measured, never zero; nothing here is an alert: ground_motion_before is a description of the past, never a warning or a prediction; the water share of flood_water is of the observed part of the place, from the first-issue products; every answer is quoted with its attribution.
An application adds its own tools. Limen adds its assessments and alerts this way:
from limen_agents.mcp_server import create_server async def assessment(aoi: str) -> dict: """The latest assessment of an area.""" ... server = create_server(extra_tools=[assessment]) A tool that writes says so, and can keep the name its clients know:
from limen_agents.mcp_server import WRITES, Tool async def run_monitor(aoi: str) -> dict: """Run the monitoring once (it writes).""" ... server = create_server( extra_tools=[assessment, Tool(run_monitor, name="tool_run_monitor", annotations=WRITES)], instructions="The application's own rules.", evidence_tools=False, # only the application's tools, no library client opened extensions=[], # MCP extensions (SEP-2133), for new request methods ) The A2A agent
limen-agents-a2a # http://127.0.0.1:8791, card at /.well-known/agent-card.json Other agents find Limen through its card and send it messages over JSON-RPC (SendMessage, A2A protocol 1.0).
By default the agent needs no model. It takes a JSON request and answers with what the sources say, as data:
{"hazard": "landslide", "cells": [{"id": "a", "lon": 16.05, "lat": 38.91}]} An application plugs in its own answer, one with a model behind it, as a function from text to text: create_app(answer).
from limen_agents.llm import ChatMessage, LlmConfig, resolve factory = resolve(LlmConfig(anthropic_api_key="...")) client = factory.create("Briefing") text = await client.chat([ChatMessage("user", "...")]) resolve follows Limen's order:
an Anthropic key, if the SDK is installed;
llama.cpp, the self-hosted fallback.
Ollama is chosen only explicitly. choose(config) gives the decision alone. An application with its own factories keeps the decision and builds the provider itself:
factory = resolve(config, builders={"anthropic": my_anthropic, "llamacpp": my_llamacpp}) Each builder gets the LlmConfig; a provider not named there gets the library's factory. on_event receives the decisions in place of the module's logger, and an explicit provider without credentials raises MissingCredentialsError, whose provider lets the application word the error for its operators. A MonthlyBudget over a store you provide caps the paid models; when the spend cannot be read, it lets no call through.
unknown_numbers(text, source) gives the numbers of a text that are not in the message the model received. evaluate_briefing adds the rules of a public briefing: length, no lists, no alarm terms, no orders to the reader. These are pure functions, with no model.
evals/ measures Claude answering through this server: 31 questions on the ISPRA data (an area's hazard and exposure, rankings, landslide counts, a point, monitoring, code meanings, three traps), each graded against a truth recomputed from the live IdroGEO API on every run, plus whether the answer cites ISPRA and whether the model checked its numbers. The eval builds its server with create_server(extra_tools=...), adding the readings of ispra_idrogeo.facts; those tools are not in the package.
make eval-dry # offline: an oracle in place of Claude, no key, $0; CI runs it ANTHROPIC_API_KEY=… make eval ARGS="--limit 5" # live pilot, about $0.25 on claude-sonnet-5-5 The key is read only from ANTHROPIC_API_KEY. All 31 cases cost about $1.50 on claude-sonnet-5-5 (the default) and twice that on claude-opus-5-5 (ARGS="--model claude-opus-5-5"); the report gives the measured cost.
Some sources need set-up. Without a CLMS key ground_motion answers with an error that names the variables, without a filled GloFAS store river_discharge does the same, and without the tile's table on disk ground_motion_before answers with the egms init command that fetches it; in evidence those readings are left out. The first EGMS read of a point downloads its tile, about 60 MB.
The motion before a day is not calibrated. The minimums of ground_motion_before (points, acquisitions, a year of history, two standard errors) are limen-core's conservative choices; nobody has yet measured that a change tells the cells with a landslide from the others. InSAR misses fast motion.
Flood activations are by country. The Rapid Mapping list has no geometry: find the code with flood_activations, then read one activation with flood_activation_summary and flood_water. flood_water takes a circle around a point; a place with its own boundary (a municipality) is read in Python with limen_core.evidence.flood_water_over_place, or added by an application as its own tool.
No model is called by this package unless you configure one. The default A2A answer is deterministic.
The faithfulness check finds invented numbers, not misplaced ones. A true number said of the wrong thing passes it.
The servers have no authentication. They listen on 127.0.0.1; see SECURITY.md.
Not an alert service. The official alert is the criticality bulletin of the Civil Protection Department and of the Region.
Apache-2.0. The data read by the tools keep their own licences: DPC and IFFI CC BY-SA 4.0; INGV, EFFIS, NASA FIRMS, GloFAS, Copernicus EMS and EGMS as stated in each answer.
Released: Dec 3, 2026
Author: Giuseppe Zileni
Both files in this release have provenance metadata.
View provenance details
Apache-2.0 View SPDX License List
a2a chat mcp providers
llm mcp a2a agents open-data civil-protection limen
Development Status 3 - Alpha
Intended Audience Science/Research
Operating System OS Independent
Programming Language Python :: 3
Release files for limen-agents 0.6.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 199.5 kB
Release files / limen_agents-0.6.5.tar.gz
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Release files / limen_agents-0.6.5-py3-none-any.whl
Security for limen-agents 0.6.5
Both files in this release have been uploaded with provenance metadata.
With provenance limen_agents-0.6.5.tar.gz Dec 3, 2026
With provenance limen_agents-0.6.5-py3-none-any.whl Dec 3, 2026
Attestation for limen_agents-0.6.5.tar.gz
Attestation for limen_agents-0.6.5-py3-none-any.whl
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.
Release history Release notifications | RSS feed
Dec 3, 2026 2 release files Full provenance
Nov 30, 2026 2 release files Full provenance
Nov 29, 2026 2 release files Full provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation
Deployed from 107c339











