Skip to content

Agentic Inventory Q&A for Maat — Environment Setup

The whole stack — Maat, its database, the MCP server, and the agent itself — runs locally from Docker Compose and a Python virtual environment, so a fresh evaluation environment can be created from scratch. Alternatively, the agent can be pointed at an existing Maat deployment by changing one setting, or added as one more container to a system where Maat and a chat UI already run.

Environment

service address role
🗄 Maat API http://127.0.0.1:8080 the inventory itself (TMF638/TMF639)
🍃 MongoDB :27017 (internal) Maat's database
🔌 Maat MCP server 1.0.5 http://127.0.0.1:8002/mcp the only interface the agent uses
⚙ schema server (nginx) internal serves the TMF schemas locally, so Maat validates POSTs without reaching out over the network
🤖 agent as an MCP tool (optional) http://127.0.0.1:8011/mcp the agent offered to a chat host as a single tool
💬 agent as a model (optional) http://127.0.0.1:8010/v1 the agent behind an OpenAI-compatible endpoint

Minimum prerequisites

  • Docker + Docker Compose. Allow about 16 GB for Docker: Maat alone is capped at 12 GB, and loading the full dataset peaks near 10 GB. The Maat images are linux/amd64; on Apple silicon they run emulated, which works but is slower.
  • Python 3.11 or newer and a virtual environment — the agent framework (deepagents) has no release for 3.10. The published results were produced on 3.11.
  • An OpenAI-compatible LLM endpoint and API token (any provider works — the agent is not tuned to one model). A typical question costs 30,000–40,000 tokens; a blast-radius question can cost more.

Images — public, no login needed

Both Maat images are hosted on the GÉANT artifactory and are publicly pullable; mongo is public too. docker login is only needed if your network blocks anonymous pulls.

  • artifactory.software.geant.org/spa-docker/maat:1.0.16
  • artifactory.software.geant.org/spa-docker/maat-mcp-server:1.0.5

The agent's client detects which call signature the server uses, so it also works with MCP server 1.0.2 — but all results in this documentation were measured on 1.0.5, which is what the bundled stack runs.

💡 The MCP server reads its data-model documentation at startup. Version 1.0.5 pulls the community data-model docs from a remote repository, and the bundled compose file pins them to the commit the test dataset follows (MAAT_DOCS_ENABLED=true, MAAT_DOCS_REF=c9df169…) so the tool descriptions cannot change in the middle of a benchmark. If that repository is unreachable, the server silently falls back to a documentation snapshot bundled in the image — which describes the older data model. After every restart, check the server's startup log for the docs source.

Bring up the stack

git clone https://bitbucket.software.geant.org/scm/gplor/maat-ai-agent.git
cd maat-ai-agent
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt -c constraints.txt

constraints.txt pins every package to the version the published results were measured with; without it pip installs whatever is newest that day.

cp deploy/.env.example deploy/.env       # REQUIRED first: the stack reads its settings from deploy/.env
cd deploy && docker compose up -d        # maat + mongo + mcp + schema-server
docker compose ps                        # wait until all are healthy (Maat takes a minute or two)

⚠ Do not skip deploy/.env. Without it every variable in the compose file is blank: MongoDB starts with no credentials and Maat cannot find its database.

💡 Memory note: Maat's mem_limit is set to 12g. A full-scale data load peaks near 9.8 GiB — at 10g the JVM has been observed to shut itself down mid-load and silently restart, which can duplicate objects without logging an error. Always compare the stored object count against what the loader reports after a large seed.

Verify Maat is answering before doing anything else (an empty list [] is success — there is just no data loaded yet):

curl http://127.0.0.1:8080/resourceInventoryManagement/v4.0.0/resource
curl http://127.0.0.1:8080/serviceInventoryManagement/v4.0.0/service
# Swagger UI: http://localhost:8080

Seed a test inventory

There are two seeders, and which one you run determines whether the rest of the project's examples and test suites work:

# (a) FULL dataset — what the agent, benchmarks and every documented example assume.
#     24,455 objects in 45 categories, following the current community data model, with the
#     cross-layer optical stack and deliberate spare capacity so capacity/absence questions
#     have real answers.
SEED_MODEL=upstream SCALE=500 SEED=42 python -m seed.seed_full

# (b) SMALL topology — a few hundred objects, useful for a quick look at the object shapes only.
python seed/seed_maat.py      # idempotent

Pass all three variables explicitly. The default SCALE is a small validation dataset, and the published benchmark figures were measured on SEED_MODEL=upstream SCALE=500 SEED=42. The generator is deterministic — the same three values reproduce the same inventory object for object — which is why the dataset ships as a script rather than a dump.

