Dark Factory — Autonomous AI Agents

Create agent and ai_task sub-components to run autonomous AI agents inside FastMCP. Tasks execute on a schedule using Claude AI with access to all MCP tools.

How It Works

1. Agent
Defines AI model, API key, max iterations
2. Task
Defines what to do, schedule, mode, notifications
3. Link
ai_task-agent link connects task to its agent
4. Run
Background loop executes tasks, sends notifications

Agent Sub-Component

Each agent is an AI model configuration. Multiple tasks can share one agent. The agent defines who does the work.

Attribute Default Description
ai_api_key REQUIRED API key for the AI provider (Anthropic or OpenAI-compatible)
ai_model claude-haiku-4-5-20251001 Claude model ID. Haiku = cheap + fast. Sonnet = smarter for complex tasks.
agent_ai_provider anthropic anthropic or openai-compatible (for vLLM, Ollama, etc.)
ai_base_url (empty) Custom API base URL for OpenAI-compatible providers. Leave empty for Anthropic.
ai_max_iterations 10 Max tool-use loop iterations per task run. Higher = more thorough but costs more tokens.
agent_enabled true Master switch. Set to false to stop all tasks linked to this agent. Survives pod restarts (persisted in ENV).

ai_task Sub-Component

Each task defines what the agent should do. Link to an agent via ai_task-agent. Chain tasks via ai_task-ai_task.

Attribute Default Description
task_description REQUIRED Natural language instruction. Write it like you'd tell a human operator.
cron_expression (empty) Standard 5-field cron. Empty = run once on pod start.
*/30 * * * * = every 30 min   0 9 * * 1-5 = weekdays 9am   0 0 * * 0 = Sunday midnight
agent_mode monitor monitor = read-only tools only (safe for production)
act = read + write tools (INSERT, DELETE, publish, scale, sync)
retry_count 0 How many retries on failure. 0 = no retry, fail and stop.
retry_delay_seconds 60 Seconds to wait between retries.
notify_webhook (empty) Webhook URL for JSON notifications. Works with Slack, Teams, PagerDuty, or any generic webhook.
notify_email (empty) Email address for HTML reports with status badge, metadata table, and full output.

Cron Schedule Examples

cron_expression When it runs
*/5 * * * * Every 5 minutes (urgent monitoring)
*/30 * * * * Every 30 minutes (standard monitoring)
0 9 * * 1-5 Weekdays at 9am UTC (daily report)
0 0 * * 0 Sunday midnight (weekly review)
0 0 1 * * First day of month (monthly compliance)
(empty) Run once on pod start, then never again

Sub-Component Links

Link Type From → To Purpose
ai_task-agent ai_task → agent Which AI runs the task. Each task can target a different agent (cheap Haiku for data gathering, smart Sonnet for analysis).
ai_task-ai_task ai_task → ai_task Task chaining. On success, triggers next task with previous output as context. Only first task needs cron.

Agent fallback: If a task has no ai_task-agent link, it automatically uses the first available agent. In single-agent setups, you don't need to link every task — the fallback handles it.

Task Chaining

Link tasks via ai_task-ai_task to create pipelines. On success, the next task runs automatically with the previous result as context.

health-check
cron: */15 * * * *
agent: haiku
diagnose-report
chain (no cron)
agent: sonnet
remediate
chain, mode: act
agent: sonnet

Only the first task needs a cron. Each task in the chain can use a different agent (cost optimization).

Chain rules:

  • Only the first task needs cron_expression — chained tasks trigger automatically on success
  • Each task can use a different agent (cheap for data, smart for analysis)
  • Chain stops if a task fails (unless retry_count > 0)
  • Chained tasks receive the previous task's full output as context

Examples

Prometheus + Loki Monitoring

"Query Prometheus for pods with CPU > 80% or memory > 90%. Check Loki for error logs. Summarize findings."

mode: monitor cron: */30 * * * *

Weekly Stack Validation

"Run all stack-agent validation tests. Report failures with test name, component, and error details."

mode: monitor cron: 0 9 * * 1 retry: 2 (60s delay)

Database Maintenance (act mode)

"Check PostgreSQL for tables with > 1M rows and no recent VACUUM. Run ANALYZE on tables that need it."

mode: act cron: 0 3 * * 0

One-time Security Audit

"Check OPA compliance for all namespaces. Report security violations grouped by severity."

mode: monitor cron: (empty) = run once

Enable / Disable

Method How Persists? When to Use
Permanent Set agent_enabled=false on agent sub-component in Stacktic UI. Regenerate + kubectl apply -k. Yes Long-term disable, maintenance windows
Runtime Call dark_factory_toggle_agent("agent-name", false) from Claude Desktop or any MCP client. No (resets on restart) Quick pause, debugging, cost control

Dark Factory MCP Tools

These 6 tools are registered when agent/task sub-components exist. Use them from Claude Desktop or any MCP client to monitor and control the autonomous loop.

Tool Description
dark_factory_status Status of all agents and tasks — cron, last run, cost, retry state
dark_factory_history(task_name, limit) Execution history for a task (default: last 10 runs with timestamps, status, summaries)
dark_factory_toggle_agent(name, enabled) Enable/disable an agent at runtime. Takes effect instantly. Resets on pod restart.
dark_factory_run_now(task_name, follow_chain) Trigger immediate execution. Optionally follow the chain on success.
dark_factory_cost Per-task token usage breakdown and estimated USD cost since pod start.