Repository navigation
Add a safely managed customer-support agent profile #2321
Description
Objective
Add a managed customer-support agent profile that trusted integrations can provision idempotently and execute through the versioned customer-agent runtime from #2320, with a customer-specific prompt pipeline and immutable safety boundaries.
This must make the selected support agent's instructions authoritative without allowing the customer browser or consuming plugin to widen tools, collections, or privileges.
Pre-flight evidence
includes/Models/Agent.php:1-18defines custom agents with prompts, models, Tier-1 tools, greetings, and iteration settings.includes/Models/Agent.php:349-394maps a selected agent's prompt toagent_system_promptand applies model/tool overrides.includes/Core/AgentLoop.php:358-369can useagent_system_prompt, butincludes/Core/AgentLoop.php:462-468locks any explicitsystem_instructioninstead.includes/REST/SessionController.php:1850-1865passes bothagent_idand a hard-coded publicsystem_instruction; the locked instruction therefore bypasses the selected agent prompt.includes/REST/SessionController.php:1951-1966contains the current fixed documentation-assistant prompt.includes/Core/SystemInstructionBuilder.php:108-128appends global advanced-companion, memory, and skill context, which must not leak into a customer support profile.includes/Abilities/PublicChatSetupAbilities.php:27-28correctly constrains the existing public setup path tosd-ai-agent/knowledge-searchonly.- Closed Add anonymous customer mode with safe tool allowlist #2176 implemented anonymous-safe gating, while closed Set up Ultimate Multisite public docs assistant #2190 was a production docs-assistant setup task; neither provides a reusable managed support-profile lifecycle.
Scope
Managed profile lifecycle
- Extend the Expose a versioned server-side customer-agent runtime #2320 runtime with an idempotent
ensure_profile/status operation keyed by a stable integration key such asultimate-multisite-support-ticketsand a profile/spec version. - Reuse the existing agent model where appropriate, but add explicit managed ownership metadata rather than guessing ownership from an agent name or numeric ID.
- Define per-field ownership:
- integration-managed safety envelope, allowed ability set, allowed knowledge collections, profile schema version, and customer mode cannot be widened in the normal agent editor;
- operator-managed provider/model, greeting/avatar/brand copy, approved collections, and bounded generation settings survive repeated provisioning unless the operator requests reset;
- document any fields intentionally reset when the integration's safety spec version increases.
- Return a customer-safe health summary: profile key/version, enabled/ready state, missing provider/model/collection reasons, safe capability list, and drift status. Never return raw prompts, credentials, or private collection contents to the consumer.
- Support disable, re-provision, and remove semantics without deleting unrelated custom agents or conversations.
Customer-specific prompt policy
- Introduce an explicit prompt composition path for customer agents. Required precedence:
- immutable Superdav customer-safety envelope;
- managed profile/support instructions;
- approved knowledge/citation guidance;
- bounded, sanitized request context from the trusted consumer.
- Do not use the current locked hard-coded prompt in a way that discards the profile prompt.
- Do not inherit global site-agent memories, skill indexes, advanced-companion instructions, admin page context, or normal authenticated agent defaults.
- The default support profile should:
- identify itself as an AI support assistant;
- answer from approved Ultimate Multisite documentation/knowledge and cite source titles/URLs when present;
- say when evidence is insufficient rather than inventing an answer;
- invite/escalate to a human through a structured handoff signal rather than claiming a person has been contacted;
- never claim access to private account/site data, billing, licenses, admin, files, database, users, settings, WP-CLI, memory, or internal REST tools.
- Return structured handoff intent/reason separately from display text when the model requests a human, detects account/private-data needs, or cannot answer safely.
Tool and knowledge policy
- Default to
sd-ai-agent/knowledge-searchonly. Reject meta-tools, client/browser tools, attachments, mutations, memory, skills, internal REST dispatch, and generic CLI/file/database abilities. - Compute effective abilities and collections as the intersection of Superdav's immutable customer-safe set, the managed profile policy, and current operator-approved resources. A consumer request can narrow this set but never widen it.
- Validate referenced collections exist and are public/customer-approved before marking the profile ready.
- Keep public anonymous-chat behavior backward compatible; migrate it to the shared prompt/profile primitives only when tests prove no behavior regression.
Acceptance criteria
- Provisioning the same integration/profile spec repeatedly yields one managed profile and preserves documented operator-owned fields.
- A safety-spec upgrade updates only managed fields and reports drift/reset actions.
- The executed system instruction contains the safety envelope and selected support instructions, but no global memory, skill index, advanced-companion, or admin instructions.
- Attempts to add a privileged tool/collection through consumer input or the generic agent editor fail closed.
- A missing/disabled provider, model, or collection produces a precise non-secret readiness error.
- Runtime results can include a normalized handoff signal without relying on phrase matching in generated prose.
- Existing custom agents and
/public-chat/*flows continue to work.
Reference pattern
Follow Agent model CRUD/DTO conventions and PublicChatSetupAbilities fail-closed knowledge policy, while adding explicit managed-field ownership and a customer-only prompt composer instead of overloading the global prompt builder.
Files to modify
includes/Models/Agent.phpandincludes/Models/DTO/AgentRow.php— existing agent configuration and persistence.includes/Core/AgentLoop.php— current prompt override precedence and anonymous gates.includes/Core/SystemInstructionBuilder.php— reference only; customer mode must not append private/global context.includes/REST/SessionController.php— replace the hard-coded selected-agent bypass with shared customer prompt primitives where appropriate.includes/Abilities/PublicChatSetupAbilities.php— safe knowledge-only setup reference.includes/Tools/ToolDiscovery.phpandincludes/Abilities/KnowledgeAbilities.php— effective policy enforcement.- Add focused managed-profile and customer-prompt tests under
tests/SdAiAgent/Models/,tests/SdAiAgent/Core/, and/ortests/SdAiAgent/Services/.
Verification
- Run the new managed-profile lifecycle and prompt-composition tests.
- Run
vendor/bin/phpunit --filter 'AgentTest|AgentLoopTest|SystemInstructionBuilderTest|PublicChatControllerTest|PublicChatSetupAbilitiesTest|ToolDiscoveryTest|KnowledgeAbilitiesTest'. - Run the repository PHPStan and PHPCS commands and the full PHP test suite.
Dependencies and delivery notes
- Blocked by Expose a versioned server-side customer-agent runtime #2320; implement against its final contract rather than introducing a second integration API.
- This is distinct from closed Set up Ultimate Multisite public docs assistant #2190: that issue configured one production docs embed, while this issue provides a reusable, versioned, safely managed support profile.
- Target workload:
tier:thinking, high priority, approximately 4 hours.
CI Repair Feedback (from PR #2324)
The previous worker's PR #2324 had terminal failed CI checks. The PR has been
closed and this issue re-queued for dispatch. The next worker should address these failures.
Terminal failed checks
Worker guidance
- Recover the previous PR branch/commits and continue that work; do not restart from scratch.
- Read every terminal check URL above and preserve the accumulated evidence.
- Rebase the recovered work onto current
origin/main, then fix the code rather than weakening CI. - Run every listed local check and create the replacement PR from the recovered branch.
Routed by deterministic merge pass (pulse-merge.sh).
In-place repair fallback
- Reason: the bounded PR-branch repair session exhausted its retry budget
- Retry: re-run the deterministic merge pass after restoring access to branch
feature/auto-20260724-125342-gh2321; keep PR auto-recover: orphaned worker branch for #2321 #2324 open until that retry is impossible.
Activity
superdav42 commentedon Jul 24, 2026
DISPATCH_CLAIM nonce=bf5c0bec7b3e8c009b3653656891bbd7 runner=superdav42 ts=2026-07-24T18:53:20Z max_age_s=1800 version=3.32.180 opencode_version=1.18.4 lease_token=bf5c0bec7b3e8c009b3653656891bbd7 device=device-1783824528-2609248-26808 session=issue-2321 phase=prelaunch expires_at=1784919321
superdav42 commentedon Jul 24, 2026
DISPATCH_LEASE phase=prelaunch lease_token=bf5c0bec7b3e8c009b3653656891bbd7 device=device-1783824528-2609248-26808 session=issue-2321 expires_at=1784919393 ts=2026-07-24T18:54:03Z
superdav42 commentedon Jul 24, 2026
DISPATCH_LEASE phase=prelaunch lease_token=bf5c0bec7b3e8c009b3653656891bbd7 device=device-1783824528-2609248-26808 session=issue-2321 expires_at=1784919367 ts=2026-07-24T18:54:07Z
aidevops.sh v3.32.180 automated scan.
23 remaining items
superdav42 commentedon Jul 24, 2026
DISPATCH_LEASE phase=prelaunch lease_token=e7f4a510c516f99bcbd864483179b415 device=device-1783824528-2609248-26808 session=issue-2321 expires_at=1784928504 ts=2026-07-24T21:26:24Z
aidevops.sh v3.32.180 automated scan.
superdav42 commentedon Jul 24, 2026
Dispatching worker (deterministic).
superdav42 commentedon Jul 24, 2026
DISPATCH_LEASE phase=ready lease_token=e7f4a510c516f99bcbd864483179b415 device=device-1783824528-2609248-26808 session=issue-2321 expires_at=1784935595 ts=2026-07-24T21:26:35Z
aidevops.sh v3.32.180 automated scan.
superdav42 commentedon Jul 24, 2026
CLAIM_RELEASED reason=worker_complete runner=superdav42 ts=2026-07-24T21:49:35Z aidevops_version=3.32.180 opencode_version=1.18.4
aidevops.sh v3.32.180 plugin for OpenCode v1.18.4
github-actions commentedon Jul 25, 2026
Completed via PR #2325. merged to main.