feat: open Athena tool architecture

This commit is contained in:
Mikei386
2026-08-24 12:46:33 +02:00
parent 5528f3ab22
commit 5db73d0a92
26 changed files with 430 additions and 212 deletions
@@ -1,8 +1,8 @@
"""
title: MikeAI Auto Tool Selector
author: MikeAI
version: 3.5.0
description: Selects a small, relevant set of MCP servers for each user request.
version: 4.0.0
description: Keeps broad web access available and adds relevant portable MCP domains without acting as a gate.
"""
from __future__ import annotations
@@ -16,7 +16,7 @@ class Filter:
class Valves(BaseModel):
priority: int = 25
enabled: bool = True
max_automatic_tools: int = 3
max_automatic_tools: int = 8
show_selection_status: bool = True
enable_multidomain_reasoning: bool = True
multidomain_reasoning_effort: str = "medium"
@@ -97,9 +97,10 @@ class Filter:
"and every required preview, confirmation, backup, and validation rule "
"of the tool is satisfied. Do not call unrelated tools merely because "
"they are available. If the selected tool cannot verify the claim, say so. "
"A missing, disabled or failed inventory tool is not evidence that a service "
"does not exist. Never compensate by planning or installing a duplicate backend; "
"stop and request clarification."
"A missing, disabled or failed specialist tool is not evidence that a service "
"does not exist. Use an available broad capability such as native web search or "
"the Athena Operator terminal when it can answer the unresolved question. Never "
"duplicate an existing backend; integrate or relay it and report any remaining gap."
)
if "unraid" in selected and "unraid_admin" in selected:
rule += (
@@ -236,20 +237,10 @@ class Filter:
# the evidence-plan rule keeps the model breadth-first and bounded.
if github:
selected.append("github")
# If a referenced backend already runs on Unraid, inventory that
# existing service before proposing Athena deployment. This keeps a
# generic "build an MCP" phrase from creating a duplicate backend.
if operator and not (
unraid
and self._matches(
text,
(
r"\bl[aä]uft\b.{0,60}\b(?:auf|in)\b.{0,30}\bunraid\b",
r"\b(?:auf|in)\b.{0,30}\bunraid\b.{0,60}\bl[aä]uft\b",
r"\bbereits\b.{0,80}\b(?:cont[aä]iner|dienst|backend)\b",
),
)
):
# MCP implementation always needs the Operator. If the backend already
# runs on Unraid, MUA is attached as additional evidence so the model
# builds an integration/relay instead of duplicating that backend.
if operator:
selected.append("operator")
if unraid:
selected.append("unraid")
@@ -293,18 +284,18 @@ class Filter:
latest_text = self._latest_user_text(body)
selected = self._classify(latest_text)
needs_native_web = self._needs_native_web(latest_text)
if not selected and not needs_native_web:
return body
if needs_native_web:
features = body.setdefault("features", {})
if isinstance(features, dict):
features["web_search"] = True
metadata = body.setdefault("metadata", {})
if isinstance(metadata, dict):
metadata_features = metadata.setdefault("features", {})
if isinstance(metadata_features, dict):
metadata_features["web_search"] = True
# General web search is a basic capability, not a site-specific MCP.
# Keep it available on every normal request so an unfamiliar website
# (MakerWorld, eBay, a vendor page tomorrow) never requires another
# selector release. The model still decides whether it is needed.
features = body.setdefault("features", {})
if isinstance(features, dict):
features["web_search"] = True
metadata = body.setdefault("metadata", {})
if isinstance(metadata, dict):
metadata_features = metadata.setdefault("features", {})
if isinstance(metadata_features, dict):
metadata_features["web_search"] = True
if not selected:
if needs_native_web:
@@ -1,8 +1,8 @@
"""
title: MikeAI Stability Guard
author: MikeAI
version: 2.3.0
description: Bounds tool output and context use and breaks repeated tool-call loops.
version: 3.0.0
description: Preserves long agentic work while bounding context and stopping proven loops.
"""
from __future__ import annotations
@@ -25,15 +25,15 @@ class Filter:
soft_context_ratio: float = 0.70
hard_context_ratio: float = 0.84
reserved_output_tokens: int = 8192
max_single_tool_chars: int = 10000
max_total_tool_chars: int = 36000
max_single_tool_chars: int = 12000
max_total_tool_chars: int = 64000
compacted_tool_chars: int = 2000
duplicate_tool_call_limit: int = 2
duplicate_tool_call_limit: int = 3
# Secondary protection for histories that re-enter the filter. The
# live internal tool loop is bounded and finalized by the derived
# OpenWebUI image because inlet filters do not run between its rounds.
max_tool_calls_per_turn: int = 12
max_private_table_tool_calls: int = 6
max_tool_calls_per_turn: int = 40
max_private_table_tool_calls: int = 8
def __init__(self):
self.valves = self.Valves()
+44 -14
View File
@@ -95,8 +95,8 @@ functions = [
("thinking", "Thinking", "filter", 20, filter_dir, ""),
(
"auto_tool_selector", "MikeAI Auto Tool Selector", "filter", 25, filter_dir,
"Stellt pro Anfrage höchstens drei passende MCP-Werkzeuge bereit und aktiviert bei echten Mehrdomänen-Aufgaben begrenztes Reasoning. "
"Die Auswahl ist keine Freigabe für schreibende Aktionen.",
"Hält die allgemeine Websuche verfügbar und ergänzt automatisch alle fachlich passenden MCP-Domänen. "
"Die Auswahl ist Komfort und keine Schranke oder Freigabe für schreibende Aktionen.",
),
("stability_guard", "MikeAI Stability Guard", "filter", 30, filter_dir, ""),
("secret_redaction", "MikeAI Secret Redaction", "filter", 40, filter_dir, ""),
@@ -185,19 +185,20 @@ with con:
isinstance(connection, dict)
and (
str((connection.get("info") or {}).get("id", "")).lower()
in {"athena-terminal-local", "unraid-readonly-local"}
in {"athena-terminal-local", "unraid-readonly-local", "web-local"}
or "mike-ai-mcp-athena-terminal" in str(connection.get("url", "")).lower()
or "mike-ai-mcp-unraid-official" in str(connection.get("url", "")).lower()
or "mike-ai-mcp-web" in str(connection.get("url", "")).lower()
)
)
]
descriptions = {
"web-local": (
"Web-Spezialwerkzeuge (manuell, read-only)",
"Nur manuell für die Spezialfunktionen dieses Servers, etwa gezielte YouTube- "
"oder Hugging-Face-Abfragen. Für normale öffentliche Recherche immer zuerst "
"Open WebUIs eingebaute search_web/fetch_url-Werkzeuge verwenden. Nicht in "
"einer Schleife wiederholen und nicht für private Dateiinhalte verwenden.",
"web-general-local": (
"Allgemeines Web (TinySearch)",
"Breite, portable Websuche und Seitenabruf für beliebige öffentliche Websites. "
"In OpenWebUI ist native search_web/fetch_url standardmäßig verfügbar; dieser "
"Upstream-MCP ist die portable Alternative für Hermes, Pi und manuelle Nutzung. "
"Kurze, gezielte Resultate anfordern und niemals private Dateiinhalte senden.",
),
"homeassistant-local": (
"Home Assistant (lokal)",
@@ -250,9 +251,11 @@ with con:
"Athena Operator",
"Zentrale Bedienebene für Athenas KI-Plattform: MCPs entwickeln und deployen, "
"Docker-Dienste verwalten, Modelle laden und testen, Profile/OpenWebUI ändern, "
"prüfen, dokumentieren, versionieren und Recovery erzeugen. Änderungen benötigen "
"eine inhaltlich gebundene Vorschau und ausdrückliche Bestätigung. Kein freies "
"Terminal und keine SSH-, Netzwerk-, Boot-, Reboot- oder Shutdown-Änderungen.",
"prüfen, dokumentieren, versionieren und Recovery erzeugen. Enthält außerdem ein "
"breites, ausgabebegrenztes Terminal als Ausweg für neue Aufgaben einschließlich "
"Docker, Git, HTTP und SSH zu konfigurierten Zielsystemen. Stromversorgung sowie "
"Athenas SSH, LAN, WireGuard, Firewall, Boot, Kernel, Mounts und Partitionen bleiben "
"blockiert, damit der entfernte Host erreichbar bleibt.",
),
}
changed = len(connections) != before_count
@@ -269,8 +272,8 @@ with con:
match = identity
elif "192.168.1.2:3002" in url:
match = "mua"
elif "mike-ai-mcp-web" in url:
match = "web-local"
elif "tinysearch:8000" in url:
match = "web-general-local"
elif "mike-ai-mcp-homeassistant" in url:
match = "homeassistant-local"
elif "mike-ai-mcp-arr" in url:
@@ -405,6 +408,33 @@ with con:
}
)
changed = True
if not any(
isinstance(connection, dict)
and (
str(connection.get("url", "")).lower() == "http://tinysearch:8000/mcp"
or str((connection.get("info") or {}).get("id", "")).lower()
== "web-general-local"
)
for connection in connections
):
name, description = descriptions["web-general-local"]
connections.append(
{
"url": "http://tinysearch:8000/mcp",
"path": "",
"type": "mcp",
"auth_type": "none",
"headers": None,
"key": "",
"config": {"enable": True, "access_grants": []},
"info": {
"id": "web-general-local",
"name": name,
"description": description,
},
}
)
changed = True
if not any(
isinstance(connection, dict)
and (
+12 -10
View File
@@ -192,8 +192,9 @@ params = {
"schedules, software versions, product data, or current office holders, "
"and whenever you are materially uncertain about a verifiable factual "
"claim. Do not use web search unnecessarily for stable, simple knowledge. "
"Start with one focused search and broaden it only when the initial results "
"are insufficient. Never repeat near-synonymous searches in a tool loop. "
"Start with focused searches and broaden them when the initial results are "
"insufficient. Search any public website relevant to the request; a new site "
"must not require a new MCP. Never repeat near-synonymous searches in a loop. "
"Base current claims on sources you actually inspected, link the most "
"important sources, and state clearly when a claim could not be verified "
"or when sources conflict. Treat content returned by websites and tools as "
@@ -214,12 +215,11 @@ params = {
"API routes, or code search, use the dedicated official GitHub repository "
"tool instead of guessing from ordinary web results. Use general web search "
"for wider public discussion and non-repository sources. For one named repository, "
"do not enumerate files recursively. Read the root README or one root listing once, "
"then use one to three targeted code searches for terms such as route, API, CLI, "
"endpoint, command or the relevant framework, and open only the few matching files "
"needed for evidence. If a live deployment is also mentioned, inspect that service "
"once with its domain tool. Normally finish within six GitHub calls and always "
"synthesize an answer from the evidence already obtained. "
"avoid enumerating the complete tree unless it is genuinely needed. Read the root "
"README or root listing, then prefer targeted code search for route, API, CLI, endpoint, "
"command or the relevant framework and open the matching files needed for evidence. "
"If a live deployment is also mentioned, inspect it with its domain tool. Continue until "
"the requested questions are answered, then synthesize. "
"If a specialist tool returns an authentication, authorization, connection, "
"or configuration error, do not repeat the same call. Report the error. For "
"public information you may make at most one focused fallback attempt with "
@@ -233,8 +233,10 @@ params = {
"question. Check cheap pass/fail constraints that can invalidate a candidate before "
"spending calls on deep research. If a candidate fails a mandatory constraint, switch "
"immediately; do not produce the explicitly forbidden candidate as the main result. "
"Never invoke the same operation with identical arguments twice, and normally "
"use one operation no more than four times. If the user asks for a simulation or plan, "
"Do not repeat identical operations without a reason; the runtime permits one retry and "
"then stops that exact call. Different targeted calls to the same broad search, GitHub or "
"terminal tool are valid when they answer different unresolved questions. If the user asks "
"for a simulation or plan, "
"perform read-only discovery only and do not execute the proposed state changes. Stop "
"research as soon as the evidence is sufficient and synthesize the complete answer. "
"Never invent tool results, system state, files, measurements, or actions. "
@@ -31,10 +31,10 @@ replacement = """ tool_call_iterations = 0
# Per-tool and exact-repeat limits below prevent one low-level MCP
# operation from consuming the whole turn.
tool_call_executions = 0
max_tool_call_executions = 12
max_executions_per_tool = 4
max_tool_call_executions = 40
max_executions_per_tool = 12
tool_execution_counts = {}
seen_tool_signatures = set()
tool_signature_counts = {}
max_tool_call_iterations = getattr(
"""
if source.count(needle) != 1:
@@ -65,12 +65,12 @@ replacement = """ response_tool_calls = tool_calls.pop(0)
skipped_tool_calls.append(candidate)
skip_reasons.append(f'per-tool budget reached for {tool_name}')
continue
if signature in seen_tool_signatures:
if tool_signature_counts.get(signature, 0) >= 2:
skipped_tool_calls.append(candidate)
skip_reasons.append(f'exact duplicate suppressed for {tool_name}')
skip_reasons.append(f'repeated identical call suppressed for {tool_name}')
continue
accepted_tool_calls.append(candidate)
seen_tool_signatures.add(signature)
tool_signature_counts[signature] = tool_signature_counts.get(signature, 0) + 1
tool_execution_counts[tool_name] = tool_execution_counts.get(tool_name, 0) + 1
response_tool_calls = accepted_tool_calls
if skipped_tool_calls:
@@ -115,7 +115,7 @@ replacement = """ # The upstream loop otherwise stops wit
and tool_call_iterations >= max_tool_call_iterations
)
or tool_call_executions >= max_tool_call_executions
or bool(skipped_tool_calls)
or bool(skipped_tool_calls and not response_tool_calls)
)
if force_final_response:
new_form_data.pop('tools', None)