
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@agentswarmprotocol/servicesdk
Advanced tools
The SwarmServiceSDK provides a simple way for services to connect to and interact with the Agent Swarm Protocol orchestrator. Services can register functions that agents can call, and they can send notifications to clients about task progress.
The SwarmServiceSDK provides a simple way for services to connect to and interact with the Agent Swarm Protocol orchestrator. Services can register functions that agents can call, and they can send notifications to clients about task progress.
npm install @agent-swarm/service-sdk
const { SwarmServiceSDK } = require('@agent-swarm/service-sdk');
// Create a new service
const service = new SwarmServiceSDK({
name: 'LLM Service',
description: 'A service for language model operations',
capabilities: ['generate', 'chat', 'embed']
});
// Connect to the orchestrator
service.connect()
.then(() => {
console.log('Connected to orchestrator');
})
.catch(error => {
console.error('Error:', error.message);
});
// Register a function handler
service.registerFunction('generate', async (params, notifyProgress, metadata) => {
console.log('Received generate function call:', params);
console.log('Task metadata:', metadata);
// Send progress notification to client
await notifyProgress('Starting text generation...', { progress: 10 });
// Simulate some processing time
await new Promise(resolve => setTimeout(resolve, 1000));
// Send another progress notification
await notifyProgress('Processing prompt...', { progress: 50 });
await new Promise(resolve => setTimeout(resolve, 1000));
// Send info notification
await notifyProgress('Applying parameters...', {
temperature: params.temperature || 0.7,
maxTokens: params.maxTokens || 100
}, 'info');
await new Promise(resolve => setTimeout(resolve, 1000));
// Send final progress notification
await notifyProgress('Finalizing results...', { progress: 90 });
// Return the result
return {
text: `Generated text based on prompt: ${params.prompt}`,
tokens: 42
};
});
// Listen for events
service.on('error', (error) => {
console.error('Service error:', error.message);
});
The SwarmServiceSDK constructor accepts a configuration object with the following properties:
| Property | Type | Description | Default |
|---|---|---|---|
| name | string | Name of the service | 'Generic Service' |
| description | string | Service description | 'Generic Service' |
| orchestratorUrl | string | WebSocket URL of the orchestrator service interface | 'ws://localhost:3002' |
| capabilities | Array | Service capabilities/functions | [] |
| autoReconnect | boolean | Whether to auto-reconnect | true |
| reconnectInterval | number | Reconnect interval in ms | 5000 |
params: The function parameters passed by the agentnotifyProgress: A function to send notifications about task progressmetadata: Task metadata including taskId, agentId, and clientIdThe SDK emits the following events:
Here's an example of a simple LLM service that processes text generation requests:
const { SwarmServiceSDK } = require('@agent-swarm/service-sdk');
const openai = require('openai');
// Initialize OpenAI client
const openaiClient = new openai.OpenAI({
apiKey: process.env.OPENAI_API_KEY
});
// Create LLM service
const llmService = new SwarmServiceSDK({
name: 'OpenAI LLM Service',
description: 'Service for text generation using OpenAI models',
capabilities: ['chat', 'complete', 'embed']
});
// Register chat function
llmService.registerFunction('chat', async (params, notifyProgress, metadata) => {
const { messages, model = 'gpt-4', temperature = 0.7 } = params;
await notifyProgress('Initializing chat request...', {
model,
messageCount: messages.length
});
try {
await notifyProgress('Sending request to OpenAI...', { progress: 30 });
const response = await openaiClient.chat.completions.create({
model,
messages,
temperature
});
await notifyProgress('Response received', { progress: 90 });
return {
text: response.choices[0].message.content,
model: response.model,
usage: response.usage
};
} catch (error) {
await notifyProgress(`Error: ${error.message}`, {}, 'error');
throw error;
}
});
// Connect to orchestrator
llmService.connect()
.then(() => console.log('LLM Service connected and ready'))
.catch(err => console.error('Connection error:', err.message));
Services can register task handlers using the onTask method:
service.onTask('read', async (params, notify, metadata) => {
// Initial notification
await notify('Starting task...', { progress: 0 });
// Perform the task
const result = await doSomething(params);
// Return the result
return result;
});
The task handler receives three parameters:
params: The parameters for the tasknotify: A function to send progress notificationsmetadata: Additional metadata about the task (taskId, agentId, clientId, etc.)Services can send real-time notifications about task progress to clients:
// From within a task handler
await notify('Processing...', { progress: 50, details: 'step 2' });
For more control, use the service's notify method directly:
await service.notify({
taskId: 'task-123',
type: 'progress',
message: 'Processing file...',
data: { progress: 75, fileName: 'data.json' }
});
MIT
FAQs
The SwarmServiceSDK provides a simple way for services to connect to and interact with the Agent Swarm Protocol orchestrator. Services can register functions that agents can call, and they can send notifications to clients about task progress.
We found that @agentswarmprotocol/servicesdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.