awslabs / multi-agent-orchestrator

Flexible and powerful framework for managing multiple AI agents and handling complex conversations
https://awslabs.github.io/multi-agent-orchestrator/
Apache License 2.0
178 stars 30 forks source link

Bug: Cannot find module 'sylvester' after updating to multi-agent-orchestrator ^0.0.13 #30

Closed valentin-dirken closed 1 month ago

valentin-dirken commented 2 months ago

Expected Behaviour

The code should work with the updated version of multi-agent-orchestrator (^0.0.13) just as it did with version ^0.0.12, without errors related to missing modules.

Current Behaviour

After updating to multi-agent-orchestrator version ^0.0.13, the Lambda function throws an error indicating that the module 'sylvester' cannot be found. The error trace shows that this issue originates from the multi-agent-orchestrator package's dependencies.

`Response { "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'sylvester'\nRequire stack:\n- /opt/node_modules/apparatus/lib/apparatus/classifier/logistic_regression_classifier.js\n- /opt/node_modules/apparatus/lib/apparatus/index.js\n- /opt/node_modules/natural/lib/natural/classifiers/bayes_classifier.js\n- /opt/node_modules/natural/lib/natural/classifiers/index.js\n- /opt/node_modules/natural/lib/natural/index.js\n- /opt/node_modules/multi-agent-orchestrator/dist/agentOverlapAnalyzer.js\n- /opt/node_modules/multi-agent-orchestrator/dist/orchestrator.js\n- /opt/node_modules/multi-agent-orchestrator/dist/index.js", "trace": [ "Runtime.ImportModuleError: Error: Cannot find module 'sylvester'", "Require stack:", "- /opt/node_modules/apparatus/lib/apparatus/classifier/logistic_regression_classifier.js", "- /opt/node_modules/apparatus/lib/apparatus/index.js", "- /opt/node_modules/natural/lib/natural/classifiers/bayes_classifier.js", "- /opt/node_modules/natural/lib/natural/classifiers/index.js", "- /opt/node_modules/natural/lib/natural/index.js", "- /opt/node_modules/multi-agent-orchestrator/dist/agentOverlapAnalyzer.js", "- /opt/node_modules/multi-agent-orchestrator/dist/orchestrator.js", "- /opt/node_modules/multi-agent-orchestrator/dist/index.js", " at _loadUserApp (file:///var/runtime/index.mjs:1087:17)", " at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)", " at async start (file:///var/runtime/index.mjs:1282:23)", " at async file:///var/runtime/index.mjs:1288:1" ] }

Function Logs ator/dist/index.js","reason":{"errorType":"Error","errorMessage":"Cannot find module 'sylvester'\nRequire stack:\n- /opt/node_modules/apparatus/lib/apparatus/classifier/logistic_regression_classifier.js\n- /opt/node_modules/apparatus/lib/apparatus/index.js\n- /opt/node_modules/natural/lib/natural/classifiers/bayes_classifier.js\n- /opt/node_modules/natural/lib/natural/classifiers/index.js\n- /opt/node_modules/natural/lib/natural/index.js\n- /opt/node_modules/multi-agent-orchestrator/dist/agentOverlapAnalyzer.js\n- /opt/node_modules/multi-agent-orchestrator/dist/orchestrator.js\n- /opt/node_modules/multi-agent-orchestrator/dist/index.js","code":"MODULE_NOT_FOUND","requireStack":["/opt/node_modules/apparatus/lib/apparatus/classifier/logistic_regression_classifier.js","/opt/node_modules/apparatus/lib/apparatus/index.js","/opt/node_modules/natural/lib/natural/classifiers/bayes_classifier.js","/opt/node_modules/natural/lib/natural/classifiers/index.js","/opt/node_modules/natural/lib/natural/index.js","/opt/node_modules/multi-agent-orchestrator/dist/agentOverlapAnalyzer.js","/opt/node_modules/multi-agent-orchestrator/dist/orchestrator.js","/opt/node_modules/multi-agent-orchestrator/dist/index.js"],"stack":["Error: Cannot find module 'sylvester'","Require stack:","- /opt/node_modules/apparatus/lib/apparatus/classifier/logistic_regression_classifier.js","- /opt/node_modules/apparatus/lib/apparatus/index.js","- /opt/node_modules/natural/lib/natural/classifiers/bayes_classifier.js","- /opt/node_modules/natural/lib/natural/classifiers/index.js","- /opt/node_modules/natural/lib/natural/index.js","- /opt/node_modules/multi-agent-orchestrator/dist/agentOverlapAnalyzer.js","- /opt/node_modules/multi-agent-orchestrator/dist/orchestrator.js","- /opt/node_modules/multi-agent-orchestrator/dist/index.js"," at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)"," at Module._load (node:internal/modules/cjs/loader:986:27)"," at Module.require (node:internal/modules/cjs/loader:1233:19)"," at require (node:internal/modules/helpers:179:18)"," at Object. (/opt/node_modules/apparatus/lib/apparatus/classifier/logistic_regression_classifier.js:26:17)"," at Module._compile (node:internal/modules/cjs/loader:1358:14)"," at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)"," at Module.load (node:internal/modules/cjs/loader:1208:32)"," at Module._load (node:internal/modules/cjs/loader:1024:12)"," at Module.require (node:internal/modules/cjs/loader:1233:19)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: Cannot find module 'sylvester'","Require stack:","- /opt/node_modules/apparatus/lib/apparatus/classifier/logistic_regression_classifier.js","- /opt/node_modules/apparatus/lib/apparatus/index.js","- /opt/node_modules/natural/lib/natural/classifiers/bayes_classifier.js","- /opt/node_modules/natural/lib/natural/classifiers/index.js","- /opt/node_modules/natural/lib/natural/index.js","- /opt/node_modules/multi-agent-orchestrator/dist/agentOverlapAnalyzer.js","- /opt/node_modules/multi-agent-orchestrator/dist/orchestrator.js","- /opt/node_modules/multi-agent-orchestrator/dist/index.js"," at process. (file:///var/runtime/index.mjs:1276:17)"," at process.emit (node:events:519:28)"," at emitUnhandledRejection (node:internal/process/promises:250:13)"," at throwUnhandledRejectionsMode (node:internal/process/promises:385:19)"," at processPromiseRejections (node:internal/process/promises:470:17)"," at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"]} INIT_REPORT Init Duration: 12992.17 ms Phase: invoke Status: error Error Type: Runtime.ImportModuleError START RequestId: d0e67262-8d11-48f2-85d3-bf0abe329c74 Version: $LATEST END RequestId: d0e67262-8d11-48f2-85d3-bf0abe329c74 REPORT RequestId: d0e67262-8d11-48f2-85d3-bf0abe329c74 Duration: 13040.25 ms Billed Duration: 13041 ms Memory Size: 128 MB Max Memory Used: 115 MB Status: error Error Type: Runtime.ImportModuleError `