Confirm your instance matches the one the numbers came from — this compares the live inventory against every category in seed/MANIFEST.md and exits non-zero on any difference:

SEED_MODEL=upstream python -m seed.verify_seed

A partial or interrupted seed has a recognisable shape — the right categories with low counts — and this is what catches it. The published figures only apply to an instance that matches.

If you change the seed generator itself, python -m seed.dry_hash runs it without contacting Maat and prints a fingerprint of every object it would write, in order; compare it with the fingerprints in seed/MANIFEST.md (for SEED_MODEL=upstream SCALE=500 SEED=42 it lists 24,455 payloads).

⚠ Seeding order matters. Parents must be created before children so each child can carry its parent reference at creation time — reversing it produces orphaned objects that look like a data-quality finding but are a seeding artefact. Do not reseed while a benchmark is running: expected answers are derived live from the current data, so a reseed invalidates any run in flight.

Fast reseed, once the stack is already up: wipe the database directly instead of deleting through the API (which is roughly 160 ms per object), then seed with the delete step skipped:

docker exec <mongo-container> mongosh -u admin -p <password> --quiet --eval \
 'db.getSiblingDB("resources_db").resources.deleteMany({}); db.getSiblingDB("services_db").services.deleteMany({})'

PYTHONUNBUFFERED=1 CLEAR=0 SEED_MODEL=upstream SCALE=500 SEED=42 python -m seed.seed_full

At SCALE=500 a full seed takes roughly 10 minutes.

Credentials / environment

Copy the example env file and fill in your LLM endpoint and token — .env is gitignored and must never be committed:

cp .env.example .env
MAAT_MCP_URL=http://127.0.0.1:8002/mcp

MAAT_LLM_BASE_URL=<your OpenAI-compatible endpoint>/v1
MAAT_LLM_API_KEY=<your-token>
MAAT_LLM_MODEL=<model-id>              # exact casing matters; list with GET <base_url>/models
MAAT_LLM_TLS_VERIFY=1                  # set 0 only for a self-signed endpoint

LLM Model — Bring Your Own

⚠ The agent needs an OpenAI-compatible LLM endpoint. Any provider works — MAAT_LLM_MODEL is a single setting — but development and all thirteen-model benchmarking in this project used the PSNC/PCSS HPC inference gateway.

🙏 Special thank you to PCSS for generously granting access to their GPU infrastructure and hosting the models used throughout this work. Without their support, these experiments would not have been possible.

Model recommendation from this testing. GLM-5.1 is the default and answered every question in all three suites. Qwen3.8-27B, DeepSeek-V4-Flash and GLM-5.3-Flash are within two questions of it and make good fallbacks. Mistral-Small-3.2:24b (83/108 on the hard questions) and Qwen3-VL-235B (93/108) are not recommended for operational use without a human check. The full 13-model table is in Process → Results.

Optional safety/performance knobs (sensible defaults shown — see Process for what each one protects against):

variable default purpose
MAAT_LLM_MAX_TOKENS 16000 maximum tokens in one model completion
MAAT_MAX_QUESTION_TOKENS 400000 hard per-question cost ceiling
MAAT_RECURSION_LIMIT 120 maximum reasoning steps per question
MAAT_INV_TTL 900 whole-inventory aggregation-cache TTL (seconds); 0 disables caching
MAAT_FETCH_CONCURRENCY 6 concurrent MCP fetches per traversal wave
MAAT_LLM_TIMEOUT 180 per-LLM-call timeout (seconds)

For per-user permissions see Per-user access.

⚠ Do not raise MAAT_FETCH_CONCURRENCY casually. Higher concurrency has OOM-killed Maat during whole-inventory reads in testing; a degraded backend makes the agent improvise, which is the root cause behind most of the runaway questions documented in Lessons Learnt.

Check that the tools work

Before spending a single LLM token, run the tool tests. They run against your live Maat with no model in the loop — which cleanly separates "the tools are broken" from "the model is misbehaving". There are about 300 checks, and they take several minutes because they read the whole inventory:

python -m agent.test_tools_live

Check a candidate model before benchmarking it

A full benchmark run is millions of tokens and hours of wall-clock time; most incompatible models fail on something basic long before correctness matters. Screen a candidate against the agent's real 17-tool schema first:

python -m agent.probe_models          # -> results/model_probe.json

The probe checks four things: the model emits a tool call, it routes a reverse lookup correctly, it passes dict-shaped arguments, and it survives a realistic (~60k-token) prompt. Passing the probe does not guarantee a good score on the real suites — but failing it reliably predicts a bad one. The candidates it tries are listed in agent/models.txt; edit that file to match your endpoint.

