Skip to main content
KadiCache
Commerce & Pulse MCPCloud Pro

Built-In BYOK AI Agent & 3-Viewport CSS Lab

Runs an interactive performance engineer directly inside WP Admin -> KadiCache -> AI Agent with a multi-provider SecretBox-encrypted BYOK vault, live tool execution traces, Vision screenshot inspection, 3-viewport (390px / 820px / 1440px) non-live CSS draft verification, human-approved mutations, and 1-click checkpoint rollback.

BYOK · 3-Viewport Lab
4 LLM Vaults
Verified Source Entry
apps/wordpress-plugin-pro/src/Ai/AiAgentController.php
Verified Engine Capabilities

Engineered for zero regressions.

  • Multi-provider SecretBox-encrypted BYOK vault (OpenAI, Anthropic Claude, Google Gemini & OpenRouter) with in-chat provider/model switching and zero AI traffic through KadiCache Cloud
  • Read-only diagnostic tools auto-execute in step-by-step HTTP turns with collapsible millisecond Tool Traces, Stop cancellation, and 1-click Copy Report
  • Stages non-live scoped Custom CSS drafts and verifies Mobile (390px), Tablet (820px) & Desktop (1440px) via signed preview URLs before asking for publish approval
  • Every approved setting edit or Custom CSS rule records an atomic McpCheckpoints snapshot for instant 1-click rollback and serves cleanly with Early Cache after Cloud RUCSS
Verified AI Agent REST Routes & Step Lifecycle (AiAgentController.php)
GET  /wp-json/kadicache-pro/v1/ai-settings   # Multi-provider vault status (keys never leave server)
POST /wp-json/kadicache-pro/v1/ai-settings   # Save SecretBox-encrypted key, sync /models, or switch_model
POST /wp-json/kadicache-pro/v1/ai-chat/step  # 1 LLM turn or tool execution per request (max 10 steps)
GET  /wp-json/kadicache-pro/v1/custom-css    # Scoped Custom CSS rules + real-user RUM health
Inside the KadiCache WordPress Plugin

Built-In BYOK AI Agent & 3-Viewport CSS Lab — Plugin Interface

5 live 2x Retina plugin screens
WP Admin -> KadiCache -> AI Agent -> Chat Workspace
MODULE 18 · 2X RETINA
Clean connected chat workspace with in-chat provider/model switching across configured BYOK keys, 6 guided diagnostic workflows, and Vision screenshot paste.1000×1024 WebP
100% Source-Code Verified9 min engineering readUpdated 2026-11-29
Executive Summary · 30-Second SpecZero-Regressions Spec
WP Admin Path
WP Admin -> KadiCache -> AI Agent
Measured Impact
4 BYOK LLM Providers · 3-Viewport CSS Lab · 1-Click Rollback
Verification Marker
AiAgentController.php | AiKeyVault.php | CustomCssStore.php
  • Bring Your Own Key (BYOK) Multi-Provider Vault (AiKeyVault.php): Encrypts separate API keys for OpenAI, Anthropic Claude, Google Gemini, and OpenRouter locally via SecretBox (libsodium / AES-256-GCM) and calls provider HTTPS endpoints directly from WordPress — zero AI keys or prompts ever touch KadiCache Cloud.
  • In-Chat Active Agent & Model Switcher: Switch instantly between your configured providers and live-synced /models right above the chat composer without reopening settings.
  • Transparent Read-Only Diagnostics & Tool Traces: Auto-executes read-only tools (get_status, diagnose_url, get_settings, get_rum_analytics, inspect_page_dom, run_pagespeed_audit, simulate_settings) one step per HTTP request with collapsible millisecond timing traces, Stop cancellation, and 1-click Copy Report.
  • 3-Viewport Live CSS Lab & 1-Click Rollback (PreviewResponder.php + CustomCssStore.php): Stages non-live Custom CSS drafts, verifies Mobile (390px), Tablet (820px), and Desktop (1440px) via signed preview URLs, requires explicit admin approval before publishing, and writes an atomic McpCheckpoints snapshot (cp_...).
Table of Contents (4 sections)

Why Performance Debugging Belongs Inside WP Admin (With Guardrails)#

Chasing down why a mobile menu broke under Delay JS, why a WooCommerce category page returned X-KadiCache: MISS, or why a hero slider shifts layout by 0.18 CLS normally requires juggling browser DevTools, server logs, cache diagnostics, and manual CSS edits across three screen sizes. Pasting raw HTML snippets into an external chat tab gives an LLM zero visibility into your live WordPress cache headers, active exclusions, or real-user RUM histograms.

KadiCache Pro AI Agent (WP Admin -> KadiCache -> AI Agent) brings a guarded, tool-enabled performance engineer directly inside your WordPress dashboard. Unlike opaque SaaS AI wrappers that mark up token costs or route your site diagnostics through third-party proxies, KadiCache AI Agent is 100% BYOK: your WordPress server speaks directly to OpenAI, Anthropic, Google Gemini, or OpenRouter using your own encrypted API key.

FIG 01Connected status badge, in-chat Active Agent provider and model selector, 6 guided diagnostic starters, and Vision screenshot inputZoom 2x

Multi-Provider Encrypted BYOK Vault (AiKeyVault.php & AiProviderClient.php)#