Code snippet

// Use ES module syntax to import modules
import { MultiAgentOrchestrator, BedrockLLMAgent, BedrockClassifier, DynamoDbChatStorage } from 'multi-agent-orchestrator';

const customBedrockClassifier = new BedrockClassifier({
  modelId: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
  inferenceConfig: {
    maxTokens: 100,
    temperature: 0.7,
    topP: 0.9
  }
});

const tableName = 'chat_history_multi_agent_orchestrator';
const region = 'us-east-1';
const TTL_DURATION = 3600; // in seconds
const dynamoDbStorage = new DynamoDbChatStorage(tableName, region, 'chat_history_multi_agent_orchestrator_ttl', TTL_DURATION);

const orchestrator = new MultiAgentOrchestrator({ 
    classifier: customBedrockClassifier,  
    storage: dynamoDbStorage
});

// Initialize the Tech Agent
orchestrator.addAgent(
  new BedrockLLMAgent({
    name: "Tech Agent",
    description:
      "Specializes in technology areas including software development, hardware, AI, cybersecurity, blockchain, cloud computing, emerging tech innovations, and pricing/costs related to technology products and services.",
    streaming: true
  })
);

// Initialize the Insurance Agent (general inquiries)
orchestrator.addAgent(
  new BedrockLLMAgent({
    name: "Insurance Agent",
    description:
      "Specializes in insurance areas including health insurance, auto insurance, life insurance, home insurance, policy comparisons, claims processing, and risk management.",
    streaming: true
  })
);

