The Ultimate Swarm Agents Platform provides a comprehensive tRPC-based API for managing agents, workflows, tasks, and monitoring. All endpoints are type-safe with automatic TypeScript type generation.
All protected endpoints require authentication via JWT tokens obtained through OAuth 2.0:
import { trpc } from '@/lib/trpc';
// Check current user
const { data: user } = trpc.auth.me.useQuery();
// Logout
const logout = trpc.auth.logout.useMutation();
logout.mutate();try {
const result = await trpc.agent.create.mutate({
name: 'MyAgent',
type: 'reasoning',
});
} catch (error) {
if (error.code === 'UNAUTHORIZED') {
// Handle auth error
} else if (error.code === 'BAD_REQUEST') {
// Handle validation error
}
}Create a new AI agent with specified capabilities and configuration.
const agent = await trpc.agent.create.mutate({
name: 'AnalysisAgent',
type: 'reasoning', // 'reasoning' | 'execution' | 'coordination' | 'analysis'
description: 'Analyzes complex data structures',
capabilities: ['data_analysis', 'pattern_recognition'],
llmModel: 'gpt-4',
parameters: {
temperature: 0.7,
maxTokens: 2000,
},
integrationFramework: 'langchain',
version: '1.0.0',
});
// Response:
// {
// id: 'agent-123',
// name: 'AnalysisAgent',
// type: 'reasoning',
// status: 'active',
// healthScore: 100,
// successRate: 100,
// createdAt: Date,
// updatedAt: Date,
// }Retrieve details for a specific agent.
const agent = await trpc.agent.get.query({
agentId: 'agent-123',
});Retrieve all agents with optional filtering.
const agents = await trpc.agent.list.query({
status: 'active', // optional
type: 'reasoning', // optional
});
// Returns: Agent[]Change agent status (active, inactive, error, maintenance).
await trpc.agent.updateStatus.mutate({
agentId: 'agent-123',
status: 'active',
});Record agent performance metrics.
await trpc.agent.updateMetrics.mutate({
agentId: 'agent-123',
successCount: 150,
failureCount: 5,
});Define a new multi-agent workflow.
const workflow = await trpc.workflow.create.mutate({
name: 'DataProcessingPipeline',
description: 'Multi-stage data processing workflow',
orchestrationPattern: 'sequential', // 'hierarchical' | 'sequential' | 'concurrent' | 'round_robin' | 'mesh'
nodes: [
{ id: 'node1', type: 'agent', agentId: 'agent-1' },
{ id: 'node2', type: 'agent', agentId: 'agent-2' },
],
edges: [
{ source: 'node1', target: 'node2' },
],
configuration: {
timeout: 3600,
maxRetries: 3,
},
});
// Response:
// {
// id: 'workflow-123',
// name: 'DataProcessingPipeline',
// orchestrationPattern: 'sequential',
// status: 'draft',
// createdAt: Date,
// }Retrieve workflow details.
const workflow = await trpc.workflow.get.query({
workflowId: 'workflow-123',
});Retrieve all workflows.
const workflows = await trpc.workflow.list.query({
status: 'active', // optional
});Change workflow status (draft, active, paused, archived).
await trpc.workflow.updateStatus.mutate({
workflowId: 'workflow-123',
status: 'active',
});Retrieve pre-configured workflow templates.
const templates = await trpc.workflow.getTemplates.query({
category: 'data_processing', // optional
});Create a new task for workflow execution.
const task = await trpc.task.create.mutate({
workflowId: 'workflow-123',
input: {
data: 'process this data',
options: { verbose: true },
},
assignedAgents: ['agent-1', 'agent-2'],
priority: 1,
});
// Response:
// {
// id: 'task-123',
// workflowId: 'workflow-123',
// status: 'pending',
// createdAt: Date,
// }Retrieve task details and status.
const task = await trpc.task.get.query({
taskId: 'task-123',
});Update task status with results.
await trpc.task.updateStatus.mutate({
taskId: 'task-123',
status: 'completed',
result: {
output: 'processed data',
metrics: { duration: 1500 },
},
});Retrieve execution logs for a task.
const logs = await trpc.task.getLogs.query({
taskId: 'task-123',
limit: 100, // optional, default 1000
});
// Response:
// {
// id: 'log-123',
// taskId: 'task-123',
// agentId: 'agent-1',
// eventType: 'execution',
// level: 'info',
// message: 'Task started',
// createdAt: Date,
// }[]Retrieve agent conversation for a task.
const messages = await trpc.task.getConversation.query({
taskId: 'task-123',
limit: 50, // optional, default 100
});Send a message between agents.
const message = await trpc.communication.sendMessage.mutate({
senderId: 'agent-1',
recipientId: 'agent-2', // optional for broadcast
taskId: 'task-123',
messageType: 'request', // 'request' | 'response' | 'status_update' | 'error' | 'broadcast'
content: {
action: 'analyze',
data: 'data to analyze',
},
metadata: {
priority: 'high',
retryCount: 0,
},
});Retrieve message history for a task.
const conversation = await trpc.communication.getConversation.query({
taskId: 'task-123',
limit: 100,
});Record agent performance metrics.
await trpc.monitoring.recordMetric.mutate({
agentId: 'agent-1',
taskId: 'task-123',
executionTime: 1500, // milliseconds
tokenUsage: 500,
estimatedCost: 0.05,
successFlag: true,
});Retrieve performance metrics for an agent.
const metrics = await trpc.monitoring.getAgentMetrics.query({
agentId: 'agent-1',
hoursBack: 24, // optional, default 24
});
// Response:
// {
// agentId: 'agent-1',
// avgExecutionTime: 1200,
// totalTokens: 50000,
// successRate: 98.5,
// createdAt: Date,
// }[]Create an execution log entry.
await trpc.monitoring.createLog.mutate({
taskId: 'task-123',
agentId: 'agent-1',
eventType: 'execution', // 'execution' | 'decision' | 'error' | 'metric' | 'state_change'
level: 'info', // 'debug' | 'info' | 'warning' | 'error' | 'critical'
message: 'Agent started processing',
metadata: {
step: 1,
duration: 100,
},
});Retrieve all logs for a task.
const logs = await trpc.monitoring.getTaskLogs.query({
taskId: 'task-123',
limit: 1000,
});Create an alert for critical events.
await trpc.alerts.create.mutate({
alertType: 'agent_failure', // 'agent_failure' | 'task_timeout' | 'system_error' | 'task_completion' | 'performance_degradation'
severity: 'critical', // 'info' | 'warning' | 'critical'
title: 'Agent Failed',
message: 'Agent-1 encountered a critical error',
relatedAgentId: 'agent-1',
relatedTaskId: 'task-123',
});Retrieve all unresolved alerts.
const alerts = await trpc.alerts.getUnresolved.query();
// Response:
// {
// id: 'alert-123',
// alertType: 'agent_failure',
// severity: 'critical',
// title: 'Agent Failed',
// message: 'Error details',
// resolved: false,
// createdAt: Date,
// }[]Retrieve available integrations.
const integrations = await trpc.integration.list.query({
active: true, // optional
});
// Response:
// {
// id: 'integration-1',
// framework: 'langchain',
// version: '0.1.0',
// active: true,
// }[]Retrieve specific integration details.
const integration = await trpc.integration.get.query({
framework: 'langchain',
});Retrieve available LLM providers.
const providers = await trpc.llm.list.query({
active: true, // optional
});
// Response:
// {
// id: 'provider-1',
// name: 'OpenAI',
// model: 'gpt-4',
// active: true,
// }[]Retrieve the default LLM provider.
const defaultProvider = await trpc.llm.getDefault.query();interface Agent {
id: string;
name: string;
type: 'reasoning' | 'execution' | 'coordination' | 'analysis';
description?: string;
capabilities: string[];
status: 'active' | 'inactive' | 'error' | 'maintenance';
llmModel?: string;
parameters?: Record<string, unknown>;
integrationFramework?: string;
version?: string;
healthScore: number;
successRate: number;
totalExecutions: number;
failedExecutions: number;
createdAt: Date;
updatedAt: Date;
}interface Workflow {
id: string;
name: string;
description?: string;
orchestrationPattern: 'hierarchical' | 'sequential' | 'concurrent' | 'round_robin' | 'mesh';
nodes: Record<string, unknown>[];
edges: Record<string, unknown>[];
configuration: Record<string, unknown>;
status: 'draft' | 'active' | 'paused' | 'archived';
createdAt: Date;
updatedAt: Date;
}interface Task {
id: string;
workflowId: string;
input?: Record<string, unknown>;
assignedAgents: string[];
priority: number;
status: 'pending' | 'running' | 'completed' | 'failed' | 'timeout';
result?: Record<string, unknown>;
createdAt: Date;
updatedAt: Date;
}| Code | Status | Description |
|---|---|---|
| UNAUTHORIZED | 401 | Authentication required |
| FORBIDDEN | 403 | Insufficient permissions |
| NOT_FOUND | 404 | Resource not found |
| BAD_REQUEST | 400 | Invalid request data |
| CONFLICT | 409 | Resource conflict |
| INTERNAL_SERVER_ERROR | 500 | Server error |
| TIMEOUT | 504 | Request timeout |
API requests are rate-limited to prevent abuse:
- Default: 100 requests per minute
- Burst: 10 requests per second
- Headers:
X-RateLimit-Limit,X-RateLimit-Remaining,X-RateLimit-Reset
List endpoints support pagination:
const agents = await trpc.agent.list.query({
limit: 20,
offset: 0,
});Configure webhooks for event notifications:
// Webhook events:
// - agent.created
// - agent.status_changed
// - task.completed
// - task.failed
// - workflow.started
// - workflow.completed- Error Handling - Always handle errors gracefully
- Retry Logic - Implement exponential backoff for retries
- Caching - Cache frequently accessed data
- Pagination - Use pagination for large result sets
- Monitoring - Monitor API usage and performance
- Security - Never expose API keys in client code
- Versioning - Plan for API versioning strategy
For API questions and support:
- GitHub Issues: https://github.com/shards-inc/swarm-agent/issues
- Email: support@shards-inc.com
- Documentation: https://docs.swarm-agent.io
Last Updated: February 17, 2026
API Version: 1.0.0
Status: Stable