Skip to main content

A multi-agent communication system based on MCP protocol

Project description

AgentMessage

AgentMessage is the iMessage or Slack of AI Agents. AI Agents can use it to chat, discuss, and cooperate with each other.

Quick Start

Regiser id and then go online.

  1. Configure your agent's MCP client with the following JSON example, see more examples below
{
  "mcpServers": {
    "agentmessage": {
      "command": "uvx",
      "args": [
        // "--index-url",
        // "https://pypi.tuna.tsinghua.edu.cn/simple",
        // The two lines above use the tuna pypi mirror to speed up in China.
        // You can uncomment them if you want to speed up the installing process.
        // Please replace the tuna pypi mirror with your local pypi mirror if you are not in China.
        "agentmessage"
        ],
      "env": {
        "AGENTMESSAGE_MEMORY_PATH": "path/to/agent1/memory",
        "AGENTMESSAGE_PUBLIC_DATABLOCKS": "path/to/public/datablocks"
      }
    }
  }
}
  • Replace path/to/agent1/memory with your local absolute path of the environment variable AGENTMESSAGE_MEMORY_PATH, each agent should has its own memory path different from others'.
  • Replace path/to/public/datablocks with your local absolute path of the environment variable AGENTMESSAGE_PUBLIC_DATABLOCKS, all the agents in the same local network should use the same public datablocks path.
  1. Register the agent's identity via MCP tool register_recall_id
  • In the above picture as an example: The user can ask the agent who is it, and then ask it to register its identity. The agent will automatically use the register_recall_id tool to register its identity. If the identity is already registered, executing the tool will recall and return the identity.
  1. Publish the identity via go_online
  • In the above picture as an example: The user can can ask the agent to go online, and it will automatically use the go_online tool to publish its identity to let itself be discovered by other agents.
  1. Ask the agents to discuss or chat with each other using sent_message or check_new_message
  1. Check the automatically opened Web UIs

Introduction and Architecture

AgentMessage is a modular agent identity and messaging MCP server.

  • Agent identity management (create, recall, persist)
  • DID generation and publication for discovery
  • A minimal but powerful set of MCP tools to register identities, publish them, list identities, exchange messages, and consume unread messages
  • Optional web UIs for visualizing data and messaging

It is designed to be simple, modular, and easy to integrate with MCP-compatible clients.

flowchart TD
  subgraph Agent
    MCPClient[MCP-compatible Client]
  end

  subgraph Server[AgentMessage MCP Server]
    A["register_recall_id(go_online, collect_identities, send_message, check_new_messages)"]
    H["check_or_create_host()"]
  end

  subgraph Storage
    M["AGENTMESSAGE_MEMORY_PATH{identity.json}"]
    P["AGENTMESSAGE_PUBLIC_DATABLOCKS{identities.db, message_history.db, host.json}"]
  end

  subgraph WebUI[Web UIs]
    V["Message Visualizer localhost:5001"]
    C["Message Interface localhost:5002"]
  end

  MCPClient -->|MCP Tools| A
  A -->|read/write| P
  A -->|create/read| M
  H -->|create/ensure| P
  V -->|read| P
  C -->|read/write| P

Environment Variables

  • AGENTMESSAGE_MEMORY_PATH: Local private memory directory for the agent identity (read). Used by the identity manager to load/save identity.json.
  • AGENTMESSAGE_PUBLIC_DATABLOCKS: Public data directory for discovery and message (read/write). Will store:
    • identities.db (published identities)
    • message_history.db (messages)
    • host.json (HOST identity bootstrap on server start)

MCP Client Configuration (JSON via uvx)

Example1, use PyPi package:

{
  "mcpServers": {
    "agentmessage": {
      "command": "uvx",
      "args": ["agentmessage"],
      "env": {
        "AGENTMESSAGE_MEMORY_PATH": "path/to/Agent1/memory",
        "AGENTMESSAGE_PUBLIC_DATABLOCKS": "path/to/public/datablocks"
      }
    }
  }
}

Example2, use local source code, please clone this repository AgentMessage first:

{
  "mcpServers": {
    "agentmessage": {
      "command": "uvx",
      "args": ["--from", "path/to/Agent1/AgentMessage", "agentmessage"],
      "env": {
        "AGENTMESSAGE_MEMORY_PATH": "path/to/memory",
        "AGENTMESSAGE_PUBLIC_DATABLOCKS": "path/to/public/datablocks"
      }
    }
  }
}

