Agentic Inventory Q&A for Maat — Implementation Process¶
How it works¶
user question
│
┌────▼─────────────────────────────┐
│ the agent │ a language model that plans, chooses
│ + 17 purpose-built functions │ functions, and writes the answer
└────┬─────────────────────────────┘
│ every read goes through here
┌────▼──────────┐ ┌──────────────┐
│ Maat MCP 1.0.5│──▶│ Maat + Mongo │ the inventory itself
└───────────────┘ └──────────────┘
A language model — the same kind behind a chat assistant — receives the question. It cannot query the inventory itself. Instead it is given 17 functions it can ask the system to run, such as count objects of this type or find everything connected to this router. The model decides which to call and in what order, reads the results, and composes the answer.
The central design choice¶
Anything that must be exact is done by code, not by the model.
Counting, ranking, totalling, proving that something is absent, sweeping a blast radius — each is a deterministic Python function that examines the entire inventory in one pass. The model's job is to understand the question, pick the right function, and explain the result. A language model asked to count will often examine a handful of examples and extrapolate, producing a confident and wrong number with nothing to indicate anything went wrong; moving that work into code removes the opportunity. It also makes the agent portable — in testing on MCP 1.0.5, eleven of thirteen models answer at least 103 of the 108 hard questions, because the hard parts are not being done by the model at all.
Built on an agent framework¶
The agent is built with LangChain deepagents, which handles the loop of ask the model → run the tool it requested → give it the result → repeat until it answers. Two things worth knowing:
- The framework ships extra built-in tools (a virtual filesystem, a "delegate to a sub-agent" tool). Both are unwanted here and are hidden from the model and refused if called anyway — hiding a tool from the model's tool list does not stop the model from calling it out of training habit, so refusal has to happen at call time too.
- Sub-agents are not used. Delegating part of a question to a second agent was tried and removed: the sub-agent sees only some of the tools, and when it cannot answer it returns an empty result rather than saying so — indistinguishable from a genuine "nothing found".
The 17 tools¶
All are read-only and all go through the MCP server.
Finding things
| tool | purpose |
|---|---|
summarize |
How many objects exist, by type — the starting point for broad questions. Detects and repairs the MCP's per-category breakdown, which is wrong above 10,000 objects. |
resolve_entity |
Turn a name into an identity. Names are not unique, so it returns every match (id, name, category, and the owning parent) rather than guessing. Given a wrong type, it still finds the object under its real type and says so. |
get_entity |
Everything about one object: attributes and relationships — including attributes that live on a relationship (for example whether a site is a cable's A-end or Z-end). |
find_entities |
List or filter objects by attribute; reports explicitly when truncated and returns the exact matched count; can return a count only. A filter that matches nothing says which spellings and values do exist. |
describe_category |
Which attributes a category actually has — and on which child, when they live one level down — with the allowed values of the ones that have a small fixed vocabulary. |
Every tool that takes an object's id also accepts its name: one match is used, several come back as candidates with their parent, none is reported as "no object named …". Weaker models used to pass names where ids were expected and then report real objects as missing.
Following relationships
| tool | purpose |
|---|---|
find_connected |
Find everything of a given type reachable from a starting object, without knowing the path in advance. direction='down' restricts it to containment. |
path_between |
The shortest connection between two objects, reporting honestly when there is none. |
Counting and aggregating — always over everything, never a sample
| tool | purpose |
|---|---|
rank_resource_usage |
Which equipment is used by the most services. |
rank_service_usage |
Which services touch the most equipment. |
aggregate_characteristic |
Total, average, minimum, maximum, median of a numeric attribute; top=N returns the N largest exactly and in order. |
group_by_characteristic |
Tally objects by an attribute, and detect duplicates. |
relate_and_count |
Group by a related object rather than an attribute ("routers per vendor", "services per customer"). |
Finding what is missing
| tool | purpose |
|---|---|
find_unused |
Objects with no service on them: dark cables, spare interfaces. |
find_orphans |
Objects with no relationships at all — a different problem from "unused". |
Both examine everything, because a sample can never prove that something is absent.
Combinations and impact
| tool | purpose |
|---|---|
filter_by_connections |
"How many X have both a Y and a Z", or neither — optionally with a condition on the link itself: "fiber spans that use buffer tube 3", "cables whose Z-end is at site S". |
common_between |
What two things share, and what is unique to each — shared-risk analysis. |
impact_of |
What breaks if a given cable, fibre, segment, router or site fails. Sweeps every service type itself and follows shared infrastructure — a cut cable takes down the transport links riding on it, and therefore every other service sharing those same interfaces. |
One property they all share: an error never looks like an empty result. A misspelled type, an unrecognised attribute or a wrongly-cased name returns an error naming the valid alternatives — never zero results, which would be indistinguishable from a genuine "there are none".
An argument a tool does not have is refused, not ignored. If a weaker model writes
find_entities(name='cable-044'), nothing runs and the tool replies with its real arguments and a
pointer to resolve_entity. Before this was added, the unknown argument was dropped silently, the
call listed the first cable, and the model reported that cable's length as the answer.
💡 Two more functions exist but are not given to the model.
traverse(follow a known chain of relationships) was bound until November 2026: given a path it had guessed, a weaker model got an empty result and reported "none", whilefind_connectedsearches the path itself. Removing it lost nothing on strong models and fixed more answers than it cost on weak ones.get_relatedis scaffolding from the removed sub-agent design. Both are still tested.
Ways to reach the agent¶
The same agent sits behind several entry points, and they differ in an important way.
| entry point | what it is | typical use |
|---|---|---|
python -m agent.cli |
command line, one-shot or interactive | quick questions, scripting |
langgraph dev |
LangGraph Studio (browser) and a REST API | watching each tool call; calling it from any language |
ui/app_chainlit.py |
a plain chat window (optional) | a worked example of embedding the agent |
python -m ui.mcp_server |
the agent as one MCP tool, ask_maat_inventory |
a chat host that also uses other MCP servers |
python -m ui.openai_api |
the agent as the model behind an OpenAI-compatible endpoint | a standalone inventory chat |
| embedded Python | ask_conversational() |
your own application |
Why serve the agent instead of pointing a chat UI at Maat's MCP server? Because the model would get the raw inventory API, with the per-category breakdown that is wrong above 10,000 objects and none of the 17 tools, the memory policy, the provenance labelling or the forced re-lookup. The agent is the thing worth integrating; the inventory API underneath it is not.
As an MCP tool, each call starts with an empty history — the host model owns the conversation —
so questions must be self-contained ("fiber type of cable-071", not "and its fiber type?"). There is
deliberately no way to pass context in: text written by the host model would become history the
agent trusts, and a value the host model invented would then read as "from an earlier lookup". The
result carries a provenance field (verified, unverified or no_lookup) that a careful host can
act on, and a timeout or failure comes back as a tool error, never as text a host model might
relay as inventory data.
⚠ The agent's guarantees stop at the answer it returns. Behind another chat model, that model can paraphrase the answer, drop the label, or add numbers of its own — and with a network-management tool in the same chat, act on an answer that was never verified. In testing it relayed the label and asked before acting, but that is the host's behaviour, not a guarantee. If acting only on verified data matters, enforce it where the change is made.
Per-user access. By default every entry point reads Maat as one identity. With MAAT_PER_USER=1
each question must carry the user's own Keycloak token — an Authorization header on the MCP tool
(LibreChat sends Bearer {{LIBRECHAT_OPENID_ACCESS_TOKEN}}), an X-Maat-User-Token header on the
OpenAI-compatible endpoint, the Chainlit sign-in, or a token file for the CLI. All of them run the
same check before anything else:
- the token is introspected at Keycloak on every question, never reused from an earlier one — a user who signs out is refused on the next question, and an unreachable Keycloak means refusal, not an unchecked answer;
- Maat is read with that token, so it applies the user's own roles and filters, and each user has a separate inventory cache;
- "not allowed" from Maat is reported as an error, and a genuine empty result is worded "none visible to you";
- a conversation can only be continued by the user who started it;
- when a user's own filter and the query restrict the same attribute, Maat applies the user's value instead of both, so the agent re-checks every returned object against what it asked for.
Tested end to end through LibreChat (as an MCP tool and as the model) and in Chainlit: a user whose filter allows only L2 circuits was told "0 networks visible to you", while a user without a filter got the real count. Setup and caveats are in Setup.
⚠ If you embed the Python directly, call
ask_conversational(), neverbuild_agent().ainvoke(). The raw engine answers questions, so it looks like it works — but it silently skips the memory policy and the provenance labelling, both of which live around the agent rather than inside it.
Conversations: memory and knowing where an answer came from¶
The agent supports back-and-forth conversation, not just single questions. Two mechanisms make that trustworthy.
Remembering earlier turns. The most recent exchange is kept in full, because follow-ups like "and how many fibres does it have?" depend on it. Older exchanges are reduced to question-and-answer pairs, and beyond a limit they are summarised rather than deleted — keeping a note that earlier turns exist, any standing instruction the user gave, and a compact record of what was asked and answered. In practice a specific fact stays available for around 50 turns; after that the agent notices it is no longer in view and looks it up again, at a cost in time rather than correctness.
Labelling where each answer came from. Every answer carries a provenance label:
| label | meaning |
|---|---|
| verified | the agent queried Maat on this turn |
| from an earlier lookup | the value came from earlier in this conversation — shown with the time of the most recent lookup in the conversation, which is not necessarily the lookup the value came from |
| not verified | the value appears nowhere and was not looked up — shown as a warning |
Where the label is shown depends on the interface: LangGraph Studio stamps every verified answer with the time of the lookup; the command line, Chainlit and the OpenAI-compatible endpoint add a note only when an answer is recalled or unverified, so an answer with no note was looked up. Through an OpenAI-compatible chat client, which stores the conversation as plain text, a recalled value keeps its label but loses that time.
⚠ Why this matters: in a long or repetitive conversation a model can answer from the pattern of its own earlier replies instead of querying, producing a well-formatted value that was never checked. The user cannot see which functions were called, so without a label a fabricated figure and a verified one look identical. The label is stored as hidden metadata, not as text in the answer — anything visible in the conversation is something the model can also reproduce, including a label, so the metadata (not the prose) is the record that is trusted.
When an answer states a value that came from no lookup, the agent asks the question a second time, forcing a fresh lookup, and keeps the second answer if it genuinely checked. This exists because the failure behaves like a latch rather than a slip: once a model starts producing values from the pattern of its own replies, nothing in its context contradicts it, and it tends to keep going. One retry only — if the second attempt is also unverified, the first answer is kept with its warning, so the behaviour is never worse than without the retry and the cost has a ceiling.
A separate, independent check reads every answer for values that are not in Maat's vocabulary at all (for example, a route type the inventory has never recorded). This is the only check that catches a misreport made with a real lookup, and it needs no conversation history to work.
Safety limits¶
| limit | value | what it prevents |
|---|---|---|
| tokens per question | 400,000 | a question that spirals is stopped with a clear message instead of consuming the whole run |
| reasoning steps | 120 | bounds how long the agent can loop on one question |
| model call timeout | 180 s | a hung endpoint does not stall everything |
| temperature | 0 | answers as repeatable as the endpoint allows (token use still varies from run to run) |
The same limits apply in testing and in every live interface, so behaviour under test matches behaviour in use. They are read from environment variables by every entry point — they were once set differently for the tests and the UIs, which meant a question could pass the suite and fail in production.
Testing and benchmarking¶
Every question run through the system records how many tokens it used, how many model calls it made, and which functions were actually invoked — the record that makes it possible to check whether an answer was genuinely looked up. Three rules keep infrastructure problems from being mistaken for poor model performance: a question that never reached the model (endpoint down) is marked not measured, not scored zero; a question the endpoint rejected leaves the denominator rather than counting as wrong; and a run with more than 10% timeouts is flagged degraded, since a congested endpoint produces a low score that looks exactly like a weak model.
Five test suites (plus the no-LLM tool tests):
| suite | size | what it measures |
|---|---|---|
| randomized regression | 130 questions (4 are guardrails) | correctness across every object type |
| stress | 108 questions | capability — can it answer at all, one question at a time |
| coverage | 201 questions | reach — one question per attribute and relationship type found in the data |
| conversation | 24 conversations, 243 turns (the published results use a standard set of 22 conversations and 137 turns) | memory — does the answer survive being asked in context |
| provenance | 11 turns per model | integrity — does the label match what actually happened |
Questions are written as the work of specific personas — a network engineer, a service manager, a customer-support desk, a data steward, a capacity planner, a new joiner — so the suite covers real usage shapes rather than an even spread of API calls. The stress suite also has a group of 23 questions that only the current data model can answer: attributes on relationships, routing-policy entries, site classification, AS-sets. The suites read which data model is loaded from the data itself, and each checks its exact question count before asking anything, so a question can never silently drop out.
About 300 tool tests (no model calls, no cost) separate "the tools are broken" from "the model
is behaving badly" before any expensive benchmark starts. Every run is archived under
results/runs/, one create-only file per run named by start time, model, engine and data model — so
an earlier result can never be overwritten, and any two runs can be compared or shown to be
incomparable.
Comparing against plain MCP. The stress, randomized and coverage suites can also run without
the agent, with only the MCP server's own four tools: MAAT_ENGINE=raw_b1 adds the server's
maat-guide prompt, MAAT_ENGINE=raw_b0 adds nothing. Same questions, same expected answers, same
limits — so the scores compare directly, and python -m agent.crossmodel_report builds the
cross-model table from stored runs.
How answers are checked — the oracle¶
Every expected answer is computed independently of the agent, at the moment the test runs, by walking the raw inventory directly — the agent's own functions are never used to produce the correct answer, because if the traversal logic were wrong in the same way in both places, the test would still pass. Expected values are never typed in advance (a stale literal fails a question the agent answered correctly the moment the inventory changes), and an expected answer must not be quotable from the question itself, or a model could pass by echoing the prompt. Where a name belongs to several objects, the expected answer is the list of candidates and a question back.
💡 Known weaknesses, stated plainly: the oracle can itself be wrong (a question with several correct answers where the checker accepts only one); an ambiguous question can look exactly like a model error; the inventory does not change during a test run, so the "freshness" label shown to users is not exercised end to end by these suites; and every question is written by the project team rather than collected from real operators — the largest open gap in the evaluation.
Results¶
On MCP 1.0.5 (October–November 2026)¶
Thirteen models on the stress, randomized and coverage suites, against Maat MCP server 1.0.5 and the 24,455-object dataset. Each model's newest full run is shown; the last column is the same 108 hard questions answered by the same model with plain MCP and the server's guide prompt, no agent.
| Model | Stress (108) | Randomized (126) | Coverage (201) | Stress, plain MCP |
|---|---|---|---|---|
| GLM-5.1 (default) | 108 | 126 | 201 | 67 |
| Qwen3.8-27B | 108 | 126 | 201 | 75 |
| DeepSeek-V4-Flash | 107 | 126 | 201 | 74 |
| GLM-5.3-Flash | 106 | 126 | 201 | 75 |
| Qwen3.5-397B-A17B | 107 | 126 | 199 | 68 |
| MiMo-V2.5 | 107 | 126 | 199 | 8 ¹ |
| GLM-5.2 | 105 | 126 | 199 | 61 |
| MiniMax-M2.5 | 107 | 126 | 196 | 70 |
| gpt-oss_120b | 106 | 125 | 196 | 52 |
| DeepSeek-V3.1 | 105 | 126 | 195 | 59 |
| gemma-4-26B-A4B-it | 103 | 125 | 197 | 45 |
| Qwen3-VL-235B-A22B-Instruct-FP8 | 93 | 125 | 193 | 56 |
| Mistral-Small-3.2:24b | 83 | 118 | 187 | 34 |
¹ MiMo cannot drive the MCP server directly: it sends its filters as a JSON string and the server rejects every call. Through the agent it does fine.
Randomized is out of 126 because the 4 guardrail questions are scored apart. The agent runs span builds a few days apart (Mistral on the newest, GLM-5.1 and gemma-4 on the one before, the others earlier); the changes in between moved scores by at most a few questions per suite.
Cost. On simple questions plain MCP is 13–33% cheaper per question (median). On hard questions it is far dearer, because it pages through the inventory in the model's context while the agent's tools do that pass in Python (pooled over the 12 models whose runs were stored by 4 November):
| Suite | Engine | Tokens per correct answer |
|---|---|---|
| Stress | agent | 40,275 |
| Stress | MCP + guide / MCP only | 254,038 / 273,351 |
| Randomized | agent | 34,457 |
| Randomized | MCP + guide / MCP only | 37,542 / 32,728 |
| Coverage | agent | 32,678 |
| Coverage | MCP + guide / MCP only | 36,134 / 37,414 |
The agent also helps weak models most: with plain MCP, Mistral-Small-3.2:24b answers 34 of the 108
hard questions with the server's guide prompt and 21 without it; with the agent, 83.
Conversation results (November 2026, MCP 1.0.5)¶
Thirteen models on the standard conversation set (22 conversations, 137 turns), sorted by conversational accuracy, the number to choose a chat model on:
| Model | Stress (108) | Conversation | Invented |
|---|---|---|---|
| DeepSeek-V3.1 | 105 | 100.0% | 0.9% |
| GLM-5.3-Flash | 106 | 100.0% | 0.0% |
| gemma-4-26B-A4B-it | 103 | 100.0% | 0.0% |
| Qwen3.5-397B-A17B | 107 | 100.0% | 0.0% |
| MiniMax-M2.5 | 107 | 100.0% | 0.0% |
| GLM-5.1 | 108 | 99.3% | 0.0% |
| GLM-5.2 | 105 | 99.3% | 0.0% |
| DeepSeek-V4-Flash | 107 | 99.3% | 0.0% |
| gpt-oss_120b | 106 | 99.2% | 0.0% |
| Qwen3.8-27B | 108 | 98.5% | 0.0% |
| MiMo-V2.5 | 107 | 97.1% | 0.0% |
| Qwen3-VL-235B-A22B-Instruct-FP8 | 93 | 97.0% | 0.9% |
| Mistral-Small-3.2:24b | 83 | 90.5% | 6.5% |
The standard set leaves out the 84-turn long-range-recall conversation and the memory-limit probe, which are slow and are run on their own. One run of the standard set costs about 4.3 million tokens per model and 10–45 minutes on a responsive endpoint. Most remaining misses are single turns, and some are strict grading: three models lose the same turn with a correct answer that also repeats the previous turn's site, which that turn forbids; GLM-5.1's one miss is an arithmetic slip (495 + 489 written as 1,984). Provenance labelling was checked on 1.0.5 with GLM-5.1: 11 of 11 turns were labelled correctly.
"Invented" is the fabrication rate: the share of turns needing a lookup that produced an answer with no lookup behind it (a floor: the detector misses about a fifth of cases). Conversation is a rate because denominators differ: turns a model cannot answer even when asked directly are excluded. See Lessons Learnt for why this number, not the capability score, should drive model choice for a chat deployment.