agentleFS
antivantiv/mate/CLAUDE.md

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.

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
  1. Distinctive:

    Follow PEP 8 with type hints on all function signatures.

    line 81
  2. Very specific:

    Do not add attribution trailers to commit messages: no Co-Authored-By: Claude ..., no Claude-Session: ..., and no "Generated with Claude …

    line 85
  3. Distinctive:

    If multiple interpretations exist, present them - don't pick silently.

    line 147
  4. Distinctive:

    If a simpler approach exists, say so.

    line 148
  5. Distinctive:

    If something is unclear, stop.

    line 149
  6. Distinctive:

    No features beyond what was asked.

    line 155
  7. Distinctive:

    No abstractions for single-use code.

    line 156
  8. Distinctive:

    No error handling for impossible scenarios.

    line 158
  9. Distinctive:

    If you write 200 lines and it could be 50, rewrite it.

    line 159
  10. Distinctive:

    Ask yourself: "Would a senior engineer say this is overcomplicated?" If yes, simplify.

    line 161
  11. Distinctive:

    When editing existing code:

    line 167
  12. Distinctive:

    Don't "improve" adjacent code, comments, or formatting.

    line 168
  13. Distinctive:

    Don't refactor things that aren't broken.

    line 169
  14. Distinctive:

    If you notice unrelated dead code, mention it - don't delete it.

    line 171
  15. Distinctive:

    When your changes create orphans:

    line 173
  16. Very specific:

    Remove imports/variables/functions that YOUR changes made unused.

    line 174
  17. Distinctive:

    Don't remove pre-existing dead code unless asked.

    line 175

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

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 up

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).

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 report

Tests 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 server
  • adk_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

VariablePurpose
AGENT_FRAMEWORKAgent runtime: adk (default) or langgraph
GOOGLE_API_KEYGoogle Gemini (primary LLM)
OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.Additional LLM providers via LiteLLM
DB_TYPEsqlite (default), postgresql, mysql
AUTH_USERNAME / AUTH_PASSWORDDashboard login
MATE_ENVdevelopment (default) or production; production refuses insecure defaults
MATE_ALLOW_INSECURE_DEFAULTSOverride the production startup checks
ADK_DEV_UIServe ADK's dev UI at /dev-ui (admins only); defaults to off when MATE_ENV=production, on otherwise
ALLOWED_ORIGINSComma-separated CORS allowlist
TRUSTED_PROXY_HOSTSProxy hosts trusted for X-Forwarded-* headers; audit logs only trust X-Forwarded-For when set
OAUTH_ALLOWED_DOMAINS / OAUTH_ALLOWED_EMAILSRestrict who may sign in via SSO (unset = anyone with a provider account)
TOKEN_TTL_HOURSBearer token lifetime, default 24
WIDGET_ORIGIN_STRICTEnforce (vs. only log) a widget key's origin allowlist
CSP_MODEContent-Security-Policy: report-only (default), enforce or off
CSP_EXTRA_SOURCESExtra hosts the CSP allows for scripts, styles, fonts, connections and frames
BROWSER_ALLOW_PRIVATE_NETWORKLet the server-side browser load private/loopback addresses (blocked by default)
MATE_ALLOW_CODE_EXECUTOR_ON_WIDGETAllow code_executor on an agent that has a widget key (refused by default — it is not a sandbox)
WIDGET_LEGACY_ADMIN_KEYTransitional: let the public widget key work on /widget/api admin routes
ADK_HOST / ADK_PORTADK server address (default 127.0.0.1:8001)
ARTIFACT_SERVICElocal_folder, supabase, or s3
TAVILY_API_KEYWeb search for google_search; falls back to DuckDuckGo when unset
EVAL_JUDGE_MODEL / EVAL_IMPROVE_MODELJudge for llm_judge evals / model that suggests instruction fixes (falls back to the judge)
EMBEDDING_MODELEmbedding model for memory block semantic search (litellm format, default gemini/gemini-embedding-001)
RATE_LIMIT_ENABLEDEnable per-user/agent/project budgets
ALERTS_ENABLED / ALERTS_INTERVAL_SECONDSAlert rules on agent errors, guardrail bursts and budget thresholds
OTEL_TRACING_ENABLEDOpenTelemetry distributed tracing (ADK runtime)
LANGSMITH_TRACING / LANGSMITH_API_KEYLangSmith run tracing (langgraph runtime)
AUDIT_RETENTION_DAYSAudit log retention (evidence toward EU AI Act Art. 12)
MATE_AI_DISCLOSUREStandalone 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, run python scripts/gen_docs.py and commit the result; CI fails on a stale reference (--check).
  • docs/user/ and docs/dev/ are guides. Before finishing a task, run python 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.