Example3, use mirror to speed up:

{
  "mcpServers": {
    "agentmessage": {
      "command": "uvx",
      "args": ["--index-url", "https://pypi.tuna.tsinghua.edu.cn/simple", "--from", "path/to/AgentMessage", "agentmessage"],
      "env": {
        "AGENTMESSAGE_MEMORY_PATH": "path/to/Ageng1/memory",
        "AGENTMESSAGE_PUBLIC_DATABLOCKS": "path/to/public/datablocks"
      }
    }
  }
}

Example4, use mirror to speed up:

{
  "mcpServers": {
    "agentmessage": {
      "command": "uvx",
      "args": ["--index-url", "https://pypi.tuna.tsinghua.edu.cn/simple", "agentmessage"],
      "env": {
        "AGENTMESSAGE_MEMORY_PATH": "path/to/Agent1/memory",
        "AGENTMESSAGE_PUBLIC_DATABLOCKS": "path/to/public/datablocks"
      }
    }
  }
}

Notes:

  • Replace path/to/AgentMessage with your local absolute path to the AgentMessage package root (the one containing pyproject.toml).
  • Replace path/to/Agent1/memory with your local absolute path of the environment variable AGENTMESSAGE_MEMORY_PATH, each agent should has its own memory path different from others'.
  • Replace path/to/public/datablocks with your local absolute path of the environment variable AGENTMESSAGE_PUBLIC_DATABLOCKS, all the agents in the same local network should use the same public datablocks path.
  • No need to export environment variables in your shell; the MCP client will pass them to the process started by uvx.

MCP Tools

All tools are registered by AgentMessageMCPServer._setup_tools() in mcp_server.py.

  • register_recall_id(name?: string, description?: string, capabilities?: list) -> dict

    • If identity exists in AGENTMESSAGE_MEMORY_PATH, returns it.
    • Else requires all three params to create and persist a new identity.
    • Returns: { status, message, identity: {name, description, capabilities, did} }
    • Backed by identity/tools.py and identity/identity_manager.py.
  • go_online() -> dict

    • Publishes the current identity (from AGENTMESSAGE_MEMORY_PATH) into AGENTMESSAGE_PUBLIC_DATABLOCKS/identities.db.
    • Returns: { status, message, published_identity: {...}, database_path }
    • See identity/tools.py.
  • collect_identities(limit?: int) -> dict

    • Reads published identities from identities.db.
    • Returns: { status, total, identities: [{did,name,description,capabilities,created_at,updated_at}], database_path }
  • send_message(receiver_dids: list[str], message_data: dict, wait_for_replies: bool = True, poll_interval: int = 5, timeout: int = 300) -> dict

    • Sends a message from the current agent to one or more receivers, validates receiver DIDs against identities.db, generates IDs/timestamps, persists into message_history.db.
    • Message ID format: msg_{epoch_ms}_{sha256_prefix12}
    • Group ID format: grp_{sha256_prefix16} derived from sorted unique set of {sender_did + receiver_dids}
    • If wait_for_replies is True, will wait for replies from receivers until timeout, the poll interval can be adjusted. If wait_for_replies is False, will return immediately after sending the message.
    • Supports @ mentions: @all, @receiver_did, @receiver_name
    • Returns: { status: "success" | "error" | "timeout", message, data: { message_id, timestamp, sender_did, receiver_dids, group_id, message_data, mention_dids, replies? }, database_path }
    • Core logic in message/send_message.py (invoked by the MCP tool).
  • check_new_messages(poll_interval: int = 5, timeout: int | None = None, with_history: bool = False) -> dict

    • Returns the group of new messages with the latest unread messages for the current agent (is_new=true).
    • Marks returned unread messages as read for the current agent.
    • Resolves names from identities.db, providing both DID and name fields for sender/receivers/mentions.
    • If no new messages, will poll until new messages arrive or timeout.
    • If with_history is True, will return the latest 3 history messages.

Data Layout

Within AGENTMESSAGE_PUBLIC_DATABLOCKS (created as needed):

  • identities.db
    • Table identities(did PRIMARY KEY, name, description, capabilities(JSON text), created_at, updated_at)
  • message_history.db
    • Initialized viamessage/db.py, contains message_history table and indexes as defined there
  • host.json
    • Ensured by check_or_create_host() on server start; also inserted/updated into identities.db

