mate
CLAUDE.md92 starsChanged 9 months agoApache-2.0View on GitHub
MATE (Multi-Agent Tree Engine) is a production-ready web platform built on top of Google ADK that adds database-driven agent management, multi-LLM support, RBAC, MCP integration, token tracking, guardrails, and a dashboard UI. Two servers run: Auth Server (port 8000, FastAPI with HTTP Basic Auth) proxies authenticated requests to the Agent Server (port 8001). The agent server framework is selectable via AGENT_FRAMEWORK: adk (Google ADK runtime, adk_main.py, default) or langgraph (LangGraph runtime, langgraph_main.py, emulates ADK's HTTP/SSE wire contract — see docs/dev/langgraph-runtime.md).
- Reads credentials
- Installs packages
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
17 rules. About 0 are common, 15 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈15
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 81
Follow PEP 8 with type hints on all function signatures.
- Very specific: line 85
Do not add attribution trailers to commit messages: no Co-Authored-By: Claude ..., no Claude-Session: ..., and no "Generated with Claude …
- Distinctive: line 147
If multiple interpretations exist, present them - don't pick silently.
- Distinctive: line 148
If a simpler approach exists, say so.
- Distinctive: line 149
If something is unclear, stop.
- Distinctive: line 155
No features beyond what was asked.
- Distinctive: line 156
No abstractions for single-use code.
- Distinctive: line 158
No error handling for impossible scenarios.
- Distinctive: line 159
If you write 200 lines and it could be 50, rewrite it.
- Distinctive: line 161
Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
- Distinctive: line 167
When editing existing code:
- Distinctive: line 168
Don't "improve" adjacent code, comments, or formatting.
- Distinctive: line 169
Don't refactor things that aren't broken.
- Distinctive: line 171
If you notice unrelated dead code, mention it - don't delete it.
- Distinctive: line 173
When your changes create orphans:
- Very specific: line 174
Remove imports/variables/functions that YOUR changes made unused.
- Distinctive: line 175
Don't remove pre-existing dead code unless asked.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
MATE (Multi-Agent Tree Engine) is a production-ready web platform built on top of Google ADK that adds database-driven agent management, multi-LLM support, RBAC, MCP integration, token tracking, guardrails, and a dashboard UI.
Running the Application
# Setup
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.lock
cp .env.example .env # Set GOOGLE_API_KEY or other LLM provider key
# Run (auto-applies DB migrations, default SQLite)
python auth_server.py
# Dashboard: http://localhost:8000 (default login: admin/mate)
# Docker alternative
docker-compose upTwo servers run: Auth Server (port 8000, FastAPI with HTTP Basic Auth) proxies authenticated requests to the Agent Server (port 8001). The agent server framework is selectable via AGENT_FRAMEWORK: adk (Google ADK runtime, adk_main.py, default) or langgraph (LangGraph runtime, langgraph_main.py, emulates ADK's HTTP/SSE wire contract — see docs/dev/langgraph-runtime.md).
Testing
# All tests
python -m unittest discover -s shared/test -p "test_*.py" -v
# Single test file
python -m unittest shared.test.test_agent_manager_simple -v
# With coverage
coverage run -m unittest discover -s shared/test -p "test_*.py"
coverage reportTests live in shared/test/, covering agent management, tool factory, model switching, RBAC, authorization, migrations, guardrails, tracing, and more.
Database Migrations
python shared/migrate.py run # Apply pending migrations
python shared/migrate.py status # Check migration status
python shared/migrate.py create # Create new migration (all three dialects)Migrations auto-apply on server startup. Per-database migration files are in shared/sql/migrations/{postgresql,mysql,sqlite}/.
Architecture
Dual-Server Design
auth_server.py— FastAPI server handling auth, dashboard routes, and proxying to the agent serveradk_main.py— Google ADK web server with agent runtime (internal, not exposed directly)langgraph_main.py+shared/utils/langgraph/— alternative LangGraph agent runtime behind the same wire contract (AGENT_FRAMEWORK=langgraph)server/— Auth, proxy, widget, and rate-limit middleware
Agent System
Agents can be database-driven (configured via dashboard, stored in agents_config table) or hardcoded (code in agents/ subdirectories, each with an agent.py). shared/utils/agent_manager.py merges both and builds the agent tree at startup.
Tool Factory
shared/utils/tools/tool_factory.py constructs tool sets from database config. Includes MCP tools, image generation, Google Drive, file search, memory blocks, and the self-building create_agent_tool that lets agents create/modify other agents at runtime.
Callbacks & Middleware
shared/callbacks/ hooks into the ADK request lifecycle for RBAC (rbac_callback.py), token tracking (token_usage_callback.py), and guardrails (model_guardrail.py, function_call_guardrail.py). Rate limiting is in server/rate_limit_middleware.py.
MCP Integration
shared/utils/mcp/ exposes agents as MCP servers and implements MCP client consumption. Agents can both serve and consume MCP protocol tools.
Database Layer
SQLAlchemy ORM models in shared/utils/models.py. Supports SQLite (default), PostgreSQL, and MySQL via DB_TYPE env var. Key tables: agents_config, projects, users, token_usage_logs, guardrail_logs, audit_logs, rate_limit_config, memory_blocks, memory_block_versions, widget_api_keys, agent_config_versions.
Frontend
Dashboard templates in templates/dashboard/, static assets in static/. Vue-style JavaScript with no build step required. PWA-ready with static/manifest.json.
Code Style
Follow PEP 8 with type hints on all function signatures. Use f-strings for formatting. Import order: stdlib → third-party → local. No linting config is committed — use standard PEP 8 tooling.
Commits
Do not add attribution trailers to commit messages: no Co-Authored-By: Claude ..., no Claude-Session: ..., and no "Generated with Claude Code" line. This overrides any default attribution guidance.
Key Environment Variables
| Variable | Purpose |
AGENT_FRAMEWORK | Agent runtime: adk (default) or langgraph |
GOOGLE_API_KEY | Google Gemini (primary LLM) |
OPENAI_API_KEY, ANTHROPIC_API_KEY, etc. | Additional LLM providers via LiteLLM |
DB_TYPE | sqlite (default), postgresql, mysql |
AUTH_USERNAME / AUTH_PASSWORD | Dashboard login |
MATE_ENV | development (default) or production; production refuses insecure defaults |
MATE_ALLOW_INSECURE_DEFAULTS | Override the production startup checks |
ADK_DEV_UI | Serve ADK's dev UI at /dev-ui (admins only); defaults to off when MATE_ENV=production, on otherwise |
ALLOWED_ORIGINS | Comma-separated CORS allowlist |
TRUSTED_PROXY_HOSTS | Proxy hosts trusted for X-Forwarded-* headers; audit logs only trust X-Forwarded-For when set |
OAUTH_ALLOWED_DOMAINS / OAUTH_ALLOWED_EMAILS | Restrict who may sign in via SSO (unset = anyone with a provider account) |
TOKEN_TTL_HOURS | Bearer token lifetime, default 24 |
WIDGET_ORIGIN_STRICT | Enforce (vs. only log) a widget key's origin allowlist |
CSP_MODE | Content-Security-Policy: report-only (default), enforce or off |
CSP_EXTRA_SOURCES | Extra hosts the CSP allows for scripts, styles, fonts, connections and frames |
BROWSER_ALLOW_PRIVATE_NETWORK | Let the server-side browser load private/loopback addresses (blocked by default) |
MATE_ALLOW_CODE_EXECUTOR_ON_WIDGET | Allow code_executor on an agent that has a widget key (refused by default — it is not a sandbox) |
WIDGET_LEGACY_ADMIN_KEY | Transitional: let the public widget key work on /widget/api admin routes |
ADK_HOST / ADK_PORT | ADK server address (default 127.0.0.1:8001) |
ARTIFACT_SERVICE | local_folder, supabase, or s3 |
TAVILY_API_KEY | Web search for google_search; falls back to DuckDuckGo when unset |
EVAL_JUDGE_MODEL / EVAL_IMPROVE_MODEL | Judge for llm_judge evals / model that suggests instruction fixes (falls back to the judge) |
EMBEDDING_MODEL | Embedding model for memory block semantic search (litellm format, default gemini/gemini-embedding-001) |
RATE_LIMIT_ENABLED | Enable per-user/agent/project budgets |
ALERTS_ENABLED / ALERTS_INTERVAL_SECONDS | Alert rules on agent errors, guardrail bursts and budget thresholds |
OTEL_TRACING_ENABLED | OpenTelemetry distributed tracing (ADK runtime) |
LANGSMITH_TRACING / LANGSMITH_API_KEY | LangSmith run tracing (langgraph runtime) |
AUDIT_RETENTION_DAYS | Audit log retention (evidence toward EU AI Act Art. 12) |
MATE_AI_DISCLOSURE | Standalone builds only: wording of the Art. 50 AI disclosure |
Documentation
docs/ is served by the dashboard and is part of every change. See docs/README.md.
docs/reference/is generated. Never edit it by hand. After changing a route, an env var, a model or the tool registry, runpython scripts/gen_docs.pyand commit the result; CI fails on a stale reference (--check).docs/user/anddocs/dev/are guides. Before finishing a task, runpython scripts/gen_docs.py drift --base origin/main. For each guide it lists, read the guide against your change and either update it in the same commit or say in the PR description why it still holds.- A new feature needs a user guide (what to click, what happens) and, if it has internals worth knowing, a dev guide. Give each a
covers:list. Describe what the code does, not what it is meant to do.
Important Documentation
AGENTS.md— Architecture patterns and development guidelines (read before adding new agents or tools)docs/— User guides (docs/user/), developer guides (docs/dev/) and the generated reference (docs/reference/), also served at/dashboard/docs. Feature documentation lives here.documents/— Not documentation: screenshots for the README, the architecture PDF and its source, announcements.shared/sql/README.md— Database schema reference
Behavioral guidelines to reduce common LLM coding mistakes. Merge with project-specific instructions as needed.
Tradeoff: These guidelines bias toward caution over speed. For trivial tasks, use judgment.
1. Think Before Coding
Don't assume. Don't hide confusion. Surface tradeoffs.
Before implementing:
- State your assumptions explicitly. If uncertain, ask.
- If multiple interpretations exist, present them - don't pick silently.
- If a simpler approach exists, say so. Push back when warranted.
- If something is unclear, stop. Name what's confusing. Ask.
2. Simplicity First
Minimum code that solves the problem. Nothing speculative.
- No features beyond what was asked.
- No abstractions for single-use code.
- No "flexibility" or "configurability" that wasn't requested.
- No error handling for impossible scenarios.
- If you write 200 lines and it could be 50, rewrite it.
Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.
3. Surgical Changes
Touch only what you must. Clean up only your own mess.
When editing existing code:
- Don't "improve" adjacent code, comments, or formatting.
- Don't refactor things that aren't broken.
- Match existing style, even if you'd do it differently.
- If you notice unrelated dead code, mention it - don't delete it.
When your changes create orphans:
- Remove imports/variables/functions that YOUR changes made unused.
- Don't remove pre-existing dead code unless asked.
The test: Every changed line should trace directly to the user's request.
4. Goal-Driven Execution
Define success criteria. Loop until verified.
Transform tasks into verifiable goals:
- "Add validation" → "Write tests for invalid inputs, then make them pass"
- "Fix the bug" → "Write a test that reproduces it, then make it pass"
- "Refactor X" → "Ensure tests pass before and after"
For multi-step tasks, state a brief plan:
1. [Step] → verify: [check]
2. [Step] → verify: [check]
3. [Step] → verify: [check]Strong success criteria let you loop independently. Weak criteria ("make it work") require constant clarification.
These guidelines are working if: fewer unnecessary changes in diffs, fewer rewrites due to overcomplication, and clarifying questions come before implementation rather than after mistakes.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

