This plugin follows the portable hexagonal architecture documented in the wpscholar/standards repository.
- Architecture standard (full)
- ADR 0008 — Portable PHP Application Architecture
- Plugin standards (PHP version, CI, tooling)
For non-trivial features:
src/
├── Domain/ pure PHP. No WordPress. Value objects, entities, domain logic.
├── Application/ use cases (command/handler). Orchestrates Domain + Contracts.
├── Contracts/ interfaces at framework boundaries (Mailer, Clock, repositories).
├── Infrastructure/ concrete adapters implementing Contracts using WordPress APIs.
└── WordPress/ hooks, REST controllers, admin pages, CLI, blocks. Thin glue.
Dependencies point inward. Domain knows nothing about WordPress. WordPress integration delegates to Application handlers.
Use the architecture when the plugin has business rules, non-trivial persistence, external API calls, a reasonable expected lifespan, plans for reuse in Laravel or another runtime, or non-trivial test coverage requirements.
Skip it for tiny plugins (a filter, a single admin tweak, a one-action utility). The template doesn't enforce the layout — adopt the architecture when scope warrants it.
If the code answers "what should happen?" → Domain/Application. If the code answers "how does WordPress do it?" → Infrastructure / WordPress.
WP_Post,WP_User,wpdb,get_option()insrc/Domain/orsrc/Application/.- Hook callbacks containing real business logic instead of delegating to an Application handler.
- Global state (
global $wpdb;) inside Application services. - Service locator pattern instead of constructor injection.
See the canonical references above for examples and patterns (Command/Handler, Repository, Adapter, Service Provider, Factory, DTO, Strategy, Policy).
Gutenberg is experimenting with a wp_knowledge post type, typed by a wp_knowledge_type taxonomy (guideline, memory, note), for content AI features read (gutenberg#77230). It is not in core, and as of October 2026 it is not planned for the near term, so Agent Studio never depends on it and does not read site guidelines.
- Agent Studio stores what agents know the same way: post type
agent_studio_kb(title, excerpt as the description, content, author, revisions) typed by theagent_studio_kb_typetaxonomy. Skills are theskilltype today; memories and notes would be further types. Post type keys are limited to 20 characters, hencekb. WordPressSkillRepositoryreads only theskilltype. If core ships Knowledge, a secondSkillRepositoryadapter can read it instead.- The stock post screens are hidden for knowledge (
show_uifalse). People use Agents → Skills, which explains the fields in plain language.
- Agents stay a post type (
agent_studio_agent): title is the name, content the instructions, settings JSON in post meta. The post status is the agent's status:draft(being set up),publish(active), and the registeredagent_studio_paused.Infrastructure\AgentPostStatusmaps between them; content version 3 moved the oldstatussetting into the post status. - The stock list and editor are replaced by the React Agents screen (
assets/src/agents), backed byRest\AgentsController.Admin\OldScreensredirects old links (edit.php,post.php,post-new.php, and the oldedit.php?page=…addresses) to the new screens. - Lists that can grow without limit (triggers, abilities) are searched and paged on the server by
Rest\CatalogController(/triggers,/abilities). The screen never loads the full list. Agents\Readinesschecks the site on each request; nothing about it is cached.
Domain\Connection\Connectionis a service agents can use. Its non-secret settings, status and last-known tools are JSON in post meta on the privateagent_studio_connpost type. Secrets never go there: they go throughContracts\SecretStore.Contracts\Connection\ConnectionTypeis the extension point. Agent Studio ships the MCP server type (WordPress\Connections\McpConnectionType); plugins add theirs onagent_studio_register_connection_types. The type declares setup fields asDomain\Setup\SetupFielddata, so the Connections screen draws its form without knowing the type. Auth (none, API key, OAuth) is handled once for every type byApplication\Connections\ConnectionService.Application\Mcp\McpClientis a small Streamable HTTP client overContracts\Http\HttpClient(WordPress HTTP API in production, a fake in tests). It speaks MCP 2026-07-28 and falls back to the 2025 initialize/session handshake when a server answers like an older one. We wrote our own because the PHP SDKs either have no client OAuth, pull large dependency trees that would need namespace prefixing in a plugin, or call curl directly (bypassing proxies and test mocks).Application\OAuthfollows the MCP authorization spec: protected resource metadata (RFC 9728), authorization server metadata with exact issuer match, PKCE S256 required,resourceon authorize and token requests (RFC 8707),isschecked on return (RFC 9207). Client identity, in order: a client ID the person entered, this site's client ID metadata document (HTTPS sites only), dynamic registration, otherwise the screen asks the person to register an app and shows the callback address to paste.Application\Connections\ConnectionAbilityGatewayoffers connection tools to agents asmcp-<slug>/<tool>, from the stored tool list so building an agent's tools never waits on the network.Application\Execute\CompositeAbilityGatewaymerges it with the Abilities API gateway. Tool hints are untrusted: onlyreadOnlyHintlowers the risk, unmarked tools count as external.Infrastructure\Secrets:CoreSecretStoreuseswp_set_secret()/wp_get_secret()when WordPress has them;EncryptedOptionSecretStoreis the fallback (libsodium secretbox, one non-autoloaded option per secret, key fromAGENT_STUDIO_SECRETS_KEYorwp_salt('secure_auth')).SecretStoreFactory::migrateToCore()moves secrets over onadmin_initonce core supports it.
Domain\Channel\Channelis a place people talk to an agent or get notified (privateagent_studio_chanposts; the author is the owner).Contactis someone who wrote to it (tableagent_studio_contacts): pending, allowed or blocked, optionally linked to a WordPress user by a one-time pairing code.Contracts\Channel\ChannelTypeis the extension point (agent_studio_register_channel_types). A type declares capabilities (receive, reply, notify, approve), setup asDomain\Setup\SetupSteps with instructions and fields, and does the service-specific work: activate (for example register a webhook), verify and parse inbound requests, send messages with buttons. Agent Studio ships Telegram and ntfy inWordPress\Channels.- Inbound:
POST /agent-studio/v1/channels/{id}/inboundis public; the type verifies the request (Telegram: a secret header derived from the bot token).Application\Channels\InboundHandlerapplies the access rules, opens or continues the conversation, records the message and dispatches amessagerun (deduplicated on the service's message id). Button presses resolve approvals only for contacts linked to a user whoApprovalPolicy::canApprove(). Domain\Conversation\ConversationWindowdecides what the agent sees: the newest messages up to 20 and about 24,000 characters, the rest folded into a running summary; 24 hours of quiet closes the conversation.Application\Conversations\ConversationServicebuilds the opening transcript of a message run and writes the summary with the agent's own model.Contracts\RunObserveris told when a run stops.ConversationRepliessends the answer (or a failure, or "waiting for approval" with buttons when the person may decide) back to the chat.- Approvals:
CompositeNotifieremails (site admin and the agent's owner) andChannelNotifiermessages every notification channel whose owner may approve. Buttons are signed byApprovalTokens: short values for chat callbacks (bound to the run, the pending call and the decision), and full-length signed links for channels that can only call a URL (ntfy), also bound to the channel and its owner. - Chat text Agent Studio itself writes goes through
Contracts\Channel\ChannelPhrases, so it is translated even though the Application layer has no WordPress i18n. - Some channel types need the channel to exist before setup can finish (Slack's app manifest must contain this channel's own addresses). They implement
Contracts\Channel\GuidedSetup: the Add screen saves the name and agent, and the channel's page shows the type's follow-up steps (links, fields, a Connect button) until it is switched on. Types connected by signing in implementContracts\Channel\AuthorizesWithOAuth;ChannelService::beginAuthorization()/finishAuthorization()handle the single-use state (bound to the user), the return address (admin-post.php?action=agent_studio_channel_connected) and storing the returned secrets. - Slack checks every request with the app's signing secret (
v0HMAC, five-minute window). The one exception is Slack's URL check while the app is being created, before the signing secret is saved: the challenge is echoed and nothing else happens.
TriggerType::Customtriggers carry the event key in their config (kind).Contracts\Trigger\TriggerDefinition(registered onagent_studio_register_triggers) gives the label, filter fields and amatches()check;DispatchTriggerHandlerapplies it on top of the Domain's key match, so the Domain stays free of plugin code.- Plugins fire events with
do_action( 'agent_studio_trigger', $key, $payload, $dedupe_key ). The payload gets the event key (trigger) and the definition's one-lineabout, which the agent sees as the first line; the rest stays inside the untrusted event block. - See
extending.mdfor examples of every extension point.