Task Manager Agent - Coordinates tasks between agents and manages the workflow.
Event Bus
Agents communicate through a central event bus, which follows a publish-subscribe pattern:
Plugin System
The Sonic Agent uses a plugin system to interact with different DeFi protocols:
Development Workflow
Adding a New Feature
Create a branch:
Implement your changes:
For new agent capabilities, add methods to the relevant agent class
For new UI features, add components and update pages
Add tests for your changes
Run tests:
Submit a pull request:
Ensure your code follows the project's style guide
Include a description of your changes
Reference any related issues
Adding a New Protocol Integration
To add support for a new DeFi protocol:
Create a new plugin in server/src/agents/plugins/:
Implement the plugin with necessary methods:
Update the Sonic Agent to use your plugin:
Testing
Unit Tests
Run unit tests for a specific component:
Integration Tests
Integration tests can be run with:
End-to-End Tests
End-to-end tests use Cypress:
Debugging
Server Debugging
For detailed server logs:
Transaction Debugging
To debug blockchain transactions:
Frontend Debugging
For frontend debugging, use the browser's developer tools. The application also provides debug information in the browser console when running in development mode.
Common Issues and Solutions
"Cannot find module" Error
If you encounter a "Cannot find module" error:
Server Connection Issues
If the frontend can't connect to the backend:
Check that both servers are running
Verify the API URL in the frontend's .env.local
Check for any CORS issues in the browser console
Database Connection Issues
If there are database connection errors:
Check your database configuration in server/.env.local
Ensure the database server is running
Try resetting the database with bun run db:reset
Next Steps
Once you have your development environment set up, you can:
# Install root dependencies
bun install
# Install server dependencies
cd server
bun install
# Install frontend dependencies
cd ../frontend
bun install
# Return to root
cd ..
// Subscribe to an event
eventBus.subscribe("portfolio:updated", (data) => {
// Handle the event
});
// Publish an event
eventBus.publish("portfolio:updated", {
walletAddress: "0x123...",
portfolioValue: 1000
});
// Example plugin usage
const uniswapProvider = new UniswapProvider({
chainId: 1,
rpcUrl: process.env.ETHEREUM_RPC_URL,
});
// Register the plugin with the Sonic Agent
const sonicAgent = new SonicAgent("sonic", eventBus, storage, uniswapProvider);