The Integrated Swarm Task System is a comprehensive distributed architecture that enables the execution and management of AI swarm-based tasks across the Koii network with $SWARMS token payments integration. The system orchestrates interactions between multiple agents to solve complex tasks efficiently, with built-in payment, verification, and auditing mechanisms.
Central coordination hub that manages task distribution, submission tracking, and verification processes. It maintains the workflow state and orchestrates the communication between workers and services.
Handles task execution logic, submission processing, and interfaces with both the middle server and Python API layer. This component manages the task lifecycle and provides a standardized interface for swarm operations.
Implements the AI task processing functionality with specialized workflows for repository analysis, code generation, and other AI-driven tasks. Provides RESTful APIs for task management and result retrieval.
- Added comprehensive integration testing framework
- Implemented SwarmJob, SwarmStatus, and SwarmResult models
- Created RESTful API endpoints for job creation, status updates, and result storage
- Added proper MongoDB connection and test environment configuration
- Standardized project structure with appropriate gitignore patterns
- Repository Analysis: Analyze code repositories to generate documentation, find bugs, and suggest improvements
- Feature Building: Coordinate multiple AI agents to design, plan, and implement new features
- Summarization: Generate concise summaries of complex codebases or documentation
- Task Distribution: Distribute complex tasks among specialized AI agents for efficient processing
# Install dependencies
npm install
# Run tests
npm test
# Start the middle server
cd middle-server/middle-server
npm run dev
# Start the worker
cd modified-swarm-task/worker
npm run dev
To run all tests in one command:
# Make the script executable
chmod +x scripts/test-local.sh
# Run the test script
./scripts/test-local.sh
This script will:
- Check for required environment variables
- Verify Node.js version and dependencies
- Install all required packages
- Run the worker tests with verbose output
- Report test results
- Node.js >= 18.17.0
- npm or yarn package manager
- TypeScript 5.6.2 or later
- MongoDB (for middle server tests)
-
Install dependencies for each component:
# Middle server cd middle-server/middle-server npm install # Worker cd node/worker npm install
-
Set up environment variables:
# Required for worker tests export ANTHROPIC_API_KEY=your_api_key export GITHUB_TOKEN=your_github_token export GITHUB_USERNAME=your_github_username export TASK_ID=your_task_id # Required for middle server tests export MONGODB_URI=your_mongodb_uri
The worker uses Jest for testing with TypeScript support:
# Navigate to worker directory
cd node/worker
# Run all tests
npm run jest-test
# Run tests with verbose output
npm run jest-test -- --verbose
# Run a specific test file
npm run jest-test -- tests/node-worker.test.ts
# Run tests in watch mode (auto-rerun on changes)
npm run jest-test -- --watch
Test types:
-
Integration Tests (
tests/node-worker.test.ts
):- Tests core worker functionality
- Currently passing and verifying basic operations
- Includes configuration, task execution, and submission tests
-
Main Tests (
tests/main.test.ts
):- Legacy test suite
- Currently failing (known issue)
- Not recommended for local development
The middle server uses Jest and Supertest for API testing:
# Navigate to middle server directory
cd middle-server/middle-server
# Run all tests
npm test
# Run tests with verbose output
npm test -- --verbose
# Run a specific test file
npm test -- tests/swarm.test.ts
Each component has its own test configuration:
-
Worker:
jest.config.js
: Jest configuration with ES modules supportbabel.config.js
: Babel configuration for TypeScripttsconfig.tests.json
: TypeScript configuration
-
Middle Server:
jest.config.js
: Jest configurationtsconfig.json
: TypeScript configuration
-
Module Resolution:
- Ensure TypeScript configurations are properly set up
- Check import paths in test files
-
Environment Variables:
- Verify all required variables are set
- Worker tests require
ANTHROPIC_API_KEY
- Middle server tests require
MONGODB_URI
-
Watchman Warnings:
watchman watch-del '/path/to/project' ; watchman watch-project '/path/to/project'
-
Namespace Wrapper Errors:
- Some errors from
@_koii/namespace-wrapper
are expected - These are handled by test mocks
- Some errors from
-
Worker:
- ✅ Integration tests passing
- ❌ Main tests failing (known issue)
- 🔄 Watchman warnings present
⚠️ Expected namespace wrapper errors
-
Middle Server:
- ✅ API endpoint tests passing
- ✅ Model tests passing
- ✅ Integration tests passing
/api/swarm/jobs
: Create and manage swarm jobs/api/swarm/jobs/:id/status
: Update job status/api/swarm/jobs/:id/result
: Store and retrieve job results
- Backend: Node.js, Express, MongoDB
- AI Processing: Python, FastAPI
- Containerization: Docker
- Testing: Jest, Supertest
- Storage: IPFS for distributed storage
- Integration: GitHub API for repository access
- Fork the repository
- Create a feature branch
- Submit a pull request with tests
To start both the coordinator and the node in development mode, you can use the root project script. This script first runs the coordinator's start-and-test.sh script and then runs the node's start-node.sh script.
-
Make sure you are in the root directory of the project.
-
Run the following command:
./run-all.sh
This script will:
- Start the coordinator in development mode.
- Start the node in development mode.
You can also test each script independently:
-
Coordinator: Navigate to the
coordinator
directory and run:./start-and-test.sh
-
Node: Navigate to the
node
directory and run:./start-node.sh
Ensure that the following prerequisites are met before running the scripts:
- The middle server must be running.
- The Swarms API must be accessible.
- All necessary environment variables are set in the respective
.env
files.
If you encounter any issues while running the scripts, check the following:
- Ensure that the
package.json
file exists in thenode
directory. - Verify that all dependencies are installed.
- Check the logs for any error messages.