Mersenne Prime Sub-Agent (Rust)
This subdirectory contains the local Rust sub-agent implementation for prime calculation. It is designed to run as an independent web service that implements the Agent-to-Agent (A2A) protocol.
The agent is responsible for executing heavy prime-checking computations (specifically checking exponents for Mersenne primes using the Lucas-Lehmer test) and returning the results back to the master coordinator.
Table of Contents
Architecture & Features
- Asynchronous Axum Server: Built with the
axumweb framework and run ontokiofor efficient, asynchronous network handling. - Offloaded Calculations: Prime-checking calculations are offloaded to Tokio's blocking thread pool (
tokio::task::spawn_blocking) to keep the HTTP server responsive under heavy computing loads. - Lucas-Lehmer Test: Performs primality tests on exponents using arbitrary-precision arithmetic provided by the
num-bigintcrate. - Agent Card Auto-Discovery: Serves the
.well-known/agent-card.jsonmetadata file, allowing coordinator agents to auto-discover capabilities. - State Check: Tracks calculation concurrency using atomic flags to prevent concurrent compute runs.
API Endpoints
The agent exposes the following HTTP endpoints:
| Endpoint | Method | Description |
|---|---|---|
/health |
GET |
Simple health check endpoint that returns OK. |
/.well-known/agent-card.json |
GET |
Returns agent metadata, skills, and configuration information. |
/.well-known/agent.json |
GET |
Alias to the agent card endpoint. |
/ |
POST |
The entry point for A2A JSON-RPC messages. |
A2A JSON-RPC Protocol
Sub-agents communicate via standard JSON-RPC 2.0. The master agent requests calculations or health checks by posting to the root (/) path using the message/send method.
1. Calculation Request
To request a primality check on an exponent, send a payload containing the exponent number.
- Payload:
- Success Response (Mersenne Prime Found):
- Success Response (Not Prime):
2. Status Request
Used by the master coordinator to verify if the agent is idle or currently busy with another calculation.
- Payload:
- Response:
Returns
"ready"if idle, or"not ready"if a computation is active.
Development Commands
All standard development actions can be performed using the local Makefile:
# Build the sub-agent project
# Run the agent in the foreground (Ctrl+C to quit)
# Start the agent in the background (logs to local_agent.log, PID to local_agent.pid)
# Stop the background agent
# Check status of the agent process and query its health endpoint
# Fetch the Agent Card (well-known metadata)
# Send an A2A JSON-RPC status check query to the running agent
# Run tests
# Format the code base
# Lint the codebase (Clippy & format check)
# Clean build files and background process artifacts
Configuration
The agent behavior is configured via environment variables:
PORT: The port on which the server listens (defaults to8104).MODEL_NAME: Optional name of the underlying model / agent executor.PUBLIC_URL: Public-facing address used when generating the agent card metadata.