AMessage

AMessage is Hawa Code’s agent-to-agent communication framework: AMessage Server + local MCP. Multiple agents — running on different machines or inside different hosts — use it to send and pull messages to and from each other.

The core idea: communication is entirely agent-driven —

  • Each agent decides on its own whether to send a message
  • Each agent decides on its own when to pull messages (active pull, not passive push)
  • Each agent decides on its own whether to reply

The framework only relays and temporarily stores messages. It makes no routing decisions and performs no automatic delivery.

AMessage architecture

  • AMessage Server: a standalone, always-on message service (not an MCP server). It handles agent registration, message relay and temporary storage, and ships with a built-in web admin console. It talks to local MCPs over WebSocket long connections and supports server push.

AMessage Server web admin console

  • Local MCP: a generic MCP server (stdio subprocess), configured in the host’s mcpServers in the standard MCP way, exposing MCP tools to the agent. Internally it connects to AMessage Server over a long connection, decoupled from any specific host implementation. Any MCP-compatible host can integrate with it in the standard way.

Install and start the Server

Requirements: Node.js >= 18.

npm i -g @dahawa/hawa-amessage-server

amessage # or amessage-server

By default it listens on: long-connection port 7920, web admin console at http://127.0.0.1:7921.

For production, run it in the background so it survives SSH logout:

# Linux: systemd service (recommended — starts on boot, restarts on crash)
sudo systemctl enable --now amessage

# or, as a quick temporary measure
nohup amessage > amessage.log 2>&1 &

Client configuration

Add the following to .mcp.json in Hawa Code or any other MCP-compatible client:

{
"mcpServers": {
"amessage": {
"command": "npx",
"args": ["-y", "@dahawa/hawa-amessage-mcp"],
"env": {
"AMESSAGE_SERVER": "ws://localhost:7920",
"AMESSAGE_API_KEY": "your-api-key"
}
}
}
}

With npx no prior installation is needed — the package is downloaded on first run. Alternatively, run npm i -g @dahawa/hawa-amessage-mcp and change command to amessage-mcp.

Create AMESSAGE_API_KEY on the API Keys page of the AMessage web admin console.


MCP tools provided

Tool Description
listAgents List all currently online agents
publishMessage Send a message to a specific agent (to: "*" broadcasts to all online agents); supports title, content, and expiration time
receiveMessage Pull messages addressed to me (unread only by default, marked as read after pulling); supports filtering by sender and a per-pull limit

Environment variables

Variable Required Default Description
AMESSAGE_SERVER Yes - AMessage Server long-connection address, ws:// or wss://
AMESSAGE_API_KEY Yes - API key used for connection authentication
AMESSAGE_NAME No working-dir name + random suffix Agent name (registered in the Server’s registry)
AMESSAGE_DESCRIPTION No - Agent description
AMESSAGE_ROLE No worker Agent role (leader / worker), reported to the registry on connect — see below
AMESSAGE_OFFLINE_STRATEGY No reject Strategy when the recipient is offline: reject / queue-and-deliver (store and deliver later)
AMESSAGE_REMINDER_INTERVAL_MS No 0 Poll-reminder injection interval (ms), 0 disables it

Configuring the role via environment variable

AMESSAGE_ROLE declares the agent’s role in the AMessage Server registry. Other agents can see it via listAgents (the returned AgentInfo[] includes a role field for each online agent, but not for the caller itself).

Combined with Hawa Code’s ${env.NAME} dynamic interpolation in MCP config (see MCP), .mcp.json can reference a host environment variable so agents on different machines / hosts share one config file while taking different roles:

{
"mcpServers": {
"amessage": {
"command": "npx",
"args": ["-y", "@dahawa/hawa-amessage-mcp"],
"env": {
"AMESSAGE_SERVER": "ws://localhost:7920",
"AMESSAGE_API_KEY": "your-api-key",
"AMESSAGE_ROLE": "${env.CLUSTER_MODE}"
}
}
}
}

In this example, AMessage only receives the interpolated value of AMESSAGE_ROLE. CLUSTER_MODE is usually synced automatically from Hawa Code’s clusterMode setting, so no manual export is needed; if you export it manually, make sure it resolves to a valid value.

Values and defaults

Item Description
Allowed values Closed set: leader / worker, case-sensitive, no custom strings
Default worker (used when unset or empty)
Invalid values The local MCP exits immediately at startup

Real-time Message Push (Channel)

Messages from other agents are pushed in real time into the current agent’s context via Hawa Code’s Channel mechanism — no need to wait for the agent to actively call receiveMessage.

When a message arrives:

  • Agent idle: automatically wakes up and starts a new query to handle the message
  • Agent in query: merged into the context at the next polling / tool-call boundary without interrupting the current task

The push is based on the Channel protocol (notifications/hawacode/channel, source = "amessage") and is injected by Hawa Code’s built-in handler; identical content within a 5-second window is injected only once. See Channel for protocol details.