OpenClaw is an agent framework, and AgenticMail needs to work inside it seamlessly. Not as an afterthought bolted on through generic HTTP tools, but as a native plugin that participates in the agent lifecycle. The @agenticmail/openclaw package is that integration.
The plugin manifest declares 52 tools. These cover the same surface as the MCP server (mail operations, contacts, tasks, storage, SMS) but adapted to OpenClaw’s tool interface. The key difference is that OpenClaw plugins can also hook into agent lifecycle events, which opens up capabilities that a standalone MCP server can’t provide.
The hook system
OpenClaw plugins can register hooks that fire at specific points in the agent lifecycle. AgenticMail uses two of them.
before_agent_start
This hook fires just before a new agent spins up. AgenticMail uses it for automatic sub agent provisioning. When a main agent spawns a sub agent, the hook intercepts the startup, creates a new email account for the sub agent, configures its mailbox, and injects the credentials into the sub agent’s environment.
The sub agent comes online with a working email address already provisioned. It doesn’t need to call a setup tool or wait for manual configuration. This is critical for task workflows where the main agent spawns several sub agents to handle different parts of a job. Each one needs its own isolated mailbox, and that provisioning has to happen before the sub agent starts doing work.
The hook also handles cleanup. When a sub agent shuts down, its email account can be deactivated or archived based on the configured retention policy. No orphaned mailboxes accumulating over time.
before_tool_call
This hook fires before every tool invocation across the agent’s session. AgenticMail uses it to inject notification context. If new emails have arrived since the last tool call, the hook prepends a notification to the tool call context so the agent is aware of pending messages.
This is subtle but important. Without it, an agent would only know about new email when it explicitly checks. With the hook, the agent gets a gentle nudge every time it does anything: “By the way, you have 3 unread messages from the last 10 minutes.” The agent can choose to handle them immediately or continue with its current task.
The channel plugin
OpenClaw has a channel system for persistent communication streams. AgenticMail registers as a channel plugin, which means it can provide a continuous flow of incoming messages to the agent rather than requiring the agent to poll.
Under the hood, the channel plugin runs an IMAP poller that watches the agent’s mailbox. When new mail arrives, it flows through the channel into the agent’s message queue. The agent processes incoming emails the same way it processes any other channel message, whether that’s Slack, Discord, or a custom source.
The channel abstraction means agents don’t need email specific code to receive messages. A multi channel agent can handle email, chat, and webhooks through the same message processing pipeline.
The monitor service
The plugin includes a monitor service that tracks the health of the email infrastructure. It periodically verifies IMAP connectivity, checks outbound SMTP delivery, and reports metrics back to the OpenClaw dashboard.
If the email server goes down or credentials expire, the monitor catches it and surfaces the issue through OpenClaw’s alerting system. Agents that depend on email get notified that their channel is degraded, so they can switch to fallback communication methods or queue outbound messages for later delivery.
SSE watcher for the main agent
The main agent (the one that orchestrates sub agents) gets a dedicated SSE watcher. Instead of polling the API for sub agent status updates and task completions, the main agent opens an SSE connection and receives events in real time.
The SSE watcher handles new email notifications, task state changes, sub agent health events, and delivery confirmations. This keeps the main agent responsive without hammering the API with polling requests.
Auto spawn modes
When the main agent decides to delegate a task, it can specify one of four auto spawn modes:
Light mode gives the sub agent basic email capabilities: send, receive, search. Minimal resource footprint. Good for simple tasks like sending a notification or checking for a specific message.
Standard mode adds features like templates, scheduling, and contact management. This is the default for most tasks.
Full mode enables everything, including storage, SMS, and advanced filtering. For sub agents that need to run complex, multi step workflows independently.
Async mode is special. The sub agent gets provisioned but doesn’t start immediately. Instead, it waits for an activation signal, typically an incoming email or task assignment. This is useful for setting up agents that should exist and be reachable by email but only wake up when contacted.
Each mode maps to a different set of enabled tools and resource limits. Light mode sub agents consume less memory and fewer API connections than full mode ones. When you’re running dozens of sub agents, these resource differences matter.
The OpenClaw plugin is where AgenticMail stops being a standalone email service and becomes part of a larger agent ecosystem. The hooks, channels, and auto provisioning turn email from something agents use into something that’s woven into how they operate.