Run the agent

# Interactive REPL (conversational; keeps history)
python -m agent.cli

# One-shot (stateless)
python -m agent.cli "what's the blast radius if router r-001 fails?"

Other chat surfaces:

  • LangGraph Studio — langgraph dev (needs no extra install; config in langgraph.json). A browser UI that shows each tool call as the agent makes it — the best way to understand what the agent did.
  • Chainlit UI (ui/) — optional; install with pip install chainlit first (it is commented out of requirements.txt by default), then chainlit run ui/app_chainlit.py.

All of them are conversational and carry the same memory and provenance behaviour described in Process.

Run the test suites (optional)

Each suite asks the agent questions and compares its answers with expected answers computed from the live inventory, so run them only against the seeded dataset above. They cost LLM tokens — a full stress run is about 4 million tokens, a randomized run about 4.5 million, coverage about 6.5 million and the standard conversation set about 4.3 million — and take 10–45 minutes each on a responsive endpoint.

python -m agent.regression_stress                         # 108 hard single questions
python -m agent.regression_random                         # 126 randomized questions (+4 guardrails)
MAAT_PART=coverage python -m agent.regression_random      # 201 coverage questions
./agent/run_conversation.sh GLM-5.1                       # the standard conversation set, one or more models
python -m agent.test_provenance                           # does the provenance label match what happened
MAAT_ONLY=S1,CAP3 python -m agent.regression_stress       # just the named questions

Set MAAT_ENGINE=raw_b1 (or raw_b0) to run the same questions with plain MCP and no agent, and build the cross-model comparison with python -m agent.crossmodel_report. Every run is archived under results/runs/. What each suite measures is in Process.

Serve it to a chat UI (LibreChat and others)

The agent is not tied to the bundled interfaces. It can be served in two shapes — choose by who should be talking to the user:

A. MCP tool (recommended) B. The agent as the model
Who answers the user your chat model, which calls the agent when needed the agent itself
Combine with other MCP servers (e.g. network management) yes no
Conversation memory the chat model's the agent's
Start python -m ui.mcp_server — :8011/mcp python -m ui.openai_api — :8010/v1

Both work with any client that speaks the protocol; LibreChat is the worked example, tested end to end (deploy/librechat.example.yaml holds both configurations). Shape A exposes one tool, ask_maat_inventory(question); shape B also serves a small test page at http://127.0.0.1:8010/.

⚠ Neither endpoint has authentication, and both spend your LLM token. Run from Python, they listen on 127.0.0.1 only. Docker Desktop (macOS, Windows) lets a container reach a loopback-only server through host.docker.internal; on Linux, set MAAT_AGENT_MCP_HOST / MAAT_API_HOST to 0.0.0.0 and firewall the port, or use the container below. To expose either further, put your own authentication in front. (Per-user mode, below, checks a token on each question but does not protect the endpoints themselves.)

In a container

The agent has its own image (pinned to the tested dependency versions) and its own compose file, deploy/docker-compose.agent.yml. It is built to be added to a system that is already running — Maat, its MCP server, LibreChat — and starts nothing else. It joins two existing Docker networks: the one the Maat MCP server is on, and the one the chat host is on.

cp .env.example .env                     # the container reads the project-root .env
docker inspect <maat-mcp-container> LibreChat --format '{{.Name}}: {{range $k,$v := .NetworkSettings.Networks}}{{$k}} {{end}}'

cd deploy && MAAT_NETWORK=<maat-network> CHAT_NETWORK=<librechat-network> \
    docker compose -f docker-compose.agent.yml up -d --build

Add --profile openai before up to also start shape B on :8010. Then check that the agent can reach both Maat and the LLM, before touching LibreChat ("healthy" in docker ps only means the server is up):

docker exec maat-agent-maat-agent-1 python -m agent.cli "How many routers are there?"

