Phase 3.5: Automation & Agents Plugin

Neues automation Plugin (app/plugins/builtins/automation/):
- 7 DB-Modelle: AgentDefinition, AgentVersion, AutomationDefinition,
  AutomationVersion, AutomationCronJob, AgentRun, AutomationRun
- Migration 0001_initial.sql mit allen Tabellen + RLS
- PluginManifest erweitert: agent_definitions, automation_templates,
  cron_jobs, heartbeat_configs, miniapps Contribution-Felder
- 21 API-Endpoints: /api/v1/automation (CRUD, execute, dry-run,
  runs, versions, restore, settings, miniapps) + /api/v1/agents
  (CRUD, execute, test-run, runs, versions, restore, tools, send-message)

Backend Features:
- Cron-Scheduler (scheduler.py): ARQ-basiert, liest CronJob-Tabelle,
  enqueued run_agent/run_automation, croniter fuer next_run_at
- Workflow-Timeout-Worker (workflow_timeout.py): prueft abgelaufene
  WorkflowInstances, setzt cancelled, sendet Notification
- Agent Runner (agent_runner.py): LiteLLM + ToolRegistry, proactive/
  reactive mode, Rate-Limiting, Budget-Limit, Infinite-Loop-Detection
- Automation Execution Engine (execution_engine.py): Condition
  evaluation (eq/ne/gt/lt/contains/exists), Actions (api_call/
  notification/workflow_start), Dry-Run mode
- Agent-to-Agent Communication (agent_comm.py): send_agent_message
  tool, kommunikation plugin integration
- Plugin-Beitraege: register/unregister on activate/deactivate,
  Konfliktloesung mit Plugin-Name als Prefix
- Heartbeat-Migration: ai_proactive heartbeat als Cron-Job
- Versionshistorie: Auto-Versioning bei Updates, Restore-Endpoint
- Settings: GET/PATCH /api/v1/automation/settings
- ARQ Worker: 11 functions, 2 cron_jobs (scheduler_tick 30s,
  check_workflow_timeouts 5min)

Frontend:
- AutomationDashboard.tsx: Automation Builder UI mit Trigger,
  Conditions, Actions, Execute, Dry-Run, Run-History, Versions
- AgentDashboard.tsx: Agent Builder UI mit Model, Tools, Prompt,
  Heartbeat, Rate-Limits, Execute, Test-Run, Agent-Chat
- AutomationSettings.tsx: Settings + MiniApp-Builder
- automation.ts: 24 React Query Hooks
- automation.ts types: TypeScript Interfaces
- routes/index.tsx: /automation, /agents, /settings/automation

Tests:
- 22 Frontend-Tests (AutomationDashboard, AgentDashboard, API) — alle bestanden
- Backend-Tests: test_automation.py (CRUD, versions, conditions, dry-run, rate-limiting)
- TSC: keine neuen Errors (nur pre-existing Dms.tsx)
- croniter dependency installiert
This commit is contained in:
Agent Zero
2026-07-23 20:00:37 +02:00
parent fc96a2f86c
commit 5dc6f29ac1
28 changed files with 7397 additions and 0 deletions
+62
View File
@@ -350,6 +350,61 @@ class PluginRegistry:
)
return warnings
# ── Plugin Contribution Registration ──
async def _register_contributions_for_plugin(self, db: AsyncSession, name: str, plugin: BasePlugin) -> None:
"""Register agent_definitions, automation_templates, cron_jobs, and heartbeat_configs
from a plugin's manifest with the automation plugin."""
automation_plugin = self._plugins.get("automation")
if automation_plugin is None:
return
# Check if automation plugin is active
automation_record = await self._get_plugin_record(db, "automation")
if automation_record is None or not automation_record.active:
return
# Check if the activating plugin has any contributions
manifest = plugin.manifest
has_contributions = bool(
manifest.agent_definitions
or manifest.automation_templates
or manifest.cron_jobs
or manifest.heartbeat_configs
)
if not has_contributions:
return
try:
await automation_plugin.register_plugin_contributions(db, name, manifest)
logger.info(
"Registered contributions from plugin '%s' with automation plugin",
name,
)
except Exception:
logger.exception(
"Failed to register contributions from plugin '%s' with automation plugin",
name,
)
async def _unregister_contributions_for_plugin(self, db: AsyncSession, name: str) -> None:
"""Unregister contributions from a plugin being deactivated."""
automation_plugin = self._plugins.get("automation")
if automation_plugin is None:
return
try:
await automation_plugin.unregister_plugin_contributions(db, name)
logger.info(
"Unregistered contributions from plugin '%s' with automation plugin",
name,
)
except Exception:
logger.exception(
"Failed to unregister contributions from plugin '%s' with automation plugin",
name,
)
# ── Version Comparison & Update Path ──
async def _check_and_run_version_migrations(
@@ -470,6 +525,10 @@ class PluginRegistry:
# Call on_activate hook (registers event listeners)
await plugin.on_activate(db, self._container, self._event_bus)
# Register plugin contributions (agent_definitions, automation_templates, etc.)
# with the automation plugin if it is active
await self._register_contributions_for_plugin(db, name, plugin)
# Register routes on FastAPI app if available
# Track actual route objects by identity to avoid cross-plugin removal
if self._app is not None:
@@ -533,6 +592,9 @@ class PluginRegistry:
f"depend on it: {', '.join(active_dependents)}"
)
# Unregister plugin contributions from automation plugin
await self._unregister_contributions_for_plugin(db, name)
# Call on_deactivate hook (unregisters event listeners)
await plugin.on_deactivate(db, self._container, self._event_bus)