Swarm.js is a Node.js implementation of OpenAI's experimental Swarm framework[https://github.com/openai/swarm]. Also following this cookbook from OpenAI[https://cookbook.openai.com/examples/orchestrating_agents]. I took some inspiration from both the repo and the cookbook to create my own Node.js implementation of Swarm. This library also supports anthropic sdk, so you are not limited to just using openai.
You can install the Swarm.js library via npm:
npm install node-swarmjs
Swarm.js focuses on multi-agent coordination and execution by defining lightweight agents that can carry out tasks and hand off conversations when necessary. Heavily inspired by OpenAI's Python Swarm framework, this Node.js implementation allows developers to build multi-agent systems that are highly customizable, scalable, and easy to use.
This is currently in the early stages of development and is not yet ready for production use. There are no tests and some of the core functionality is missing(e.g. this doesn't yet support streaming responses from agents).
Swarm.js makes it easy to define agents, assign them tasks, and manage interactions between them. Below is a simple example demonstrating how to create and orchestrate two agents.
import { Swarm, Agent } from 'node-swarmjs';
const client = new Swarm({
apiKey: process.env.OPENAI_API_KEY,
clientType: 'openai'// can also be anthropic,
});
// define the agents
function transferToAgentB() {
return agentB;
}
const agentA = new Agent({
name: 'Agent A',
instructions: 'You are a helpful agent',
functions: [transferToAgentB],
});
const agentB = new Agent({
name: 'Agent B',
instructions: 'Only speak in Haiku.',
});
// run the conversation with agentA
(async () => {
try {
const response = await client.run({
agent: agentA,
messages: [{ role: "user", content: "I want to talk to agent B." }]
});
console.log(response.messages[response.messages.length - 1].content);
} catch (error) {
console.error('An error occurred:', error);
}
})();
import { Swarm, Agent } from 'node-swarmjs';
const client = new Swarm({
apiKey: process.env.ANTHROPIC_API_KEY,
clientType: 'anthropic',
});
function transferToAgentB() {
return agentB;
}
const agentA = new Agent({
name: 'Agent A',
instructions: 'You are a helpful agent',
functions: [transferToAgentB],
});
const agentB = new Agent({
name: 'Agent B',
instructions: 'Only speak in Haiku.',
});
(async () => {
try {
const response = await client.run({
agent: agentA,
messages: [{ role: 'user', content: 'I want to talk to agent B.' }],
});
console.log(response.messages[response.messages.length - 1].content);
} catch (error) {
console.error('An error occurred:', error);
}
})();
This project is licensed under the MIT License. See the LICENSE file for more details.
- Expand LLM Support
- Integrate with Hugging Face models
- Add support for Anthropic
- Implement Azure OpenAI Service integration
- Enhance Agent Capabilities
- Implement streaming responses from agents
- Develop context passing mechanism between agents
- Create advanced conversation routing logic
- Add support for concurrent agent execution
- LangChain Integration
- Implement support for LangChain tools
- Create adapters for LangChain agents
- UI Components
- Develop drop-in React components for easy UI integration
- Database Connectors
- Add support for vector databases (e.g., Pinecone, Weaviate)
- Implement connectors for relational databases
- CLI
- Add a CLI for easy setup of agents(ideally use be able to bootstrap your agents from a CLI inside your NextJS app, or express server)
- Implement Retry Mechanism
- Add exponential backoff for failed requests
- Optimize Performance
- Implement caching layer for frequent requests
- Add support for batch processing of tasks
- Expand Documentation
- Create comprehensive API reference
- Write step-by-step tutorials for common use cases
- Improve Testing
- Increase unit test coverage to 80%(currently there are no tests)
- Add performance benchmarks
- Develop Example Projects
- Create a customer support chatbot example
- Build a multi-agent collaborative task solver
- Implement a document analysis and summarization system
- Improve Contribution Process
- Develop contributor guidelines
- Set up automated code quality checks for pull requests