You do not have to lock your team into a single AI vendor. AiKeyVault.php stores encrypted keys per provider inside encrypted_keys_by_provider, validates key prefixes (sk-or-, sk-ant-, AIza / AQ.) to prevent pasting a key into the wrong provider card, and calls strictly allowlisted HTTPS endpoints (wp_safe_remote_post with sslverify => true and redirection => 0):

ProviderOfficial HTTPS Endpoint (AiProviderClient::ENDPOINTS)Live Model DiscoveryVision Support
OpenAIhttps://api.openai.com/v1/chat/completions/v1/models live syncAuto + manual override
Anthropic Claudehttps://api.anthropic.com/v1/messages/v1/models live syncAuto + manual override
Google Geminihttps://generativelanguage.googleapis.com/v1beta/models//v1beta/models live syncAuto + manual override
OpenRouterhttps://openrouter.ai/api/v1/chat/completions/api/v1/models live syncAuto + manual override

Once you save one or more provider keys in API & Models, the setup banner disappears automatically, the header switches to a green Connected badge, and the Active Agent dropdown in Chat lists only providers with verified keys so you can switch models mid-workflow.

FIG 02Storing encrypted keys per provider across OpenAI, Anthropic Claude, Google Gemini, and OpenRouter with live model discoveryZoom 2x

Step-by-Step Execution, Live Tool Traces & Zero Shared-Host Timeouts#

Traditional PHP plugins that run a multi-turn LLM loop inside a single HTTP request routinely hit 30-second or 60-second Nginx/Cloudflare gateway timeouts (HTTP 502 / 504). AiAgentController::restChatStep() avoids timeouts architecturally by executing exactly one LLM turn or one tool call per REST request (MAX_STEPS_PER_PROMPT = 10), returning structured JSON error payloads instead of raw 502 responses, and supporting instant client cancellation via AbortController (Stop).

Every assistant reply surfaces a collapsible Used X tools · Y ms execution trace listing each tool name and exact latency in milliseconds alongside a 1-click Copy Report button for client tickets or agency handoffs.

FIG 03Expanded 3-tool execution trace with millisecond timings, formatted cache diagnostics, and Copy Report buttonZoom 2x

Vision Screenshots, 3-Viewport CSS Drafts & Atomic 1-Click Rollback#

  • In-Memory Vision Screenshots (AiProviderClient::validateImage()): Paste (Ctrl+V) or attach a PNG, JPEG, or WebP screenshot (verified via magic bytes up to 1.2 MB). Image bytes stay strictly in request memory and are never written to disk.
  • 3-Viewport Non-Live Draft Verification (PreviewResponder.php): Before proposing a CSS layout fix, AI Agent stages a non-live draft via manage_custom_css(action: "stage_draft") and runs run_viewport_lab against signed preview URLs at Mobile (390px), Tablet (820px), and Desktop (1440px) to check overflow, element overlaps, CLS, and console errors.
  • Human-Approved Mutations & Scoped Custom CSS (CustomCssStore.php): No setting change or CSS publication executes silently. Every mutating tool renders an interactive approval card, records an atomic McpCheckpoints rollback checkpoint (cp_...), and injects published CSS rules cleanly after Cloud Remove Unused CSS (RUCSS) inside Early Cache.
FIG 04Managing allowlist-sanitized Custom CSS rules with Early Cache compatibility and 1-click rollback checkpointsZoom 2x

Ready to configure your keys and run your first diagnostic? Follow the illustrated AI Agent Step-by-Step Setup & Usage Guide.

Gergis — Lead Systems & Cache Architect
Principal WordPress & Cloud Edge Architect
E-E-A-T Source Verified

Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.

apps/wordpress-plugin-pro/src/Ai/AiAgentController.phpapps/wordpress-plugin-pro/src/Ai/AiKeyVault.phpapps/wordpress-plugin-pro/src/Ai/AiProviderClient.phpapps/wordpress-plugin-pro/src/Ai/PreviewResponder.phpapps/wordpress-plugin-pro/src/CustomCss/CustomCssStore.php

Technical FAQ

Is AI Agent available in KadiCache Free Core?

KadiCache Free Core displays a read-only AI Agent overview tab inside WP Admin so you can inspect its capabilities before upgrading. Live AI Agent execution, multi-provider BYOK vault storage, 3-viewport CSS lab verification, and scoped Custom CSS rules require an active KadiCache Cloud Pro connection.

Do I pay KadiCache per token or prompt to use AI Agent?

No. AI Agent is strictly Bring Your Own Key (BYOK). You pay your chosen AI provider (OpenAI, Anthropic, Google Gemini, or OpenRouter) directly at standard API rates with zero KadiCache token markup.

Can I keep API keys saved for both Gemini and OpenRouter at the same time?

Yes. AiKeyVault stores encrypted keys separately per provider in encrypted_keys_by_provider. Saving a second provider never overwrites existing keys, and you can switch between configured providers directly from the Active Agent bar in Chat.

How are Custom CSS rules published by AI Agent protected against breaking the site?

Every rule is allowlist-sanitized, scoped to exact or wildcard paths (such as / or /product/*), staged first as a non-live draft for 3-viewport verification, gated behind manual admin approval, and paired with a 1-click McpCheckpoints rollback checkpoint.