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:
@@ -0,0 +1,137 @@
|
||||
-- automation plugin: agent definitions, automation definitions, cron jobs, run logs
|
||||
|
||||
-- Agent Definitions
|
||||
CREATE TABLE IF NOT EXISTS automation_agent_definitions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
description VARCHAR(500) NOT NULL DEFAULT '',
|
||||
llm_model VARCHAR(100) NOT NULL DEFAULT 'ollama/deepseek-v4-flash',
|
||||
system_prompt TEXT NOT NULL DEFAULT '',
|
||||
tool_ids JSONB NOT NULL DEFAULT '[]',
|
||||
heartbeat_interval_seconds INT NOT NULL DEFAULT 0,
|
||||
mode VARCHAR(20) NOT NULL DEFAULT 'reactive', -- proactive, reactive
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
max_executions_per_hour INT NOT NULL DEFAULT 10,
|
||||
max_duration_seconds INT NOT NULL DEFAULT 300,
|
||||
budget_limit_usd FLOAT NOT NULL DEFAULT 1.0,
|
||||
created_by UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ,
|
||||
UNIQUE(tenant_id, name)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_agent_def_tenant_active ON automation_agent_definitions (tenant_id, is_active);
|
||||
CREATE INDEX IF NOT EXISTS ix_agent_def_tenant_mode ON automation_agent_definitions (tenant_id, mode);
|
||||
|
||||
-- Agent Versions
|
||||
CREATE TABLE IF NOT EXISTS automation_agent_versions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
agent_id UUID NOT NULL REFERENCES automation_agent_definitions(id) ON DELETE CASCADE,
|
||||
version_number INT NOT NULL,
|
||||
snapshot JSONB NOT NULL,
|
||||
changed_by UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ,
|
||||
UNIQUE(agent_id, version_number)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_agent_versions_agent ON automation_agent_versions (tenant_id, agent_id);
|
||||
|
||||
-- Automation Definitions
|
||||
CREATE TABLE IF NOT EXISTS automation_definitions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
description VARCHAR(500) NOT NULL DEFAULT '',
|
||||
trigger_type VARCHAR(20) NOT NULL DEFAULT 'manual', -- event, schedule, manual
|
||||
trigger_config JSONB NOT NULL DEFAULT '{}',
|
||||
conditions JSONB NOT NULL DEFAULT '[]',
|
||||
actions JSONB NOT NULL DEFAULT '[]',
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
dry_run BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_by UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ,
|
||||
UNIQUE(tenant_id, name)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_automation_def_tenant_active ON automation_definitions (tenant_id, is_active);
|
||||
CREATE INDEX IF NOT EXISTS ix_automation_def_tenant_trigger ON automation_definitions (tenant_id, trigger_type);
|
||||
|
||||
-- Automation Versions
|
||||
CREATE TABLE IF NOT EXISTS automation_versions (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
automation_id UUID NOT NULL REFERENCES automation_definitions(id) ON DELETE CASCADE,
|
||||
version_number INT NOT NULL,
|
||||
snapshot JSONB NOT NULL,
|
||||
changed_by UUID REFERENCES users(id) ON DELETE SET NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ,
|
||||
UNIQUE(automation_id, version_number)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_automation_versions_def ON automation_versions (tenant_id, automation_id);
|
||||
|
||||
-- Cron Jobs
|
||||
CREATE TABLE IF NOT EXISTS automation_cron_jobs (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
cron_expression VARCHAR(100) NOT NULL,
|
||||
job_type VARCHAR(50) NOT NULL DEFAULT 'automation_trigger', -- agent_heartbeat, automation_trigger, custom
|
||||
target_id UUID,
|
||||
plugin_name VARCHAR(80) NOT NULL DEFAULT '',
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
last_run_at TIMESTAMPTZ,
|
||||
next_run_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_cron_jobs_tenant_active ON automation_cron_jobs (tenant_id, is_active);
|
||||
CREATE INDEX IF NOT EXISTS ix_cron_jobs_next_run ON automation_cron_jobs (next_run_at);
|
||||
|
||||
-- Agent Runs (Execution Log)
|
||||
CREATE TABLE IF NOT EXISTS automation_agent_runs (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
agent_id UUID NOT NULL REFERENCES automation_agent_definitions(id) ON DELETE CASCADE,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'pending', -- pending, running, completed, failed, cancelled, timeout
|
||||
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
completed_at TIMESTAMPTZ,
|
||||
duration_seconds FLOAT,
|
||||
result TEXT,
|
||||
error TEXT,
|
||||
cost_usd FLOAT,
|
||||
trigger_type VARCHAR(20) NOT NULL DEFAULT 'manual',
|
||||
trigger_data JSONB NOT NULL DEFAULT '{}',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_agent_runs_agent_status ON automation_agent_runs (tenant_id, agent_id, status);
|
||||
CREATE INDEX IF NOT EXISTS ix_agent_runs_started ON automation_agent_runs (tenant_id, started_at DESC);
|
||||
|
||||
-- Automation Runs (Execution Log)
|
||||
CREATE TABLE IF NOT EXISTS automation_runs (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
tenant_id UUID NOT NULL,
|
||||
automation_id UUID NOT NULL REFERENCES automation_definitions(id) ON DELETE CASCADE,
|
||||
status VARCHAR(20) NOT NULL DEFAULT 'pending', -- pending, running, completed, failed, cancelled, timeout
|
||||
started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
completed_at TIMESTAMPTZ,
|
||||
duration_seconds FLOAT,
|
||||
result TEXT,
|
||||
error TEXT,
|
||||
trigger_type VARCHAR(20) NOT NULL DEFAULT 'manual',
|
||||
trigger_data JSONB NOT NULL DEFAULT '{}',
|
||||
dry_run BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS ix_automation_runs_def_status ON automation_runs (tenant_id, automation_id, status);
|
||||
CREATE INDEX IF NOT EXISTS ix_automation_runs_started ON automation_runs (tenant_id, started_at DESC);
|
||||
Reference in New Issue
Block a user