AI Systems
Alith Orchestrator
AI-powered music generation orchestrator using Alith framework
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
AI-powered music generation orchestrator using Alith framework
// Initialize Alith agent with optimized preamble
musicAgent = new Agent({
model: "gemini-2.5-flash-lite",
apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY,
baseUrl: "generativelanguage.googleapis.com/v1beta/openai",
preamble: enhancedPreamble,
memory: new WindowBufferMemory(8)
});
const interpretation = await musicAgent.run(JSON.stringify({
sensorData: enrichedSensorData,
sessionHistory: sessionData?.history || [],
userProfile: sessionData?.profile || {},
currentBaseline: this.currentBaseline
}));
// Optimized rate limiting for baseline-driven processing
this.geminiCallCooldown = 4500; // 4.5 seconds for 15 requests/minute quota
this.serverLatency = 250; // Stability-focused latency
this.minSendInterval = 200; // Smooth server processing
userPatternStore = new QdrantStore({
url: process.env.QDRANT_URL || 'http://localhost:6333',
collectionName: 'user_patterns',
apiKey: process.env.QDRANT_API_KEY
});
// Reduced memory window for token efficiency
memory: new WindowBufferMemory(8)
this.wsServer.on('connection', (ws) => {
ws.on('message', async (message) => {
const data = JSON.parse(message);
if (data.type === 'sensorUpdate') {
await this.processSensorData(data.sensorData, ws);
}
});
});
function preambleWithKnowledge() {
const poemsContent = readFileSync(join(__dirname, 'knowledge', 'poems.txt'), 'utf8');
const parametersContent = readFileSync(join(__dirname, 'knowledge', 'parameters.txt'), 'utf8');
return `Enhanced preamble with ${poemsContent} and ${parametersContent}`;
}
let agentProcessingQueue = Promise.resolve();
let activeProcessingCount = 0;
// Queue processing to prevent parallel API calls
agentProcessingQueue = agentProcessingQueue.then(async () => {
activeProcessingCount++;
try {
return await processRequest();
} finally {
activeProcessingCount--;
}
});
createIntelligentRaveFallback(enrichedSensorData, sessionData) {
// Energy-based fallback when AI agent is unavailable
const energy = Math.sqrt(
Math.pow(enrichedSensorData.x, 2) +
Math.pow(enrichedSensorData.y, 2) +
Math.pow(enrichedSensorData.z, 2)
) / 3;
return {
singleCoherentPrompt: this.generateEnergyBasedPrompt(energy),
lyriaConfig: this.generateEnergyBasedConfig(energy),
requiresCrossfade: energy > 0.6
};
}
async reconnectToServer() {
const delay = Math.min(1000 * Math.pow(2, this.reconnectAttempts), 30000);
setTimeout(async () => {
try {
await this.connectToInterpretationServer();
} catch (error) {
this.reconnectAttempts++;
if (this.reconnectAttempts < this.maxReconnectAttempts) {
this.reconnectToServer();
}
}
}, delay);
}