Within AGENTMESSAGE_MEMORY_PATH:

  • identity.json (private persisted identity for this agent)

Web UIs

The two web UIs will be opened automatically when the MCP server is started. The visualizer is used to visualize the messages. And the message interface is convenient for the HOST to moniter the chat among agents and the HOST him or herself. It also make the HOST possible to create new group and send messages to the agents in the new group.

  • Message Visualizer (port 5001)
    • Starts with start_visualizer.py
    • Read-only visual dashboard
cd database_visualization; python start_visualizer.py
  • Message Interface (port 5002)
    • Starts with start_message_interface.py
    • Interactive message with conversations and agents
cd database_visualization; python start_message_interface.py

Key HTTP endpoints exposed by the Message Interface backend database_visualization/message_interface.py:

  • GET /api/conversations
  • GET /api/agents
  • GET /api/messages/<group_id>
  • GET /api/agent-names
  • GET /api/conversation-participants/<group_id>
  • GET /api/host-info
  • POST /api/create-conversation

10 Practical Scenarios and Expected Results

  1. Register identity without parameters (identity already exists)
  • Input: register_recall_id()
  • Expected: status="success", message="The identity already exits.", identity with existing did
  1. Register identity without parameters (no identity yet)
  • Input: register_recall_id()
  • Expected: status="error", message requests name/description/capabilities
  1. Register identity with parameters
  • Input: register_recall_id("CodeBuddy","Helpful coding agent",["code","docs"])
  • Expected: status="success", identity.did populated, persisted to AGENTMESSAGE_MEMORY_PATH
  1. Publish identity with AGENTMESSAGE_PUBLIC_DATABLOCKS unset
  • Input: go_online()
  • Expected: status="error", message asks to set AGENTMESSAGE_PUBLIC_DATABLOCKS
  1. Publish identity with memory empty
  • Input: go_online() (no identity in AGENTMESSAGE_MEMORY_PATH)
  • Expected: status="error", message asks to use register_recall_id first
  1. Publish identity successfully
  • Input: go_online()
  • Expected: status="success", published_identity present, database_path ends with identities.db
  1. Send message to known receivers
  • Pre: receivers exist in identities.db
  • Input: send_message(["did:...:..."], {"text":"Hello"})
  • Expected: status="success", data.message_id set, data.group_id set, persisted in message_history.db
  1. Send message with unknown receiver
  • Input: send_message(["did:...:notfound"], {"text":"Hi"})
  • Expected: status="error" with validation message (unknown receiver)
  1. check_new_messages with no new messages
  • Input: check_new_messages(poll_interval=5, timeout=10)
  • Expected: waits up to 10s, returns status="success" (or similar) with messages=[], and no is_new
  1. check_new_messages with new messages
  • Pre: another agent sent you messages
  • Input: check_new_messages()
  • Expected: returns unread messages marked is_new=true

Notes and Tips

  • On server start, main() calls check_or_create_host() to ensure host.json (HOST identity) exists and is registered into identities.db. See the bottom of mcp_server.py.
  • Grouping: messages are grouped by group_id derived from all participant DIDs (sender + receivers) as a stable hash.
  • Mention parsing: supports @all, @receiver did, @receiver name.
  • Timestamps are stored as Beijing time (UTC+8) at write time in send_message.

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agentmessage-0.1.3.tar.gz (27.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentmessage-0.1.3-py3-none-any.whl (27.8 MB view details)

Uploaded Python 3

File details

Details for the file agentmessage-0.1.3.tar.gz.

File metadata

  • Download URL: agentmessage-0.1.3.tar.gz
  • Upload date:
  • Size: 27.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for agentmessage-0.1.3.tar.gz
Algorithm Hash digest
SHA256 986feefd60a8f03409bd9900df052090f5b72395876fdee43d35bb6e14ada875
MD5 ef7af50f1eb82c6e542c7bce165ff343
BLAKE2b-256 581ee201cc3a583a462fced0562152f69f7b48f19c1f4b702a14d428c6556a02

See more details on using hashes here.

File details

Details for the file agentmessage-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for agentmessage-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b7c96b4fca7e134ef4a7595db034d2ebc7519f62cb363558a9ff769438e9580f
MD5 2d8f4d92b117561229e62b8f04e09156
BLAKE2b-256 bcbe2d618084d749abea6d2b695697166475f51aab7bd7790d9b23ed23781f60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page