(That is Compose's default container name; use the one docker ps shows if yours differs.)

Finally point LibreChat at http://maat-agent:8011/mcp. The token stays out of the image: .env is excluded from the build and read at run time.

Per-user access (optional)

By default every user of the agent sees the same inventory. If Maat gives users different views (Keycloak roles and access filters), set MAAT_PER_USER=1. Each question must then carry the asking user's own Keycloak token. Before anything else on every question, the agent asks Keycloak online whether the token is still active and was issued for Maat; a missing, expired or signed-out token, or an unreachable Keycloak, means the question is refused. Maat is then read as that user, each user gets a separate inventory cache, and an empty result is worded "none visible to you".

What it needs:

  • Maat with Keycloak on, and the Maat MCP server without its own Keycloak client credentials, so it passes each caller's token through instead of using its own identity.
  • LibreChat signing users in through the same Keycloak realm with OPENID_REUSE_TOKENS=true, and shared links switched off (ALLOW_SHARED_LINKS=false): anyone who opens a shared conversation sees its answers, whatever their own permissions.
  • The access-filter mapper on every Keycloak client that signs agent users in. Maat treats a token without the filter claim as "may see everything", and the agent cannot detect that.
  • A token lifetime longer than Keycloak's default 5 minutes, which can run out during a long question.
  • A confidential Keycloak client the agent uses to check tokens. Its settings are in .env.example (issuer, introspection URL, client id and secret, and MAAT_KC_AUDIENCE, the client that holds Maat's roles); without them the agent refuses to start.

Passing the token. For the agent as an MCP tool, add the header Authorization: "Bearer {{LIBRECHAT_OPENID_ACCESS_TOKEN}}" to the maat entry in librechat.yaml. For the agent as the model, use X-Maat-User-Token with the same value and X-Conversation-ID: "{{LIBRECHAT_BODY_CONVERSATIONID}}" instead, because the endpoint's own Authorization header carries its API key. Both are in the commented-out sections of deploy/librechat.example.yaml. The command line, Chainlit and the REST API take the token differently; the repository's OPERATIONS.md describes each. LangGraph Studio sends no token, so in per-user mode its questions are refused.

⚠ Tested end to end on a Keycloak test set-up through LibreChat (both ways of serving the agent) and Chainlit, with the agent run from Python rather than in its container. The other surfaces run the same check but were not tested end to end.

Troubleshooting

🙏 pull access denied / unauthorized — the images are public; if your network blocks anonymous pulls, docker login artifactory.software.geant.org with your GÉANT credentials (and VPN, if required).

🙏 No matching distribution found for deepagents — Python is older than 3.11.

🙏 Maat will not start, or the logs show blank MongoDB settings — deploy/.env is missing; copy it from deploy/.env.example.

🙏 MCP can't reach Maat — confirm Maat answers on :8080 directly, then check the MCP container's MAAT_BASE_URL. On Linux, host.docker.internal needs an explicit extra_hosts: host.docker.internal:host-gateway entry in the compose file; Docker Desktop on macOS resolves it automatically.

🙏 MaatUnavailable: cannot reach the Maat MCP server — the MCP container is not running or still starting, or MAAT_MCP_URL is wrong. This is raised deliberately: an outage must never look like an empty inventory.

🙏 Empty query results — no data has been loaded yet (see Seed a test inventory above), not a bug.

🙏 The agent answers, but every value looks wrong — run SEED_MODEL=upstream python -m seed.verify_seed; a different SEED_MODEL, SCALE or SEED produces a different inventory.

🙏 AuthenticationError: 401 — .env still has the placeholder MAAT_LLM_API_KEY. The tool tests pass without a token; only the agent itself needs one.

🙏 LibreChat gets HTTP 421 from the agent — the server rejects unknown Host names as DNS-rebinding protection. Other containers must call it maat-agent; add any other name to MAAT_AGENT_MCP_ALLOWED_HOSTS. If LibreChat says Domain ... is not allowed, add the agent's address to mcpSettings.allowedAddresses — it blocks private addresses by default.

🙏 MCP returns 401/403 — Maat has authentication enabled; the setup described here assumes Maat is running without it (matching the lean MCP server config, which omits all KEYCLOAK_* settings). In per-user mode it means Maat refused the user's own token: the agent reports it as a credentials error, never as an empty result.

🙏 Per-user mode refuses a question — "could not be verified": no token reached the agent (check the header in librechat.yaml) or it expired; "could not be checked right now": Keycloak is unreachable or the agent's client id or secret is wrong; "not issued for Maat": MAAT_KC_AUDIENCE is wrong. A filtered user who sees everything means their Keycloak client lacks the access-filter mapper.

Using an existing Maat instance

⚠️ Every user sees the same inventory by default. If your Maat enforces Keycloak roles or filters, switch on per-user access.

The agent never touches Maat's REST API directly — every read goes through the MCP server. Pointing it at an already-running deployment is therefore a single setting, MAAT_MCP_URL; the bundled stack and seeders above are only needed to build an evaluation environment from scratch. Two things write to Maat, and neither is the agent: the seeder (seed/seed_full.py) and the optional staleness test (agent/test_staleness.py, which only prints its plan unless MAAT_STALENESS_APPLY=1). Both need MAAT_BASE (the REST endpoint) and are the only components that do.