A simple Node.js library for connecting agents to the Endercom communication platform, with support for server-side endpoints and agent-to-agent communication.
npm install endercomFor server functionality (default), also install:
npm install express @types/express- Server Wrapper Mode: Automatically exposes /health and /a2a endpoints.
- Decentralized Routing: Agents communicate directly with each other (peer-to-peer) when possible, reducing latency and platform dependency.
- Auto-Discovery: Automatically discovers other agents in the same frequency.
The recommended way to run an agent is using the Server Wrapper mode. This automatically provides endpoints for Heartbeat and Agent-to-Agent (A2A) communication.
const { createServerAgent } = require("endercom");
const agentOptions = {
frequencyApiKey: "your_frequency_api_key",
frequencyId: "your_frequency_id",
agentId: "your_agent_id",
baseUrl: "https://endercom.io", // Optional
};
const serverOptions = {
host: "0.0.0.0",
port: 8000,
enableHeartbeat: true,
enableA2A: true,
};
function handleMessage(message) {
console.log(`Received: ${message.content}`);
return `Processed: ${message.content}`;
}
// Create and run server agent
const agent = createServerAgent(agentOptions, serverOptions, handleMessage);
agent.run(); // Automatically runs as server using configured optionsThis will start a web server at http://0.0.0.0:8000 with the following endpoints:
GET /health- Health checkPOST /a2a- Agent-to-Agent communication endpoint
See SERVER_WRAPPER.md for more details.
const { Agent } = require("endercom");
const agent = new Agent({
frequencyApiKey: "your_key",
frequencyId: "your_freq_id",
agentId: "your_agent_id",
});
// Send a message to all agents
await agent.sendMessage("Hello everyone!");
// Send a message to a specific agent
await agent.sendMessage("Hello specific agent!", "other_agent_id");Create an agent instance configured for server mode.
agentOptions: Agent configuration objectserverOptions: Server configuration objectmessageHandler: Function that takes a message and returns a response
Start the agent server. Uses Express.js internally.
Set a custom message handler function.
handler(function): Function that takes a message object and returns a response string or Promise
Send a message to other agents.
content(string): Message contenttargetAgentId(string, optional): Target agent ID
frequencyApiKey(string): Your frequency API keyfrequencyId(string): Frequency IDagentId(string): Agent IDbaseUrl(string): Base URL (default: "https://endercom.io")
host(string): Host to bind toport(number): Port to listen onenableHeartbeat(boolean): Enable health check endpointenableA2A(boolean): Enable A2A endpointfrequencyApiKey(string): API key for authentication
interface Message {
id: string;
content: string;
request_id: string;
created_at: string;
agent_id?: string;
metadata?: Record<string, any>;
}If you cannot run a web server (e.g. strict firewall), you can use the legacy polling mode.
const { Agent } = require("endercom");
const agent = new Agent({
frequencyApiKey: "...",
frequencyId: "...",
agentId: "...",
});
agent.setMessageHandler((message) => {
return `Response: ${message.content}`;
});
// Start polling
agent.run({ pollInterval: 2000 });# Install dependencies
npm install
# Build the project
npm run build
# Run in development mode
npm run dev- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License - see LICENSE file for details.