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
+291
View File
@@ -0,0 +1,291 @@
"""Pydantic v2 schemas for the Automation & Agents plugin API."""
from __future__ import annotations
from datetime import datetime
from typing import Any
from pydantic import BaseModel, Field
# ─── Agent Definition Schemas ───
class AgentDefinitionCreate(BaseModel):
"""Create a new agent definition."""
name: str = Field(..., min_length=1, max_length=120)
description: str = Field(default="", max_length=500)
llm_model: str = Field(default="ollama/deepseek-v4-flash", max_length=100)
system_prompt: str = Field(default="")
tool_ids: list[str] = Field(default_factory=list)
heartbeat_interval_seconds: int = Field(default=0, ge=0)
mode: str = Field(default="reactive", pattern="^(proactive|reactive)$")
is_active: bool = Field(default=True)
max_executions_per_hour: int = Field(default=10, ge=1, le=1000)
max_duration_seconds: int = Field(default=300, ge=1, le=86400)
budget_limit_usd: float = Field(default=1.0, ge=0.0, le=10000.0)
class AgentDefinitionUpdate(BaseModel):
"""Update an existing agent definition (partial)."""
name: str | None = Field(None, max_length=120)
description: str | None = Field(None, max_length=500)
llm_model: str | None = Field(None, max_length=100)
system_prompt: str | None = None
tool_ids: list[str] | None = None
heartbeat_interval_seconds: int | None = Field(None, ge=0)
mode: str | None = Field(None, pattern="^(proactive|reactive)$")
is_active: bool | None = None
max_executions_per_hour: int | None = Field(None, ge=1, le=1000)
max_duration_seconds: int | None = Field(None, ge=1, le=86400)
budget_limit_usd: float | None = Field(None, ge=0.0, le=10000.0)
class AgentDefinitionResponse(BaseModel):
"""Agent definition response."""
id: str
name: str
description: str = ""
llm_model: str
system_prompt: str = ""
tool_ids: list[str] = []
heartbeat_interval_seconds: int = 0
mode: str
is_active: bool = True
max_executions_per_hour: int = 10
max_duration_seconds: int = 300
budget_limit_usd: float = 1.0
created_by: str | None = None
created_at: str | None = None
updated_at: str | None = None
# ─── Automation Definition Schemas ───
class AutomationDefinitionCreate(BaseModel):
"""Create a new automation definition."""
name: str = Field(..., min_length=1, max_length=120)
description: str = Field(default="", max_length=500)
trigger_type: str = Field(default="manual", pattern="^(event|schedule|manual)$")
trigger_config: dict[str, Any] = Field(default_factory=dict)
conditions: list[dict[str, Any]] = Field(default_factory=list)
actions: list[dict[str, Any]] = Field(default_factory=list)
is_active: bool = Field(default=True)
dry_run: bool = Field(default=False)
class AutomationDefinitionUpdate(BaseModel):
"""Update an existing automation definition (partial)."""
name: str | None = Field(None, max_length=120)
description: str | None = Field(None, max_length=500)
trigger_type: str | None = Field(None, pattern="^(event|schedule|manual)$")
trigger_config: dict[str, Any] | None = None
conditions: list[dict[str, Any]] | None = None
actions: list[dict[str, Any]] | None = None
is_active: bool | None = None
dry_run: bool | None = None
class AutomationDefinitionResponse(BaseModel):
"""Automation definition response."""
id: str
name: str
description: str = ""
trigger_type: str
trigger_config: dict[str, Any] = {}
conditions: list[dict[str, Any]] = []
actions: list[dict[str, Any]] = []
is_active: bool = True
dry_run: bool = False
created_by: str | None = None
created_at: str | None = None
updated_at: str | None = None
# ─── Cron Job Schemas ───
class CronJobResponse(BaseModel):
"""Cron job response."""
id: str
name: str
cron_expression: str
job_type: str
target_id: str | None = None
plugin_name: str = ""
is_active: bool = True
last_run_at: str | None = None
next_run_at: str | None = None
created_at: str | None = None
updated_at: str | None = None
# ─── Run Log Schemas ───
class AgentRunResponse(BaseModel):
"""Agent run log response."""
id: str
agent_id: str
status: str
started_at: str
completed_at: str | None = None
duration_seconds: float | None = None
result: str | None = None
error: str | None = None
cost_usd: float | None = None
trigger_type: str = "manual"
trigger_data: dict[str, Any] = {}
created_at: str | None = None
class AutomationRunResponse(BaseModel):
"""Automation run log response."""
id: str
automation_id: str
status: str
started_at: str
completed_at: str | None = None
duration_seconds: float | None = None
result: str | None = None
error: str | None = None
trigger_type: str = "manual"
trigger_data: dict[str, Any] = {}
dry_run: bool = False
created_at: str | None = None
# ─── Version Schemas ───
class AgentVersionResponse(BaseModel):
"""Agent version response."""
id: str
agent_id: str
version_number: int
snapshot: dict[str, Any]
changed_by: str | None = None
created_at: str | None = None
class AutomationVersionResponse(BaseModel):
"""Automation version response."""
id: str
automation_id: str
version_number: int
snapshot: dict[str, Any]
changed_by: str | None = None
created_at: str | None = None
# ─── Settings Schemas ───
class AgentMessageRequest(BaseModel):
"""Request to send a message from one agent to another."""
to_agent_name: str = Field(..., min_length=1, max_length=120)
message: str = Field(..., min_length=1)
class MiniAppCreate(BaseModel):
"""Create a custom MiniApp definition."""
app_id: str = Field(..., min_length=1, max_length=80)
name: str = Field(..., min_length=1, max_length=120)
icon: str = Field(default="AppWindow")
description: str = Field(default="")
render_schema: dict[str, Any] = Field(default_factory=dict)
class MiniAppResponse(BaseModel):
"""MiniApp definition response."""
app_id: str
name: str
icon: str = "AppWindow"
description: str = ""
plugin_name: str = ""
render_schema: dict[str, Any] = {}
class AutomationSettingsResponse(BaseModel):
"""Automation settings response."""
default_llm_model: str = "ollama/deepseek-v4-flash"
heartbeat_default_interval: int = 300
max_concurrent_agents: int = 5
log_level: str = "INFO"
class AutomationSettingsUpdate(BaseModel):
"""Automation settings update (partial)."""
default_llm_model: str | None = None
heartbeat_default_interval: int | None = None
max_concurrent_agents: int | None = None
log_level: str | None = None
# ─── List Response Schemas ───
class AgentDefinitionListResponse(BaseModel):
"""Paginated agent definition list."""
items: list[AgentDefinitionResponse]
total: int
class AutomationDefinitionListResponse(BaseModel):
"""Paginated automation definition list."""
items: list[AutomationDefinitionResponse]
total: int
class AgentRunListResponse(BaseModel):
"""Paginated agent run list."""
items: list[AgentRunResponse]
total: int
class AutomationRunListResponse(BaseModel):
"""Paginated automation run list."""
items: list[AutomationRunResponse]
total: int
class CronJobListResponse(BaseModel):
"""Paginated cron job list."""
items: list[CronJobResponse]
total: int
class AgentVersionListResponse(BaseModel):
"""Paginated agent version list."""
items: list[AgentVersionResponse]
total: int
class AutomationVersionListResponse(BaseModel):
"""Paginated automation version list."""
items: list[AutomationVersionResponse]
total: int