// Initialize the Natural Disaster Agent
orchestrator.addAgent(
  new BedrockLLMAgent({
    name: "Natural Disaster Agent",
    description:
      "Specializes to provide Natural Disaster information. So, Reply 'I am the Natural Disaster Agent' and nothing else",
    streaming: true
  })
);

// Lambda handler function
export const handler = async (event) => {
  // Extract request parameters from the event
  const { query, userId, sessionId } = event;

  try {
    // Route the request using the orchestrator
    const response = await orchestrator.routeRequest(
      query, userId, sessionId
    );

    // Handle the response (streaming or non-streaming)
    if (response.streaming == true) {
        console.log("\n** RESPONSE STREAMING ** \n");
        // Send metadata immediately
        console.log(`> Agent ID: ${response.metadata.agentId}`);
        console.log(`> Agent Name: ${response.metadata.agentName}`);
        console.log(`> User Input: ${response.metadata.userInput}`);
        console.log(`> User ID: ${response.metadata.userId}`);
        console.log(`> Session ID: ${response.metadata.sessionId}`);
        console.log(
          `> Additional Parameters:`,
          response.metadata.additionalParams
        );
        console.log(`\n> Response: `);

        // Stream the content
        for await (const chunk of response.output) {
          if (typeof chunk === "string") {
            process.stdout.write(chunk);
          } else {
            console.error("Received unexpected chunk type:", typeof chunk);
          }
        }

    } else {
        // Handle non-streaming response (AgentProcessingResult)
        console.log("\n** RESPONSE ** \n");
        console.log(`> Agent ID: ${response.metadata.agentId}`);
        console.log(`> Agent Name: ${response.metadata.agentName}`);
        console.log(`> User Input: ${response.metadata.userInput}`);
        console.log(`> User ID: ${response.metadata.userId}`);
        console.log(`> Session ID: ${response.metadata.sessionId}`);
        console.log(
          `> Additional Parameters:`,
          response.metadata.additionalParams
        );
        console.log(`\n> Response: ${response.output}`);
        return {
          statusCode: 200,
          body: JSON.stringify({
            message: response.output
          }),
        };
    }
  } catch (error) {
    console.error('Error processing request:', error);
    return {
      statusCode: 500,
      body: JSON.stringify({
        message: 'Internal Server Error',
        error: error.message,
      }),
    };
  }
};

Possible Solution

The error seems to indicate a missing dependency ('sylvester'). The package multi-agent-orchestrator or one of its dependencies might have been updated in a way that introduces a missing dependency.

Steps to Reproduce

  1. Update multi-agent-orchestrator to version ^0.0.13.

In AWS CloudShell : npm install multi-agent-orchestrator@latest && zip -r multi-agent-orchestrator-layer.zip node_modules && aws lambda publish-layer-version --layer-name multi-agent-orchestrator --zip-file fileb://multi-agent-orchestrator-layer.zip

  1. Deploy the Lambda function with the updated package.
  2. Invoke the Lambda function to trigger the error.
cornelcroi commented 2 months ago

In the code above I see you have a handler function. I don't follow what you are trying to do by looking at the code snippet. The code seems to be for a lambda function but you are trying to push the same zip for the lambda function but also for a layer ?

brnaba-aws commented 1 month ago

Can we close this?

cornelcroi commented 1 month ago

This issue is being closed due to inactivity from the original requester.